From c8b5ad32899503a1f992f7db75fd2c56e8d49238 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 3 Jan 2014 21:12:31 -0800 Subject: [PATCH] Move duplicated code into a helper function. --- src/deps_log.cc | 22 +++++++++++----------- src/deps_log.h | 8 ++++++++ src/ninja.cc | 4 +--- 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& nodes() const { return nodes_; } const vector& 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::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 { -- 2.7.4