28 current_use_ += edge.
weight();
33 current_use_ -= edge.
weight();
38 delayed_.insert(edge);
42 DelayedEdges::iterator it = delayed_.begin();
43 while (it != delayed_.end()) {
45 if (current_use_ + edge->
weight() > depth_)
47 ready_queue->push(edge);
51 delayed_.erase(delayed_.begin(), it);
55 printf(
"%s (%d/%d) ->\n", name_.c_str(), current_use_, depth_);
56 for (DelayedEdges::const_iterator it = delayed_.begin();
57 it != delayed_.end(); ++it)
69 AddPool(&kDefaultPool);
70 AddPool(&kConsolePool);
74 assert(LookupPool(pool->
name()) == NULL);
75 pools_[pool->
name()] = pool;
79 map<string, Pool*>::iterator i = pools_.find(pool_name);
80 if (i == pools_.end())
89 edge->
env_ = &bindings_;
90 edge->
id_ = edges_.size();
91 edges_.push_back(edge);
96 Node* node = LookupNode(path);
100 paths_[node->
path()] = node;
105 Paths::const_iterator i = paths_.find(path);
106 if (i != paths_.end())
112 const bool kAllowReplacements =
true;
113 const int kMaxValidEditDistance = 3;
115 int min_distance = kMaxValidEditDistance + 1;
117 for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) {
119 i->first, path, kAllowReplacements, kMaxValidEditDistance);
120 if (distance < min_distance && i->second) {
121 min_distance = distance;
129 Node* node = GetNode(path, slash_bits);
137 Node* node = GetNode(path, slash_bits);
140 *err = path.
AsString() +
" is defined as an output multiple times";
142 *err =
"multiple rules generate " + path.
AsString();
153 Node* node = GetNode(path, slash_bits);
160 Node* node = LookupNode(path);
162 *err =
"unknown target '" + path.
AsString() +
"'";
165 defaults_.push_back(node);
170 vector<Node*> root_nodes;
172 for (vector<Edge*>::const_iterator e = edges_.begin();
173 e != edges_.end(); ++e) {
174 for (vector<Node*>::const_iterator out = (*e)->outputs_.begin();
175 out != (*e)->outputs_.end(); ++out) {
176 if ((*out)->out_edges().empty())
177 root_nodes.push_back(*out);
181 if (!edges_.empty() && root_nodes.empty())
182 *err =
"could not determine root nodes of build graph";
188 return defaults_.empty() ? RootNodes(err) : defaults_;
192 for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i)
193 i->second->ResetState();
194 for (vector<Edge*>::iterator e = edges_.begin(); e != edges_.end(); ++e) {
195 (*e)->outputs_ready_ =
false;
196 (*e)->deps_loaded_ =
false;
202 for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) {
203 Node* node = i->second;
204 printf(
"%s %s [id:%d]\n",
205 node->
path().c_str(),
210 if (!pools_.empty()) {
211 printf(
"resource_pools:\n");
212 for (map<string, Pool*>::const_iterator it = pools_.begin();
213 it != pools_.end(); ++it)
215 if (!it->second->name().empty()) {
int EditDistance(const StringPiece &s1, const StringPiece &s2, bool allow_replacements, int max_edit_distance)
An edge in the dependency graph; links between Nodes using Rules.
std::vector< Node * > outputs_
std::vector< Node * > validations_
std::vector< Node * > inputs_
Information about a node in the dependency graph: the file, whether it's dirty, mtime,...
void set_in_edge(Edge *edge)
void AddValidationOutEdge(Edge *edge)
void AddOutEdge(Edge *edge)
const std::string & path() const
bool status_known() const
void set_generated_by_dep_loader(bool value)
A pool for delayed edges.
void DelayEdge(Edge *edge)
adds the given edge to this Pool to be delayed.
void RetrieveReadyEdges(EdgePriorityQueue *ready_queue)
Pool will add zero or more edges to the ready_queue.
void EdgeScheduled(const Edge &edge)
informs this Pool that the given edge is committed to be run.
const std::string & name() const
void EdgeFinished(const Edge &edge)
informs this Pool that the given edge is no longer runnable, and should relinquish its resources back...
void Dump() const
Dump the Pool and its edges (useful for debugging).
An invocable build command and associated metadata (description, etc.).
static std::unique_ptr< Rule > Phony()
std::vector< Node * > RootNodes(std::string *error) const
void AddValidation(Edge *edge, StringPiece path, uint64_t slash_bits)
std::vector< Node * > DefaultNodes(std::string *error) const
bool AddDefault(StringPiece path, std::string *error)
Edge * AddEdge(const Rule *rule)
Node * SpellcheckNode(const std::string &path)
Node * GetNode(StringPiece path, uint64_t slash_bits)
void AddIn(Edge *edge, StringPiece path, uint64_t slash_bits)
Add input / output / validation nodes to a given edge.
Node * LookupNode(StringPiece path) const
Pool * LookupPool(const std::string &pool_name)
void Dump()
Dump the nodes and Pools (useful for debugging).
bool AddOut(Edge *edge, StringPiece path, uint64_t slash_bits, std::string *err)
StringPiece represents a slice of a string whose memory is managed externally.
std::string AsString() const
Convert the slice into a full-fledged std::string, copying the data into a new string.
unsigned long long uint64_t