Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit c8b5ad3

Browse files
committed
Move duplicated code into a helper function.
1 parent 637b457 commit c8b5ad3

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/deps_log.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,8 @@ bool DepsLog::Recompact(const string& path, string* err) {
325325
Deps* deps = deps_[old_id];
326326
if (!deps) continue; // If nodes_[old_id] is a leaf, it has no deps.
327327

328-
Node* n = nodes_[old_id];
329-
Edge* e = n->in_edge();
330-
// FIXME: move this condition to a helper: (also used in src/ninja.cc)
331-
if (!e || e->GetBinding("deps").empty()) {
332-
// Skip entries that don't have in-edges or whose edges don't have a
333-
// "deps" attribute. They were in the deps log from previous builds, but
334-
// the the files they were for were removed from the build and their deps
335-
// entries are no longer needed.
336-
// (Without the check for "deps", a chain of two or more nodes that each
337-
// had deps wouldn't be collected in a single recompaction.)
328+
if (!IsDepsEntryLiveFor(nodes_[old_id]))
338329
continue;
339-
}
340330

341331
if (!new_log.RecordDeps(nodes_[old_id], deps->mtime,
342332
deps->node_count, deps->nodes)) {
@@ -364,6 +354,16 @@ bool DepsLog::Recompact(const string& path, string* err) {
364354
return true;
365355
}
366356

357+
bool DepsLog::IsDepsEntryLiveFor(Node* node) {
358+
// Skip entries that don't have in-edges or whose edges don't have a
359+
// "deps" attribute. They were in the deps log from previous builds, but
360+
// the the files they were for were removed from the build and their deps
361+
// entries are no longer needed.
362+
// (Without the check for "deps", a chain of two or more nodes that each
363+
// had deps wouldn't be collected in a single recompaction.)
364+
return node->in_edge() && !node->in_edge()->GetBinding("deps").empty();
365+
}
366+
367367
bool DepsLog::UpdateDeps(int out_id, Deps* deps) {
368368
if (out_id >= (int)deps_.size())
369369
deps_.resize(out_id + 1);

src/deps_log.h

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ struct DepsLog {
8888
/// Rewrite the known log entries, throwing away old data.
8989
bool Recompact(const string& path, string* err);
9090

91+
/// Returns if the deps entry for a node is still reachable from the manifest.
92+
///
93+
/// The deps log can contain deps entries for files that were built in the
94+
/// past but are no longer part of the manifest. This function returns if
95+
/// this is the case for a given node. This function is slow, don't call
96+
/// it from code that runs on every build.
97+
bool IsDepsEntryLiveFor(Node* node);
98+
9199
/// Used for tests.
92100
const vector<Node*>& nodes() const { return nodes_; }
93101
const vector<Deps*>& deps() const { return deps_; }

src/ninja.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ int NinjaMain::ToolDeps(int argc, char** argv) {
449449
if (argc == 0) {
450450
for (vector<Node*>::const_iterator ni = deps_log_.nodes().begin();
451451
ni != deps_log_.nodes().end(); ++ni) {
452-
// Only query for targets with an incoming edge and deps
453-
Edge* e = (*ni)->in_edge();
454-
if (e && !e->GetBinding("deps").empty())
452+
if (deps_log_.IsDepsEntryLiveFor(*ni))
455453
nodes.push_back(*ni);
456454
}
457455
} else {

0 commit comments

Comments
 (0)