diff options
author | David 'Digit' Turner <digit@google.com> | 2023-11-06 13:53:29 (GMT) |
---|---|---|
committer | David 'Digit' Turner <digit+github@google.com> | 2023-11-07 19:10:35 (GMT) |
commit | a744eea2b6c9b37024b12e749e61170e5c87d171 (patch) | |
tree | 24b3aee9fc9d25ac92539459242a82d895fd7c15 /src/build_test.cc | |
parent | 2a2e4703f4c13d89dd97c32497b8af1dad3262f7 (diff) | |
download | Ninja-a744eea2b6c9b37024b12e749e61170e5c87d171.zip Ninja-a744eea2b6c9b37024b12e749e61170e5c87d171.tar.gz Ninja-a744eea2b6c9b37024b12e749e61170e5c87d171.tar.bz2 |
Remove phony edges for nodes created by a dependency loader.
This patch simplifies Ninja internals without modifying
its behavior. It removes the creation (and removal) of phony
edges as producers for nodes loaded by dependency loaders, i.e.
coming from depfiles, dyndep files or the deps log.
These edges were only used to ensure the build did not
abort when these files are missing, unlike regular source
inputs. This can be easily checked by adding a new flag to
the Node class instead. This makes it easier to reason about
how Ninja works internally.
More specifically:
- Move the generated_by_dep_loader_ flag from the Edge class
to the Node class. The flag is true by default to minimize
changes to the source code, since node instances can be
first created by reading the deps or build logs before
the manifest itself.
- Modify Plan::AddSubTarget() to avoid aborting the build
when a generated-by-deploader node is missing. Instead
the function exits immediately, which corresponds to
what happened before.
- State::AddOut(), State::AddIn(), State::AddValidation():
Ensure that nodes added by these methods, which are
only called from the manifest parser and unit-tests
set the |generated_by_dep_loader_| flag to false, to
indicate that these are regular input / output nodes.
- ManifestParser::ParseEdge(): Add an assertion verifying
that the dyndep file is marked as a regular input.
- DyndepLoader::UpdateEdge(): Remove code path that
looked for phony in-edges and ignored them.
- DepLoader::CreatePhonyInEdge() is removed as no
longer necessary.
+ Update a few places in unit-tests that were checking
for the creation of the phony edges.
Fuchsia-Topic: persistent-mode
Change-Id: I98998238002351ef9c7a103040eb8a26d4183969
Diffstat (limited to 'src/build_test.cc')
-rw-r--r-- | src/build_test.cc | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/build_test.cc b/src/build_test.cc index d32ad3e..5ed8245 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -986,9 +986,19 @@ TEST_F(BuildTest, DepFileOK) { ASSERT_EQ(1u, fs_.files_read_.size()); EXPECT_EQ("foo.o.d", fs_.files_read_[0]); - // Expect three new edges: one generating foo.o, and two more from - // loading the depfile. - ASSERT_EQ(orig_edges + 3, (int)state_.edges_.size()); + // Expect one new edge generating foo.o. Loading the depfile should have + // added nodes, but not phony edges to the graph. + ASSERT_EQ(orig_edges + 1, (int)state_.edges_.size()); + + // Verify that nodes for blah.h and bar.h were added and that they + // are marked as generated by a dep loader. + ASSERT_FALSE(state_.LookupNode("foo.o")->generated_by_dep_loader()); + ASSERT_FALSE(state_.LookupNode("foo.c")->generated_by_dep_loader()); + ASSERT_TRUE(state_.LookupNode("blah.h")); + ASSERT_TRUE(state_.LookupNode("blah.h")->generated_by_dep_loader()); + ASSERT_TRUE(state_.LookupNode("bar.h")); + ASSERT_TRUE(state_.LookupNode("bar.h")->generated_by_dep_loader()); + // Expect our edge to now have three inputs: foo.c and two headers. ASSERT_EQ(3u, edge->inputs_.size()); @@ -1154,7 +1164,6 @@ TEST_F(BuildTest, DepFileCanonicalize) { ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, "rule cc\n command = cc $in\n depfile = $out.d\n" "build gen/stuff\\things/foo.o: cc x\\y/z\\foo.c\n")); - Edge* edge = state_.edges_.back(); fs_.Create("x/y/z/foo.c", ""); GetNode("bar.h")->MarkDirty(); // Mark bar.h as missing. @@ -1167,10 +1176,10 @@ TEST_F(BuildTest, DepFileCanonicalize) { // The depfile path does not get Canonicalize as it seems unnecessary. EXPECT_EQ("gen/stuff\\things/foo.o.d", fs_.files_read_[0]); - // Expect three new edges: one generating foo.o, and two more from - // loading the depfile. - ASSERT_EQ(orig_edges + 3, (int)state_.edges_.size()); + // Expect one new edge enerating foo.o. + ASSERT_EQ(orig_edges + 1, (int)state_.edges_.size()); // Expect our edge to now have three inputs: foo.c and two headers. + Edge* edge = state_.edges_.back(); ASSERT_EQ(3u, edge->inputs_.size()); // Expect the command line we generate to only use the original input, and @@ -2968,9 +2977,9 @@ TEST_F(BuildWithDepsLogTest, DepFileOKDepsLog) { EXPECT_TRUE(builder.AddTarget("fo o.o", &err)); ASSERT_EQ("", err); - // Expect three new edges: one generating fo o.o, and two more from - // loading the depfile. - ASSERT_EQ(3u, state.edges_.size()); + // Expect one new edge generating fo o.o, loading the depfile should + // note generate new edges. + ASSERT_EQ(1u, state.edges_.size()); // Expect our edge to now have three inputs: foo.c and two headers. ASSERT_EQ(3u, edge->inputs_.size()); @@ -3110,16 +3119,14 @@ TEST_F(BuildWithDepsLogTest, DepFileDepsLogCanonicalize) { Builder builder(&state, config_, NULL, &deps_log, &fs_, &status_, 0); builder.command_runner_.reset(&command_runner_); - Edge* edge = state.edges_.back(); - state.GetNode("bar.h", 0)->MarkDirty(); // Mark bar.h as missing. EXPECT_TRUE(builder.AddTarget("a/b/c/d/e/fo o.o", &err)); ASSERT_EQ("", err); - // Expect three new edges: one generating fo o.o, and two more from - // loading the depfile. - ASSERT_EQ(3u, state.edges_.size()); + // Expect one new edge generating fo o.o. + ASSERT_EQ(1u, state.edges_.size()); // Expect our edge to now have three inputs: foo.c and two headers. + Edge* edge = state.edges_.back(); ASSERT_EQ(3u, edge->inputs_.size()); // Expect the command line we generate to only use the original input. @@ -3675,8 +3682,8 @@ TEST_F(BuildTest, DyndepBuildDiscoverOutputAndDepfileInput) { EXPECT_TRUE(builder_.AddTarget("out", &err)); ASSERT_EQ("", err); - // Loading the depfile gave tmp.imp a phony input edge. - ASSERT_TRUE(GetNode("tmp.imp")->in_edge()->is_phony()); + // Loading the depfile did not give tmp.imp a phony input edge. + ASSERT_FALSE(GetNode("tmp.imp")->in_edge()); EXPECT_TRUE(builder_.Build(&err)); EXPECT_EQ("", err); |