summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-01-04 05:12:31 (GMT)
committerNico Weber <nicolasweber@gmx.de>2014-01-04 05:12:31 (GMT)
commitc8b5ad32899503a1f992f7db75fd2c56e8d49238 (patch)
tree5cc32b2d2074116850860fb1021bb05dc75e2e31
parent637b4572ba9c98b812858a37521af1d442b3ccc4 (diff)
downloadNinja-c8b5ad32899503a1f992f7db75fd2c56e8d49238.zip
Ninja-c8b5ad32899503a1f992f7db75fd2c56e8d49238.tar.gz
Ninja-c8b5ad32899503a1f992f7db75fd2c56e8d49238.tar.bz2
Move duplicated code into a helper function.
-rw-r--r--src/deps_log.cc22
-rw-r--r--src/deps_log.h8
-rw-r--r--src/ninja.cc4
3 files changed, 20 insertions, 14 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc
index 157b65c..61df387 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -325,18 +325,8 @@ bool DepsLog::Recompact(const string& path, string* err) {
Deps* deps = deps_[old_id];
if (!deps) continue; // If nodes_[old_id] is a leaf, it has no deps.
- Node* n = nodes_[old_id];
- Edge* e = n->in_edge();
- // FIXME: move this condition to a helper: (also used in src/ninja.cc)
- if (!e || e->GetBinding("deps").empty()) {
- // Skip entries that don't have in-edges or whose edges don't have a
- // "deps" attribute. They were in the deps log from previous builds, but
- // the the files they were for were removed from the build and their deps
- // entries are no longer needed.
- // (Without the check for "deps", a chain of two or more nodes that each
- // had deps wouldn't be collected in a single recompaction.)
+ if (!IsDepsEntryLiveFor(nodes_[old_id]))
continue;
- }
if (!new_log.RecordDeps(nodes_[old_id], deps->mtime,
deps->node_count, deps->nodes)) {
@@ -364,6 +354,16 @@ bool DepsLog::Recompact(const string& path, string* err) {
return true;
}
+bool DepsLog::IsDepsEntryLiveFor(Node* node) {
+ // Skip entries that don't have in-edges or whose edges don't have a
+ // "deps" attribute. They were in the deps log from previous builds, but
+ // the the files they were for were removed from the build and their deps
+ // entries are no longer needed.
+ // (Without the check for "deps", a chain of two or more nodes that each
+ // had deps wouldn't be collected in a single recompaction.)
+ return node->in_edge() && !node->in_edge()->GetBinding("deps").empty();
+}
+
bool DepsLog::UpdateDeps(int out_id, Deps* deps) {
if (out_id >= (int)deps_.size())
deps_.resize(out_id + 1);
diff --git a/src/deps_log.h b/src/deps_log.h
index babf828..cec0257 100644
--- a/src/deps_log.h
+++ b/src/deps_log.h
@@ -88,6 +88,14 @@ struct DepsLog {
/// Rewrite the known log entries, throwing away old data.
bool Recompact(const string& path, string* err);
+ /// Returns if the deps entry for a node is still reachable from the manifest.
+ ///
+ /// The deps log can contain deps entries for files that were built in the
+ /// past but are no longer part of the manifest. This function returns if
+ /// this is the case for a given node. This function is slow, don't call
+ /// it from code that runs on every build.
+ bool IsDepsEntryLiveFor(Node* node);
+
/// Used for tests.
const vector<Node*>& nodes() const { return nodes_; }
const vector<Deps*>& deps() const { return deps_; }
diff --git a/src/ninja.cc b/src/ninja.cc
index 298d993..095132e 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -449,9 +449,7 @@ int NinjaMain::ToolDeps(int argc, char** argv) {
if (argc == 0) {
for (vector<Node*>::const_iterator ni = deps_log_.nodes().begin();
ni != deps_log_.nodes().end(); ++ni) {
- // Only query for targets with an incoming edge and deps
- Edge* e = (*ni)->in_edge();
- if (e && !e->GetBinding("deps").empty())
+ if (deps_log_.IsDepsEntryLiveFor(*ni))
nodes.push_back(*ni);
}
} else {