diff options
author | tzik <mail@tzik.jp> | 2017-10-25 13:17:40 (GMT) |
---|---|---|
committer | tzik <mail@tzik.jp> | 2017-10-25 14:07:49 (GMT) |
commit | 0b6be4353e4ee330e9b72228ba768b4f2cb56399 (patch) | |
tree | 4a2ca23cf7a422cd5c271c627cfc0fbd15dea98d | |
parent | e234a7bdb6c42f4539c0ab09b624f191287c2c10 (diff) | |
download | Ninja-0b6be4353e4ee330e9b72228ba768b4f2cb56399.zip Ninja-0b6be4353e4ee330e9b72228ba768b4f2cb56399.tar.gz Ninja-0b6be4353e4ee330e9b72228ba768b4f2cb56399.tar.bz2 |
Look up header dependencies on the first-output build
Ninja has special syntax to specify the first output of the given node.
E.g. it builds foo.o for foo.cc^. However, it doesn't work for
headers, as headers usually doesn't appear in the regular dependency
tree.
After this change, Ninja looks up header dependencies from .ninja_deps
to pick up a build target, so that it builds foo.o for foo.h^.
-rw-r--r-- | src/deps_log.cc | 13 | ||||
-rw-r--r-- | src/deps_log.h | 1 | ||||
-rw-r--r-- | src/deps_log_test.cc | 27 | ||||
-rw-r--r-- | src/ninja.cc | 21 |
4 files changed, 54 insertions, 8 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index eb81a37..42e5326 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -310,6 +310,19 @@ DepsLog::Deps* DepsLog::GetDeps(Node* node) { return deps_[node->id()]; } +Node* DepsLog::GetFirstReverseDepsNode(Node* node) { + for (size_t id = 0; id < deps_.size(); ++id) { + Deps* deps = deps_[id]; + if (!deps) + continue; + for (int i = 0; i < deps->node_count; ++i) { + if (deps->nodes[i] == node) + return nodes_[id]; + } + } + return NULL; +} + bool DepsLog::Recompact(const string& path, string* err) { METRIC_RECORD(".ninja_deps recompact"); diff --git a/src/deps_log.h b/src/deps_log.h index 3812a28..1336078 100644 --- a/src/deps_log.h +++ b/src/deps_log.h @@ -86,6 +86,7 @@ struct DepsLog { }; bool Load(const string& path, State* state, string* err); Deps* GetDeps(Node* node); + Node* GetFirstReverseDepsNode(Node* node); /// Rewrite the known log entries, throwing away old data. bool Recompact(const string& path, string* err); diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc index 89f7be1..7daca90 100644 --- a/src/deps_log_test.cc +++ b/src/deps_log_test.cc @@ -476,4 +476,31 @@ TEST_F(DepsLogTest, TruncatedRecovery) { } } +TEST_F(DepsLogTest, ReverseDepsNodes) { + State state; + DepsLog log; + string err; + EXPECT_TRUE(log.OpenForWrite(kTestFilename, &err)); + ASSERT_EQ("", err); + + vector<Node*> deps; + deps.push_back(state.GetNode("foo.h", 0)); + deps.push_back(state.GetNode("bar.h", 0)); + log.RecordDeps(state.GetNode("out.o", 0), 1, deps); + + deps.clear(); + deps.push_back(state.GetNode("foo.h", 0)); + deps.push_back(state.GetNode("bar2.h", 0)); + log.RecordDeps(state.GetNode("out2.o", 0), 2, deps); + + log.Close(); + + Node* rev_deps = log.GetFirstReverseDepsNode(state.GetNode("foo.h", 0)); + EXPECT_TRUE(rev_deps == state.GetNode("out.o", 0) || + rev_deps == state.GetNode("out2.o", 0)); + + rev_deps = log.GetFirstReverseDepsNode(state.GetNode("bar.h", 0)); + EXPECT_TRUE(rev_deps == state.GetNode("out.o", 0)); +} + } // anonymous namespace diff --git a/src/ninja.cc b/src/ninja.cc index 30f89c2..3a7ebbc 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -282,15 +282,20 @@ Node* NinjaMain::CollectTarget(const char* cpath, string* err) { if (node) { if (first_dependent) { if (node->out_edges().empty()) { - *err = "'" + path + "' has no out edge"; - return NULL; - } - Edge* edge = node->out_edges()[0]; - if (edge->outputs_.empty()) { - edge->Dump(); - Fatal("edge has no outputs"); + Node* rev_deps = deps_log_.GetFirstReverseDepsNode(node); + if (!rev_deps) { + *err = "'" + path + "' has no out edge"; + return NULL; + } + node = rev_deps; + } else { + Edge* edge = node->out_edges()[0]; + if (edge->outputs_.empty()) { + edge->Dump(); + Fatal("edge has no outputs"); + } + node = edge->outputs_[0]; } - node = edge->outputs_[0]; } return node; } else { |