1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
19 #include "build_log.h"
24 /// Fixture for tests involving Plan.
25 // Though Plan doesn't use State, it's useful to have one around
26 // to create Nodes and Edges.
27 struct PlanTest : public StateTestWithBuiltinRules {
30 /// Because FindWork does not return Edges in any sort of predictable order,
31 // provide a means to get available Edges in order and in a format which is
32 // easy to write tests around.
33 void FindWorkSorted(deque<Edge*>* ret, int count) {
34 struct CompareEdgesByOutput {
35 static bool cmp(const Edge* a, const Edge* b) {
36 return a->outputs_[0]->path() < b->outputs_[0]->path();
40 for (int i = 0; i < count; ++i) {
41 ASSERT_TRUE(plan_.more_to_do());
42 Edge* edge = plan_.FindWork();
46 ASSERT_FALSE(plan_.FindWork());
47 sort(ret->begin(), ret->end(), CompareEdgesByOutput::cmp);
50 void TestPoolWithDepthOne(const char *test_case);
53 TEST_F(PlanTest, Basic) {
54 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
55 "build out: cat mid\n"
56 "build mid: cat in\n"));
57 GetNode("mid")->MarkDirty();
58 GetNode("out")->MarkDirty();
60 EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
62 ASSERT_TRUE(plan_.more_to_do());
64 Edge* edge = plan_.FindWork();
66 ASSERT_EQ("in", edge->inputs_[0]->path());
67 ASSERT_EQ("mid", edge->outputs_[0]->path());
69 ASSERT_FALSE(plan_.FindWork());
71 plan_.EdgeFinished(edge, true);
73 edge = plan_.FindWork();
75 ASSERT_EQ("mid", edge->inputs_[0]->path());
76 ASSERT_EQ("out", edge->outputs_[0]->path());
78 plan_.EdgeFinished(edge, true);
80 ASSERT_FALSE(plan_.more_to_do());
81 edge = plan_.FindWork();
85 // Test that two outputs from one rule can be handled as inputs to the next.
86 TEST_F(PlanTest, DoubleOutputDirect) {
87 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
88 "build out: cat mid1 mid2\n"
89 "build mid1 mid2: cat in\n"));
90 GetNode("mid1")->MarkDirty();
91 GetNode("mid2")->MarkDirty();
92 GetNode("out")->MarkDirty();
95 EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
97 ASSERT_TRUE(plan_.more_to_do());
100 edge = plan_.FindWork();
101 ASSERT_TRUE(edge); // cat in
102 plan_.EdgeFinished(edge, true);
104 edge = plan_.FindWork();
105 ASSERT_TRUE(edge); // cat mid1 mid2
106 plan_.EdgeFinished(edge, true);
108 edge = plan_.FindWork();
109 ASSERT_FALSE(edge); // done
112 // Test that two outputs from one rule can eventually be routed to another.
113 TEST_F(PlanTest, DoubleOutputIndirect) {
114 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
115 "build out: cat b1 b2\n"
118 "build a1 a2: cat in\n"));
119 GetNode("a1")->MarkDirty();
120 GetNode("a2")->MarkDirty();
121 GetNode("b1")->MarkDirty();
122 GetNode("b2")->MarkDirty();
123 GetNode("out")->MarkDirty();
125 EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
127 ASSERT_TRUE(plan_.more_to_do());
130 edge = plan_.FindWork();
131 ASSERT_TRUE(edge); // cat in
132 plan_.EdgeFinished(edge, true);
134 edge = plan_.FindWork();
135 ASSERT_TRUE(edge); // cat a1
136 plan_.EdgeFinished(edge, true);
138 edge = plan_.FindWork();
139 ASSERT_TRUE(edge); // cat a2
140 plan_.EdgeFinished(edge, true);
142 edge = plan_.FindWork();
143 ASSERT_TRUE(edge); // cat b1 b2
144 plan_.EdgeFinished(edge, true);
146 edge = plan_.FindWork();
147 ASSERT_FALSE(edge); // done
150 // Test that two edges from one output can both execute.
151 TEST_F(PlanTest, DoubleDependent) {
152 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
153 "build out: cat a1 a2\n"
154 "build a1: cat mid\n"
155 "build a2: cat mid\n"
156 "build mid: cat in\n"));
157 GetNode("mid")->MarkDirty();
158 GetNode("a1")->MarkDirty();
159 GetNode("a2")->MarkDirty();
160 GetNode("out")->MarkDirty();
163 EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
165 ASSERT_TRUE(plan_.more_to_do());
168 edge = plan_.FindWork();
169 ASSERT_TRUE(edge); // cat in
170 plan_.EdgeFinished(edge, true);
172 edge = plan_.FindWork();
173 ASSERT_TRUE(edge); // cat mid
174 plan_.EdgeFinished(edge, true);
176 edge = plan_.FindWork();
177 ASSERT_TRUE(edge); // cat mid
178 plan_.EdgeFinished(edge, true);
180 edge = plan_.FindWork();
181 ASSERT_TRUE(edge); // cat a1 a2
182 plan_.EdgeFinished(edge, true);
184 edge = plan_.FindWork();
185 ASSERT_FALSE(edge); // done
188 TEST_F(PlanTest, DependencyCycle) {
189 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
190 "build out: cat mid\n"
191 "build mid: cat in\n"
192 "build in: cat pre\n"
193 "build pre: cat out\n"));
194 GetNode("out")->MarkDirty();
195 GetNode("mid")->MarkDirty();
196 GetNode("in")->MarkDirty();
197 GetNode("pre")->MarkDirty();
200 EXPECT_FALSE(plan_.AddTarget(GetNode("out"), &err));
201 ASSERT_EQ("dependency cycle: out -> mid -> in -> pre -> out", err);
204 TEST_F(PlanTest, CycleInEdgesButNotInNodes1) {
206 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
207 "build a b: cat a\n"));
208 EXPECT_FALSE(plan_.AddTarget(GetNode("b"), &err));
209 ASSERT_EQ("dependency cycle: a -> a", err);
212 TEST_F(PlanTest, CycleInEdgesButNotInNodes2) {
214 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
215 "build b a: cat a\n"));
216 EXPECT_FALSE(plan_.AddTarget(GetNode("b"), &err));
217 ASSERT_EQ("dependency cycle: a -> a", err);
220 TEST_F(PlanTest, CycleInEdgesButNotInNodes3) {
222 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
224 "build c: cat a\n"));
225 EXPECT_FALSE(plan_.AddTarget(GetNode("b"), &err));
226 ASSERT_EQ("dependency cycle: c -> a -> c", err);
229 TEST_F(PlanTest, CycleInEdgesButNotInNodes4) {
231 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
236 "build f: cat e\n"));
237 EXPECT_FALSE(plan_.AddTarget(GetNode("f"), &err));
238 ASSERT_EQ("dependency cycle: d -> c -> b -> a -> d", err);
241 void PlanTest::TestPoolWithDepthOne(const char* test_case) {
242 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, test_case));
243 GetNode("out1")->MarkDirty();
244 GetNode("out2")->MarkDirty();
246 EXPECT_TRUE(plan_.AddTarget(GetNode("out1"), &err));
248 EXPECT_TRUE(plan_.AddTarget(GetNode("out2"), &err));
250 ASSERT_TRUE(plan_.more_to_do());
252 Edge* edge = plan_.FindWork();
254 ASSERT_EQ("in", edge->inputs_[0]->path());
255 ASSERT_EQ("out1", edge->outputs_[0]->path());
257 // This will be false since poolcat is serialized
258 ASSERT_FALSE(plan_.FindWork());
260 plan_.EdgeFinished(edge, true);
262 edge = plan_.FindWork();
264 ASSERT_EQ("in", edge->inputs_[0]->path());
265 ASSERT_EQ("out2", edge->outputs_[0]->path());
267 ASSERT_FALSE(plan_.FindWork());
269 plan_.EdgeFinished(edge, true);
271 ASSERT_FALSE(plan_.more_to_do());
272 edge = plan_.FindWork();
276 TEST_F(PlanTest, PoolWithDepthOne) {
277 TestPoolWithDepthOne(
281 " command = cat $in > $out\n"
283 "build out1: poolcat in\n"
284 "build out2: poolcat in\n");
287 TEST_F(PlanTest, ConsolePool) {
288 TestPoolWithDepthOne(
290 " command = cat $in > $out\n"
292 "build out1: poolcat in\n"
293 "build out2: poolcat in\n");
296 TEST_F(PlanTest, PoolsWithDepthTwo) {
297 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
303 " command = cat $in > $out\n"
306 " command = cat $in > $out\n"
308 "build out1: foocat in\n"
309 "build out2: foocat in\n"
310 "build out3: foocat in\n"
311 "build outb1: bazcat in\n"
312 "build outb2: bazcat in\n"
313 "build outb3: bazcat in\n"
315 "build allTheThings: cat out1 out2 out3 outb1 outb2 outb3\n"
317 // Mark all the out* nodes dirty
318 for (int i = 0; i < 3; ++i) {
319 GetNode("out" + string(1, '1' + static_cast<char>(i)))->MarkDirty();
320 GetNode("outb" + string(1, '1' + static_cast<char>(i)))->MarkDirty();
322 GetNode("allTheThings")->MarkDirty();
325 EXPECT_TRUE(plan_.AddTarget(GetNode("allTheThings"), &err));
329 FindWorkSorted(&edges, 5);
331 for (int i = 0; i < 4; ++i) {
332 Edge *edge = edges[i];
333 ASSERT_EQ("in", edge->inputs_[0]->path());
334 string base_name(i < 2 ? "out" : "outb");
335 ASSERT_EQ(base_name + string(1, '1' + (i % 2)), edge->outputs_[0]->path());
338 // outb3 is exempt because it has an empty pool
339 Edge* edge = edges[4];
341 ASSERT_EQ("in", edge->inputs_[0]->path());
342 ASSERT_EQ("outb3", edge->outputs_[0]->path());
345 plan_.EdgeFinished(edges.front(), true);
348 // out3 should be available
349 Edge* out3 = plan_.FindWork();
351 ASSERT_EQ("in", out3->inputs_[0]->path());
352 ASSERT_EQ("out3", out3->outputs_[0]->path());
354 ASSERT_FALSE(plan_.FindWork());
356 plan_.EdgeFinished(out3, true);
358 ASSERT_FALSE(plan_.FindWork());
360 for (deque<Edge*>::iterator it = edges.begin(); it != edges.end(); ++it) {
361 plan_.EdgeFinished(*it, true);
364 Edge* last = plan_.FindWork();
366 ASSERT_EQ("allTheThings", last->outputs_[0]->path());
368 plan_.EdgeFinished(last, true);
370 ASSERT_FALSE(plan_.more_to_do());
371 ASSERT_FALSE(plan_.FindWork());
374 TEST_F(PlanTest, PoolWithRedundantEdges) {
375 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
379 " command = touch foo.cpp\n"
381 " command = touch bar.cpp\n"
383 " command = echo $out > $out\n"
384 "build foo.cpp.obj: echo foo.cpp || foo.cpp\n"
386 "build bar.cpp.obj: echo bar.cpp || bar.cpp\n"
388 "build libfoo.a: echo foo.cpp.obj bar.cpp.obj\n"
389 "build foo.cpp: gen_foo\n"
390 "build bar.cpp: gen_bar\n"
391 "build all: phony libfoo.a\n"));
392 GetNode("foo.cpp")->MarkDirty();
393 GetNode("foo.cpp.obj")->MarkDirty();
394 GetNode("bar.cpp")->MarkDirty();
395 GetNode("bar.cpp.obj")->MarkDirty();
396 GetNode("libfoo.a")->MarkDirty();
397 GetNode("all")->MarkDirty();
399 EXPECT_TRUE(plan_.AddTarget(GetNode("all"), &err));
401 ASSERT_TRUE(plan_.more_to_do());
405 deque<Edge*> initial_edges;
406 FindWorkSorted(&initial_edges, 2);
408 edge = initial_edges[1]; // Foo first
409 ASSERT_EQ("foo.cpp", edge->outputs_[0]->path());
410 plan_.EdgeFinished(edge, true);
412 edge = plan_.FindWork();
414 ASSERT_FALSE(plan_.FindWork());
415 ASSERT_EQ("foo.cpp", edge->inputs_[0]->path());
416 ASSERT_EQ("foo.cpp", edge->inputs_[1]->path());
417 ASSERT_EQ("foo.cpp.obj", edge->outputs_[0]->path());
418 plan_.EdgeFinished(edge, true);
420 edge = initial_edges[0]; // Now for bar
421 ASSERT_EQ("bar.cpp", edge->outputs_[0]->path());
422 plan_.EdgeFinished(edge, true);
424 edge = plan_.FindWork();
426 ASSERT_FALSE(plan_.FindWork());
427 ASSERT_EQ("bar.cpp", edge->inputs_[0]->path());
428 ASSERT_EQ("bar.cpp", edge->inputs_[1]->path());
429 ASSERT_EQ("bar.cpp.obj", edge->outputs_[0]->path());
430 plan_.EdgeFinished(edge, true);
432 edge = plan_.FindWork();
434 ASSERT_FALSE(plan_.FindWork());
435 ASSERT_EQ("foo.cpp.obj", edge->inputs_[0]->path());
436 ASSERT_EQ("bar.cpp.obj", edge->inputs_[1]->path());
437 ASSERT_EQ("libfoo.a", edge->outputs_[0]->path());
438 plan_.EdgeFinished(edge, true);
440 edge = plan_.FindWork();
442 ASSERT_FALSE(plan_.FindWork());
443 ASSERT_EQ("libfoo.a", edge->inputs_[0]->path());
444 ASSERT_EQ("all", edge->outputs_[0]->path());
445 plan_.EdgeFinished(edge, true);
447 edge = plan_.FindWork();
449 ASSERT_FALSE(plan_.more_to_do());
452 TEST_F(PlanTest, PoolWithFailingEdge) {
453 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
457 " command = cat $in > $out\n"
459 "build out1: poolcat in\n"
460 "build out2: poolcat in\n"));
461 GetNode("out1")->MarkDirty();
462 GetNode("out2")->MarkDirty();
464 EXPECT_TRUE(plan_.AddTarget(GetNode("out1"), &err));
466 EXPECT_TRUE(plan_.AddTarget(GetNode("out2"), &err));
468 ASSERT_TRUE(plan_.more_to_do());
470 Edge* edge = plan_.FindWork();
472 ASSERT_EQ("in", edge->inputs_[0]->path());
473 ASSERT_EQ("out1", edge->outputs_[0]->path());
475 // This will be false since poolcat is serialized
476 ASSERT_FALSE(plan_.FindWork());
478 plan_.EdgeFinished(edge, false);
480 edge = plan_.FindWork();
482 ASSERT_EQ("in", edge->inputs_[0]->path());
483 ASSERT_EQ("out2", edge->outputs_[0]->path());
485 ASSERT_FALSE(plan_.FindWork());
487 plan_.EdgeFinished(edge, false);
489 ASSERT_TRUE(plan_.more_to_do()); // Jobs have failed
490 edge = plan_.FindWork();
494 /// Fake implementation of CommandRunner, useful for tests.
495 struct FakeCommandRunner : public CommandRunner {
496 explicit FakeCommandRunner(VirtualFileSystem* fs) :
497 last_command_(NULL), fs_(fs) {}
499 // CommandRunner impl
500 virtual bool CanRunMore();
501 virtual bool StartCommand(Edge* edge);
502 virtual bool WaitForCommand(Result* result);
503 virtual vector<Edge*> GetActiveEdges();
504 virtual void Abort();
506 vector<string> commands_ran_;
508 VirtualFileSystem* fs_;
511 struct BuildTest : public StateTestWithBuiltinRules, public BuildLogUser {
512 BuildTest() : config_(MakeConfig()), command_runner_(&fs_),
513 builder_(&state_, config_, NULL, NULL, &fs_),
517 virtual void SetUp() {
518 StateTestWithBuiltinRules::SetUp();
520 builder_.command_runner_.reset(&command_runner_);
522 "build cat1: cat in1\n"
523 "build cat2: cat in1 in2\n"
524 "build cat12: cat cat1 cat2\n");
526 fs_.Create("in1", "");
527 fs_.Create("in2", "");
531 builder_.command_runner_.release();
534 virtual bool IsPathDead(StringPiece s) const { return false; }
536 /// Rebuild target in the 'working tree' (fs_).
537 /// State of command_runner_ and logs contents (if specified) ARE MODIFIED.
538 /// Handy to check for NOOP builds, and higher-level rebuild tests.
539 void RebuildTarget(const string& target, const char* manifest,
540 const char* log_path = NULL, const char* deps_path = NULL,
541 State* state = NULL);
543 // Mark a path dirty.
544 void Dirty(const string& path);
546 BuildConfig MakeConfig() {
548 config.verbosity = BuildConfig::QUIET;
553 FakeCommandRunner command_runner_;
554 VirtualFileSystem fs_;
560 void BuildTest::RebuildTarget(const string& target, const char* manifest,
561 const char* log_path, const char* deps_path,
563 State local_state, *pstate = &local_state;
566 ASSERT_NO_FATAL_FAILURE(AddCatRule(pstate));
567 AssertParse(pstate, manifest);
570 BuildLog build_log, *pbuild_log = NULL;
572 ASSERT_TRUE(build_log.Load(log_path, &err));
573 ASSERT_TRUE(build_log.OpenForWrite(log_path, *this, &err));
575 pbuild_log = &build_log;
578 DepsLog deps_log, *pdeps_log = NULL;
580 ASSERT_TRUE(deps_log.Load(deps_path, pstate, &err));
581 ASSERT_TRUE(deps_log.OpenForWrite(deps_path, &err));
583 pdeps_log = &deps_log;
586 Builder builder(pstate, config_, pbuild_log, pdeps_log, &fs_);
587 EXPECT_TRUE(builder.AddTarget(target, &err));
589 command_runner_.commands_ran_.clear();
590 builder.command_runner_.reset(&command_runner_);
591 if (!builder.AlreadyUpToDate()) {
592 bool build_res = builder.Build(&err);
593 EXPECT_TRUE(build_res);
595 builder.command_runner_.release();
598 bool FakeCommandRunner::CanRunMore() {
599 // Only run one at a time.
600 return last_command_ == NULL;
603 bool FakeCommandRunner::StartCommand(Edge* edge) {
604 assert(!last_command_);
605 commands_ran_.push_back(edge->EvaluateCommand());
606 if (edge->rule().name() == "cat" ||
607 edge->rule().name() == "cat_rsp" ||
608 edge->rule().name() == "cat_rsp_out" ||
609 edge->rule().name() == "cc" ||
610 edge->rule().name() == "touch" ||
611 edge->rule().name() == "touch-interrupt") {
612 for (vector<Node*>::iterator out = edge->outputs_.begin();
613 out != edge->outputs_.end(); ++out) {
614 fs_->Create((*out)->path(), "");
616 } else if (edge->rule().name() == "true" ||
617 edge->rule().name() == "fail" ||
618 edge->rule().name() == "interrupt" ||
619 edge->rule().name() == "console") {
620 // Don't do anything.
622 printf("unknown command\n");
626 last_command_ = edge;
630 bool FakeCommandRunner::WaitForCommand(Result* result) {
634 Edge* edge = last_command_;
637 if (edge->rule().name() == "interrupt" ||
638 edge->rule().name() == "touch-interrupt") {
639 result->status = ExitInterrupted;
643 if (edge->rule().name() == "console") {
644 if (edge->use_console())
645 result->status = ExitSuccess;
647 result->status = ExitFailure;
648 last_command_ = NULL;
652 if (edge->rule().name() == "fail")
653 result->status = ExitFailure;
655 result->status = ExitSuccess;
656 last_command_ = NULL;
660 vector<Edge*> FakeCommandRunner::GetActiveEdges() {
663 edges.push_back(last_command_);
667 void FakeCommandRunner::Abort() {
668 last_command_ = NULL;
671 void BuildTest::Dirty(const string& path) {
672 Node* node = GetNode(path);
675 // If it's an input file, mark that we've already stat()ed it and
677 if (!node->in_edge())
681 TEST_F(BuildTest, NoWork) {
683 EXPECT_TRUE(builder_.AlreadyUpToDate());
686 TEST_F(BuildTest, OneStep) {
687 // Given a dirty target with one ready input,
688 // we should rebuild the target.
691 EXPECT_TRUE(builder_.AddTarget("cat1", &err));
693 EXPECT_TRUE(builder_.Build(&err));
696 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
697 EXPECT_EQ("cat in1 > cat1", command_runner_.commands_ran_[0]);
700 TEST_F(BuildTest, OneStep2) {
701 // Given a target with one dirty input,
702 // we should rebuild the target.
705 EXPECT_TRUE(builder_.AddTarget("cat1", &err));
707 EXPECT_TRUE(builder_.Build(&err));
710 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
711 EXPECT_EQ("cat in1 > cat1", command_runner_.commands_ran_[0]);
714 TEST_F(BuildTest, TwoStep) {
716 EXPECT_TRUE(builder_.AddTarget("cat12", &err));
718 EXPECT_TRUE(builder_.Build(&err));
720 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
721 // Depending on how the pointers work out, we could've ran
722 // the first two commands in either order.
723 EXPECT_TRUE((command_runner_.commands_ran_[0] == "cat in1 > cat1" &&
724 command_runner_.commands_ran_[1] == "cat in1 in2 > cat2") ||
725 (command_runner_.commands_ran_[1] == "cat in1 > cat1" &&
726 command_runner_.commands_ran_[0] == "cat in1 in2 > cat2"));
728 EXPECT_EQ("cat cat1 cat2 > cat12", command_runner_.commands_ran_[2]);
732 // Modifying in2 requires rebuilding one intermediate file
733 // and the final file.
734 fs_.Create("in2", "");
736 EXPECT_TRUE(builder_.AddTarget("cat12", &err));
738 EXPECT_TRUE(builder_.Build(&err));
740 ASSERT_EQ(5u, command_runner_.commands_ran_.size());
741 EXPECT_EQ("cat in1 in2 > cat2", command_runner_.commands_ran_[3]);
742 EXPECT_EQ("cat cat1 cat2 > cat12", command_runner_.commands_ran_[4]);
745 TEST_F(BuildTest, TwoOutputs) {
746 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
748 " command = touch $out\n"
749 "build out1 out2: touch in.txt\n"));
751 fs_.Create("in.txt", "");
754 EXPECT_TRUE(builder_.AddTarget("out1", &err));
756 EXPECT_TRUE(builder_.Build(&err));
758 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
759 EXPECT_EQ("touch out1 out2", command_runner_.commands_ran_[0]);
762 TEST_F(BuildTest, ImplicitOutput) {
763 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
765 " command = touch $out $out.imp\n"
766 "build out | out.imp: touch in.txt\n"));
767 fs_.Create("in.txt", "");
770 EXPECT_TRUE(builder_.AddTarget("out.imp", &err));
772 EXPECT_TRUE(builder_.Build(&err));
774 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
775 EXPECT_EQ("touch out out.imp", command_runner_.commands_ran_[0]);
779 // https://github.com/ninja-build/ninja/issues/148
780 TEST_F(BuildTest, MultiOutIn) {
781 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
783 " command = touch $out\n"
784 "build in1 otherfile: touch in\n"
785 "build out: touch in | in1\n"));
787 fs_.Create("in", "");
789 fs_.Create("in1", "");
792 EXPECT_TRUE(builder_.AddTarget("out", &err));
794 EXPECT_TRUE(builder_.Build(&err));
798 TEST_F(BuildTest, Chain) {
799 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
803 "build c5: cat c4\n"));
805 fs_.Create("c1", "");
808 EXPECT_TRUE(builder_.AddTarget("c5", &err));
810 EXPECT_TRUE(builder_.Build(&err));
812 ASSERT_EQ(4u, command_runner_.commands_ran_.size());
815 command_runner_.commands_ran_.clear();
817 EXPECT_TRUE(builder_.AddTarget("c5", &err));
819 EXPECT_TRUE(builder_.AlreadyUpToDate());
823 fs_.Create("c3", "");
825 command_runner_.commands_ran_.clear();
827 EXPECT_TRUE(builder_.AddTarget("c5", &err));
829 EXPECT_FALSE(builder_.AlreadyUpToDate());
830 EXPECT_TRUE(builder_.Build(&err));
831 ASSERT_EQ(2u, command_runner_.commands_ran_.size()); // 3->4, 4->5
834 TEST_F(BuildTest, MissingInput) {
835 // Input is referenced by build file, but no rule for it.
838 EXPECT_FALSE(builder_.AddTarget("cat1", &err));
839 EXPECT_EQ("'in1', needed by 'cat1', missing and no known rule to make it",
843 TEST_F(BuildTest, MissingTarget) {
844 // Target is not referenced by build file.
846 EXPECT_FALSE(builder_.AddTarget("meow", &err));
847 EXPECT_EQ("unknown target: 'meow'", err);
850 TEST_F(BuildTest, MakeDirs) {
854 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
855 "build subdir\\dir2\\file: cat in1\n"));
857 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
858 "build subdir/dir2/file: cat in1\n"));
860 EXPECT_TRUE(builder_.AddTarget("subdir/dir2/file", &err));
863 EXPECT_TRUE(builder_.Build(&err));
865 ASSERT_EQ(2u, fs_.directories_made_.size());
866 EXPECT_EQ("subdir", fs_.directories_made_[0]);
867 EXPECT_EQ("subdir/dir2", fs_.directories_made_[1]);
870 TEST_F(BuildTest, DepFileMissing) {
872 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
873 "rule cc\n command = cc $in\n depfile = $out.d\n"
874 "build fo$ o.o: cc foo.c\n"));
875 fs_.Create("foo.c", "");
877 EXPECT_TRUE(builder_.AddTarget("fo o.o", &err));
879 ASSERT_EQ(1u, fs_.files_read_.size());
880 EXPECT_EQ("fo o.o.d", fs_.files_read_[0]);
883 TEST_F(BuildTest, DepFileOK) {
885 int orig_edges = state_.edges_.size();
886 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
887 "rule cc\n command = cc $in\n depfile = $out.d\n"
888 "build foo.o: cc foo.c\n"));
889 Edge* edge = state_.edges_.back();
891 fs_.Create("foo.c", "");
892 GetNode("bar.h")->MarkDirty(); // Mark bar.h as missing.
893 fs_.Create("foo.o.d", "foo.o: blah.h bar.h\n");
894 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
896 ASSERT_EQ(1u, fs_.files_read_.size());
897 EXPECT_EQ("foo.o.d", fs_.files_read_[0]);
899 // Expect three new edges: one generating foo.o, and two more from
900 // loading the depfile.
901 ASSERT_EQ(orig_edges + 3, (int)state_.edges_.size());
902 // Expect our edge to now have three inputs: foo.c and two headers.
903 ASSERT_EQ(3u, edge->inputs_.size());
905 // Expect the command line we generate to only use the original input.
906 ASSERT_EQ("cc foo.c", edge->EvaluateCommand());
909 TEST_F(BuildTest, DepFileParseError) {
911 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
912 "rule cc\n command = cc $in\n depfile = $out.d\n"
913 "build foo.o: cc foo.c\n"));
914 fs_.Create("foo.c", "");
915 fs_.Create("foo.o.d", "randomtext\n");
916 EXPECT_FALSE(builder_.AddTarget("foo.o", &err));
917 EXPECT_EQ("foo.o.d: expected ':' in depfile", err);
920 TEST_F(BuildTest, OrderOnlyDeps) {
922 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
923 "rule cc\n command = cc $in\n depfile = $out.d\n"
924 "build foo.o: cc foo.c || otherfile\n"));
925 Edge* edge = state_.edges_.back();
927 fs_.Create("foo.c", "");
928 fs_.Create("otherfile", "");
929 fs_.Create("foo.o.d", "foo.o: blah.h bar.h\n");
930 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
933 // One explicit, two implicit, one order only.
934 ASSERT_EQ(4u, edge->inputs_.size());
935 EXPECT_EQ(2, edge->implicit_deps_);
936 EXPECT_EQ(1, edge->order_only_deps_);
937 // Verify the inputs are in the order we expect
938 // (explicit then implicit then orderonly).
939 EXPECT_EQ("foo.c", edge->inputs_[0]->path());
940 EXPECT_EQ("blah.h", edge->inputs_[1]->path());
941 EXPECT_EQ("bar.h", edge->inputs_[2]->path());
942 EXPECT_EQ("otherfile", edge->inputs_[3]->path());
944 // Expect the command line we generate to only use the original input.
945 ASSERT_EQ("cc foo.c", edge->EvaluateCommand());
947 // explicit dep dirty, expect a rebuild.
948 EXPECT_TRUE(builder_.Build(&err));
950 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
954 // Recreate the depfile, as it should have been deleted by the build.
955 fs_.Create("foo.o.d", "foo.o: blah.h bar.h\n");
957 // implicit dep dirty, expect a rebuild.
958 fs_.Create("blah.h", "");
959 fs_.Create("bar.h", "");
960 command_runner_.commands_ran_.clear();
962 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
963 EXPECT_TRUE(builder_.Build(&err));
965 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
969 // Recreate the depfile, as it should have been deleted by the build.
970 fs_.Create("foo.o.d", "foo.o: blah.h bar.h\n");
972 // order only dep dirty, no rebuild.
973 fs_.Create("otherfile", "");
974 command_runner_.commands_ran_.clear();
976 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
978 EXPECT_TRUE(builder_.AlreadyUpToDate());
980 // implicit dep missing, expect rebuild.
981 fs_.RemoveFile("bar.h");
982 command_runner_.commands_ran_.clear();
984 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
985 EXPECT_TRUE(builder_.Build(&err));
987 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
990 TEST_F(BuildTest, RebuildOrderOnlyDeps) {
992 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
993 "rule cc\n command = cc $in\n"
994 "rule true\n command = true\n"
995 "build oo.h: cc oo.h.in\n"
996 "build foo.o: cc foo.c || oo.h\n"));
998 fs_.Create("foo.c", "");
999 fs_.Create("oo.h.in", "");
1001 // foo.o and order-only dep dirty, build both.
1002 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
1003 EXPECT_TRUE(builder_.Build(&err));
1005 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
1007 // all clean, no rebuild.
1008 command_runner_.commands_ran_.clear();
1010 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
1012 EXPECT_TRUE(builder_.AlreadyUpToDate());
1014 // order-only dep missing, build it only.
1015 fs_.RemoveFile("oo.h");
1016 command_runner_.commands_ran_.clear();
1018 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
1019 EXPECT_TRUE(builder_.Build(&err));
1021 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1022 ASSERT_EQ("cc oo.h.in", command_runner_.commands_ran_[0]);
1026 // order-only dep dirty, build it only.
1027 fs_.Create("oo.h.in", "");
1028 command_runner_.commands_ran_.clear();
1030 EXPECT_TRUE(builder_.AddTarget("foo.o", &err));
1031 EXPECT_TRUE(builder_.Build(&err));
1033 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1034 ASSERT_EQ("cc oo.h.in", command_runner_.commands_ran_[0]);
1038 TEST_F(BuildTest, DepFileCanonicalize) {
1040 int orig_edges = state_.edges_.size();
1041 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1042 "rule cc\n command = cc $in\n depfile = $out.d\n"
1043 "build gen/stuff\\things/foo.o: cc x\\y/z\\foo.c\n"));
1044 Edge* edge = state_.edges_.back();
1046 fs_.Create("x/y/z/foo.c", "");
1047 GetNode("bar.h")->MarkDirty(); // Mark bar.h as missing.
1048 // Note, different slashes from manifest.
1049 fs_.Create("gen/stuff\\things/foo.o.d",
1050 "gen\\stuff\\things\\foo.o: blah.h bar.h\n");
1051 EXPECT_TRUE(builder_.AddTarget("gen/stuff/things/foo.o", &err));
1053 ASSERT_EQ(1u, fs_.files_read_.size());
1054 // The depfile path does not get Canonicalize as it seems unnecessary.
1055 EXPECT_EQ("gen/stuff\\things/foo.o.d", fs_.files_read_[0]);
1057 // Expect three new edges: one generating foo.o, and two more from
1058 // loading the depfile.
1059 ASSERT_EQ(orig_edges + 3, (int)state_.edges_.size());
1060 // Expect our edge to now have three inputs: foo.c and two headers.
1061 ASSERT_EQ(3u, edge->inputs_.size());
1063 // Expect the command line we generate to only use the original input, and
1064 // using the slashes from the manifest.
1065 ASSERT_EQ("cc x\\y/z\\foo.c", edge->EvaluateCommand());
1069 TEST_F(BuildTest, Phony) {
1071 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1072 "build out: cat bar.cc\n"
1073 "build all: phony out\n"));
1074 fs_.Create("bar.cc", "");
1076 EXPECT_TRUE(builder_.AddTarget("all", &err));
1079 // Only one command to run, because phony runs no command.
1080 EXPECT_FALSE(builder_.AlreadyUpToDate());
1081 EXPECT_TRUE(builder_.Build(&err));
1083 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1086 TEST_F(BuildTest, PhonyNoWork) {
1088 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1089 "build out: cat bar.cc\n"
1090 "build all: phony out\n"));
1091 fs_.Create("bar.cc", "");
1092 fs_.Create("out", "");
1094 EXPECT_TRUE(builder_.AddTarget("all", &err));
1096 EXPECT_TRUE(builder_.AlreadyUpToDate());
1099 TEST_F(BuildTest, Fail) {
1100 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1103 "build out1: fail\n"));
1106 EXPECT_TRUE(builder_.AddTarget("out1", &err));
1109 EXPECT_FALSE(builder_.Build(&err));
1110 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1111 ASSERT_EQ("subcommand failed", err);
1114 TEST_F(BuildTest, SwallowFailures) {
1115 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1118 "build out1: fail\n"
1119 "build out2: fail\n"
1120 "build out3: fail\n"
1121 "build all: phony out1 out2 out3\n"));
1123 // Swallow two failures, die on the third.
1124 config_.failures_allowed = 3;
1127 EXPECT_TRUE(builder_.AddTarget("all", &err));
1130 EXPECT_FALSE(builder_.Build(&err));
1131 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1132 ASSERT_EQ("subcommands failed", err);
1135 TEST_F(BuildTest, SwallowFailuresLimit) {
1136 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1139 "build out1: fail\n"
1140 "build out2: fail\n"
1141 "build out3: fail\n"
1142 "build final: cat out1 out2 out3\n"));
1144 // Swallow ten failures; we should stop before building final.
1145 config_.failures_allowed = 11;
1148 EXPECT_TRUE(builder_.AddTarget("final", &err));
1151 EXPECT_FALSE(builder_.Build(&err));
1152 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1153 ASSERT_EQ("cannot make progress due to previous errors", err);
1156 TEST_F(BuildTest, SwallowFailuresPool) {
1157 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1162 " pool = failpool\n"
1163 "build out1: fail\n"
1164 "build out2: fail\n"
1165 "build out3: fail\n"
1166 "build final: cat out1 out2 out3\n"));
1168 // Swallow ten failures; we should stop before building final.
1169 config_.failures_allowed = 11;
1172 EXPECT_TRUE(builder_.AddTarget("final", &err));
1175 EXPECT_FALSE(builder_.Build(&err));
1176 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1177 ASSERT_EQ("cannot make progress due to previous errors", err);
1180 TEST_F(BuildTest, PoolEdgesReadyButNotWanted) {
1181 fs_.Create("x", "");
1183 const char* manifest =
1187 " command = touch $out\n"
1188 " pool = some_pool\n"
1190 " command = touch grit\n"
1192 "build B.d.stamp: cc | x\n"
1193 "build C.stamp: touch B.d.stamp\n"
1194 "build final.stamp: touch || C.stamp\n";
1196 RebuildTarget("final.stamp", manifest);
1198 fs_.RemoveFile("B.d.stamp");
1201 RebuildTarget("final.stamp", manifest, NULL, NULL, &save_state);
1202 EXPECT_GE(save_state.LookupPool("some_pool")->current_use(), 0);
1205 struct BuildWithLogTest : public BuildTest {
1206 BuildWithLogTest() {
1207 builder_.SetBuildLog(&build_log_);
1210 BuildLog build_log_;
1213 TEST_F(BuildWithLogTest, NotInLogButOnDisk) {
1214 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1217 "build out1: cc in\n"));
1219 // Create input/output that would be considered up to date when
1220 // not considering the command line hash.
1221 fs_.Create("in", "");
1222 fs_.Create("out1", "");
1225 // Because it's not in the log, it should not be up-to-date until
1227 EXPECT_TRUE(builder_.AddTarget("out1", &err));
1228 EXPECT_FALSE(builder_.AlreadyUpToDate());
1230 command_runner_.commands_ran_.clear();
1233 EXPECT_TRUE(builder_.AddTarget("out1", &err));
1234 EXPECT_TRUE(builder_.Build(&err));
1235 EXPECT_TRUE(builder_.AlreadyUpToDate());
1238 TEST_F(BuildWithLogTest, RestatTest) {
1239 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1246 "build out1: cc in\n"
1247 "build out2: true out1\n"
1248 "build out3: cat out2\n"));
1250 fs_.Create("out1", "");
1251 fs_.Create("out2", "");
1252 fs_.Create("out3", "");
1256 fs_.Create("in", "");
1258 // Do a pre-build so that there's commands in the log for the outputs,
1259 // otherwise, the lack of an entry in the build log will cause out3 to rebuild
1260 // regardless of restat.
1262 EXPECT_TRUE(builder_.AddTarget("out3", &err));
1264 EXPECT_TRUE(builder_.Build(&err));
1266 EXPECT_EQ("[3/3]", builder_.status_->FormatProgressStatus("[%s/%t]"));
1267 command_runner_.commands_ran_.clear();
1272 fs_.Create("in", "");
1273 // "cc" touches out1, so we should build out2. But because "true" does not
1274 // touch out2, we should cancel the build of out3.
1275 EXPECT_TRUE(builder_.AddTarget("out3", &err));
1277 EXPECT_TRUE(builder_.Build(&err));
1278 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
1280 // If we run again, it should be a no-op, because the build log has recorded
1281 // that we've already built out2 with an input timestamp of 2 (from out1).
1282 command_runner_.commands_ran_.clear();
1284 EXPECT_TRUE(builder_.AddTarget("out3", &err));
1286 EXPECT_TRUE(builder_.AlreadyUpToDate());
1290 fs_.Create("in", "");
1292 // The build log entry should not, however, prevent us from rebuilding out2
1294 command_runner_.commands_ran_.clear();
1296 EXPECT_TRUE(builder_.AddTarget("out3", &err));
1298 EXPECT_TRUE(builder_.Build(&err));
1299 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
1302 TEST_F(BuildWithLogTest, RestatMissingFile) {
1303 // If a restat rule doesn't create its output, and the output didn't
1304 // exist before the rule was run, consider that behavior equivalent
1305 // to a rule that doesn't modify its existent output file.
1307 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1313 "build out1: true in\n"
1314 "build out2: cc out1\n"));
1316 fs_.Create("in", "");
1317 fs_.Create("out2", "");
1319 // Do a pre-build so that there's commands in the log for the outputs,
1320 // otherwise, the lack of an entry in the build log will cause out2 to rebuild
1321 // regardless of restat.
1323 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1325 EXPECT_TRUE(builder_.Build(&err));
1327 command_runner_.commands_ran_.clear();
1331 fs_.Create("in", "");
1332 fs_.Create("out2", "");
1334 // Run a build, expect only the first command to run.
1335 // It doesn't touch its output (due to being the "true" command), so
1336 // we shouldn't run the dependent build.
1337 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1339 EXPECT_TRUE(builder_.Build(&err));
1340 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1343 TEST_F(BuildWithLogTest, RestatSingleDependentOutputDirty) {
1344 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1349 " command = touch\n"
1350 "build out1: true in\n"
1351 "build out2 out3: touch out1\n"
1352 "build out4: touch out2\n"
1355 // Create the necessary files
1356 fs_.Create("in", "");
1359 EXPECT_TRUE(builder_.AddTarget("out4", &err));
1361 EXPECT_TRUE(builder_.Build(&err));
1363 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1366 fs_.Create("in", "");
1367 fs_.RemoveFile("out3");
1369 // Since "in" is missing, out1 will be built. Since "out3" is missing,
1370 // out2 and out3 will be built even though "in" is not touched when built.
1371 // Then, since out2 is rebuilt, out4 should be rebuilt -- the restat on the
1372 // "true" rule should not lead to the "touch" edge writing out2 and out3 being
1374 command_runner_.commands_ran_.clear();
1376 EXPECT_TRUE(builder_.AddTarget("out4", &err));
1378 EXPECT_TRUE(builder_.Build(&err));
1380 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1383 // Test scenario, in which an input file is removed, but output isn't changed
1384 // https://github.com/ninja-build/ninja/issues/295
1385 TEST_F(BuildWithLogTest, RestatMissingInput) {
1386 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1389 " depfile = $out.d\n"
1393 "build out1: true in\n"
1394 "build out2: cc out1\n"));
1396 // Create all necessary files
1397 fs_.Create("in", "");
1399 // The implicit dependencies and the depfile itself
1400 // are newer than the output
1401 TimeStamp restat_mtime = fs_.Tick();
1402 fs_.Create("out1.d", "out1: will.be.deleted restat.file\n");
1403 fs_.Create("will.be.deleted", "");
1404 fs_.Create("restat.file", "");
1406 // Run the build, out1 and out2 get built
1408 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1410 EXPECT_TRUE(builder_.Build(&err));
1411 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
1413 // See that an entry in the logfile is created, capturing
1415 BuildLog::LogEntry* log_entry = build_log_.LookupByOutput("out1");
1416 ASSERT_TRUE(NULL != log_entry);
1417 ASSERT_EQ(restat_mtime, log_entry->restat_mtime);
1419 // Now remove a file, referenced from depfile, so that target becomes
1420 // dirty, but the output does not change
1421 fs_.RemoveFile("will.be.deleted");
1423 // Trigger the build again - only out1 gets built
1424 command_runner_.commands_ran_.clear();
1426 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1428 EXPECT_TRUE(builder_.Build(&err));
1429 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1431 // Check that the logfile entry remains correctly set
1432 log_entry = build_log_.LookupByOutput("out1");
1433 ASSERT_TRUE(NULL != log_entry);
1434 ASSERT_EQ(restat_mtime, log_entry->restat_mtime);
1437 struct BuildDryRun : public BuildWithLogTest {
1439 config_.dry_run = true;
1443 TEST_F(BuildDryRun, AllCommandsShown) {
1444 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1451 "build out1: cc in\n"
1452 "build out2: true out1\n"
1453 "build out3: cat out2\n"));
1455 fs_.Create("out1", "");
1456 fs_.Create("out2", "");
1457 fs_.Create("out3", "");
1461 fs_.Create("in", "");
1463 // "cc" touches out1, so we should build out2. But because "true" does not
1464 // touch out2, we should cancel the build of out3.
1466 EXPECT_TRUE(builder_.AddTarget("out3", &err));
1468 EXPECT_TRUE(builder_.Build(&err));
1469 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1472 // Test that RSP files are created when & where appropriate and deleted after
1473 // successful execution.
1474 TEST_F(BuildTest, RspFileSuccess)
1476 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1478 " command = cat $rspfile > $out\n"
1479 " rspfile = $rspfile\n"
1480 " rspfile_content = $long_command\n"
1481 "rule cat_rsp_out\n"
1482 " command = cat $rspfile > $out\n"
1483 " rspfile = $out.rsp\n"
1484 " rspfile_content = $long_command\n"
1485 "build out1: cat in\n"
1486 "build out2: cat_rsp in\n"
1487 " rspfile = out 2.rsp\n"
1488 " long_command = Some very long command\n"
1489 "build out$ 3: cat_rsp_out in\n"
1490 " long_command = Some very long command\n"));
1492 fs_.Create("out1", "");
1493 fs_.Create("out2", "");
1494 fs_.Create("out 3", "");
1498 fs_.Create("in", "");
1501 EXPECT_TRUE(builder_.AddTarget("out1", &err));
1503 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1505 EXPECT_TRUE(builder_.AddTarget("out 3", &err));
1508 size_t files_created = fs_.files_created_.size();
1509 size_t files_removed = fs_.files_removed_.size();
1511 EXPECT_TRUE(builder_.Build(&err));
1512 ASSERT_EQ(3u, command_runner_.commands_ran_.size());
1514 // The RSP files were created
1515 ASSERT_EQ(files_created + 2, fs_.files_created_.size());
1516 ASSERT_EQ(1u, fs_.files_created_.count("out 2.rsp"));
1517 ASSERT_EQ(1u, fs_.files_created_.count("out 3.rsp"));
1519 // The RSP files were removed
1520 ASSERT_EQ(files_removed + 2, fs_.files_removed_.size());
1521 ASSERT_EQ(1u, fs_.files_removed_.count("out 2.rsp"));
1522 ASSERT_EQ(1u, fs_.files_removed_.count("out 3.rsp"));
1525 // Test that RSP file is created but not removed for commands, which fail
1526 TEST_F(BuildTest, RspFileFailure) {
1527 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1530 " rspfile = $rspfile\n"
1531 " rspfile_content = $long_command\n"
1532 "build out: fail in\n"
1533 " rspfile = out.rsp\n"
1534 " long_command = Another very long command\n"));
1536 fs_.Create("out", "");
1538 fs_.Create("in", "");
1541 EXPECT_TRUE(builder_.AddTarget("out", &err));
1544 size_t files_created = fs_.files_created_.size();
1545 size_t files_removed = fs_.files_removed_.size();
1547 EXPECT_FALSE(builder_.Build(&err));
1548 ASSERT_EQ("subcommand failed", err);
1549 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1551 // The RSP file was created
1552 ASSERT_EQ(files_created + 1, fs_.files_created_.size());
1553 ASSERT_EQ(1u, fs_.files_created_.count("out.rsp"));
1555 // The RSP file was NOT removed
1556 ASSERT_EQ(files_removed, fs_.files_removed_.size());
1557 ASSERT_EQ(0u, fs_.files_removed_.count("out.rsp"));
1559 // The RSP file contains what it should
1560 ASSERT_EQ("Another very long command", fs_.files_["out.rsp"].contents);
1563 // Test that contents of the RSP file behaves like a regular part of
1564 // command line, i.e. triggers a rebuild if changed
1565 TEST_F(BuildWithLogTest, RspFileCmdLineChange) {
1566 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1568 " command = cat $rspfile > $out\n"
1569 " rspfile = $rspfile\n"
1570 " rspfile_content = $long_command\n"
1571 "build out: cat_rsp in\n"
1572 " rspfile = out.rsp\n"
1573 " long_command = Original very long command\n"));
1575 fs_.Create("out", "");
1577 fs_.Create("in", "");
1580 EXPECT_TRUE(builder_.AddTarget("out", &err));
1583 // 1. Build for the 1st time (-> populate log)
1584 EXPECT_TRUE(builder_.Build(&err));
1585 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1587 // 2. Build again (no change)
1588 command_runner_.commands_ran_.clear();
1590 EXPECT_TRUE(builder_.AddTarget("out", &err));
1592 ASSERT_TRUE(builder_.AlreadyUpToDate());
1594 // 3. Alter the entry in the logfile
1595 // (to simulate a change in the command line between 2 builds)
1596 BuildLog::LogEntry* log_entry = build_log_.LookupByOutput("out");
1597 ASSERT_TRUE(NULL != log_entry);
1598 ASSERT_NO_FATAL_FAILURE(AssertHash(
1599 "cat out.rsp > out;rspfile=Original very long command",
1600 log_entry->command_hash));
1601 log_entry->command_hash++; // Change the command hash to something else.
1602 // Now expect the target to be rebuilt
1603 command_runner_.commands_ran_.clear();
1605 EXPECT_TRUE(builder_.AddTarget("out", &err));
1607 EXPECT_TRUE(builder_.Build(&err));
1608 EXPECT_EQ(1u, command_runner_.commands_ran_.size());
1611 TEST_F(BuildTest, InterruptCleanup) {
1612 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1614 " command = interrupt\n"
1615 "rule touch-interrupt\n"
1616 " command = touch-interrupt\n"
1617 "build out1: interrupt in1\n"
1618 "build out2: touch-interrupt in2\n"));
1620 fs_.Create("out1", "");
1621 fs_.Create("out2", "");
1623 fs_.Create("in1", "");
1624 fs_.Create("in2", "");
1626 // An untouched output of an interrupted command should be retained.
1628 EXPECT_TRUE(builder_.AddTarget("out1", &err));
1630 EXPECT_FALSE(builder_.Build(&err));
1631 EXPECT_EQ("interrupted by user", err);
1633 EXPECT_GT(fs_.Stat("out1", &err), 0);
1636 // A touched output of an interrupted command should be deleted.
1637 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1639 EXPECT_FALSE(builder_.Build(&err));
1640 EXPECT_EQ("interrupted by user", err);
1642 EXPECT_EQ(0, fs_.Stat("out2", &err));
1645 TEST_F(BuildTest, StatFailureAbortsBuild) {
1646 const string kTooLongToStat(400, 'i');
1647 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1648 ("build " + kTooLongToStat + ": cat " + kTooLongToStat + "\n").c_str()));
1649 // Also cyclic, for good measure.
1651 // This simulates a stat failure:
1652 fs_.files_[kTooLongToStat].mtime = -1;
1653 fs_.files_[kTooLongToStat].stat_error = "stat failed";
1656 EXPECT_FALSE(builder_.AddTarget(kTooLongToStat, &err));
1657 EXPECT_EQ("stat failed", err);
1660 TEST_F(BuildTest, PhonyWithNoInputs) {
1661 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1662 "build nonexistent: phony\n"
1663 "build out1: cat || nonexistent\n"
1664 "build out2: cat nonexistent\n"));
1665 fs_.Create("out1", "");
1666 fs_.Create("out2", "");
1668 // out1 should be up to date even though its input is dirty, because its
1669 // order-only dependency has nothing to do.
1671 EXPECT_TRUE(builder_.AddTarget("out1", &err));
1673 EXPECT_TRUE(builder_.AlreadyUpToDate());
1675 // out2 should still be out of date though, because its input is dirty.
1677 command_runner_.commands_ran_.clear();
1679 EXPECT_TRUE(builder_.AddTarget("out2", &err));
1681 EXPECT_TRUE(builder_.Build(&err));
1683 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1686 TEST_F(BuildTest, DepsGccWithEmptyDepfileErrorsOut) {
1687 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1691 "build out: cc\n"));
1695 EXPECT_TRUE(builder_.AddTarget("out", &err));
1697 EXPECT_FALSE(builder_.AlreadyUpToDate());
1699 EXPECT_FALSE(builder_.Build(&err));
1700 ASSERT_EQ("subcommand failed", err);
1701 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1704 TEST_F(BuildTest, StatusFormatReplacePlaceholder) {
1705 EXPECT_EQ("[%/s0/t0/r0/u0/f0]",
1706 status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]"));
1709 TEST_F(BuildTest, FailedDepsParse) {
1710 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1711 "build bad_deps.o: cat in1\n"
1713 " depfile = in1.d\n"));
1716 EXPECT_TRUE(builder_.AddTarget("bad_deps.o", &err));
1719 // These deps will fail to parse, as they should only have one
1720 // path to the left of the colon.
1721 fs_.Create("in1.d", "AAA BBB");
1723 EXPECT_FALSE(builder_.Build(&err));
1724 EXPECT_EQ("subcommand failed", err);
1727 /// Tests of builds involving deps logs necessarily must span
1728 /// multiple builds. We reuse methods on BuildTest but not the
1729 /// builder_ it sets up, because we want pristine objects for
1731 struct BuildWithDepsLogTest : public BuildTest {
1732 BuildWithDepsLogTest() {}
1734 virtual void SetUp() {
1737 temp_dir_.CreateAndEnter("BuildWithDepsLogTest");
1740 virtual void TearDown() {
1741 temp_dir_.Cleanup();
1744 ScopedTempDir temp_dir_;
1746 /// Shadow parent class builder_ so we don't accidentally use it.
1750 /// Run a straightforwad build where the deps log is used.
1751 TEST_F(BuildWithDepsLogTest, Straightforward) {
1753 // Note: in1 was created by the superclass SetUp().
1754 const char* manifest =
1755 "build out: cat in1\n"
1757 " depfile = in1.d\n";
1760 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1761 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1763 // Run the build once, everything should be ok.
1765 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
1768 Builder builder(&state, config_, NULL, &deps_log, &fs_);
1769 builder.command_runner_.reset(&command_runner_);
1770 EXPECT_TRUE(builder.AddTarget("out", &err));
1772 fs_.Create("in1.d", "out: in2");
1773 EXPECT_TRUE(builder.Build(&err));
1776 // The deps file should have been removed.
1777 EXPECT_EQ(0, fs_.Stat("in1.d", &err));
1778 // Recreate it for the next step.
1779 fs_.Create("in1.d", "out: in2");
1781 builder.command_runner_.release();
1786 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1787 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1789 // Touch the file only mentioned in the deps.
1791 fs_.Create("in2", "");
1793 // Run the build again.
1795 ASSERT_TRUE(deps_log.Load("ninja_deps", &state, &err));
1796 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
1798 Builder builder(&state, config_, NULL, &deps_log, &fs_);
1799 builder.command_runner_.reset(&command_runner_);
1800 command_runner_.commands_ran_.clear();
1801 EXPECT_TRUE(builder.AddTarget("out", &err));
1803 EXPECT_TRUE(builder.Build(&err));
1806 // We should have rebuilt the output due to in2 being
1808 EXPECT_EQ(1u, command_runner_.commands_ran_.size());
1810 builder.command_runner_.release();
1814 /// Verify that obsolete dependency info causes a rebuild.
1815 /// 1) Run a successful build where everything has time t, record deps.
1816 /// 2) Move input/output to time t+1 -- despite files in alignment,
1817 /// should still need to rebuild due to deps at older time.
1818 TEST_F(BuildWithDepsLogTest, ObsoleteDeps) {
1820 // Note: in1 was created by the superclass SetUp().
1821 const char* manifest =
1822 "build out: cat in1\n"
1824 " depfile = in1.d\n";
1826 // Run an ordinary build that gathers dependencies.
1827 fs_.Create("in1", "");
1828 fs_.Create("in1.d", "out: ");
1831 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1832 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1834 // Run the build once, everything should be ok.
1836 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
1839 Builder builder(&state, config_, NULL, &deps_log, &fs_);
1840 builder.command_runner_.reset(&command_runner_);
1841 EXPECT_TRUE(builder.AddTarget("out", &err));
1843 EXPECT_TRUE(builder.Build(&err));
1847 builder.command_runner_.release();
1850 // Push all files one tick forward so that only the deps are out
1853 fs_.Create("in1", "");
1854 fs_.Create("out", "");
1856 // The deps file should have been removed, so no need to timestamp it.
1857 EXPECT_EQ(0, fs_.Stat("in1.d", &err));
1861 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1862 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1865 ASSERT_TRUE(deps_log.Load("ninja_deps", &state, &err));
1866 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
1868 Builder builder(&state, config_, NULL, &deps_log, &fs_);
1869 builder.command_runner_.reset(&command_runner_);
1870 command_runner_.commands_ran_.clear();
1871 EXPECT_TRUE(builder.AddTarget("out", &err));
1874 // Recreate the deps file here because the build expects them to exist.
1875 fs_.Create("in1.d", "out: ");
1877 EXPECT_TRUE(builder.Build(&err));
1880 // We should have rebuilt the output due to the deps being
1882 EXPECT_EQ(1u, command_runner_.commands_ran_.size());
1884 builder.command_runner_.release();
1888 TEST_F(BuildWithDepsLogTest, DepsIgnoredInDryRun) {
1889 const char* manifest =
1890 "build out: cat in1\n"
1892 " depfile = in1.d\n";
1894 fs_.Create("out", "");
1896 fs_.Create("in1", "");
1899 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1900 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1902 // The deps log is NULL in dry runs.
1903 config_.dry_run = true;
1904 Builder builder(&state, config_, NULL, NULL, &fs_);
1905 builder.command_runner_.reset(&command_runner_);
1906 command_runner_.commands_ran_.clear();
1909 EXPECT_TRUE(builder.AddTarget("out", &err));
1911 EXPECT_TRUE(builder.Build(&err));
1912 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
1914 builder.command_runner_.release();
1917 /// Check that a restat rule generating a header cancels compilations correctly.
1918 TEST_F(BuildTest, RestatDepfileDependency) {
1919 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
1921 " command = true\n" // Would be "write if out-of-date" in reality.
1923 "build header.h: true header.in\n"
1924 "build out: cat in1\n"
1925 " depfile = in1.d\n"));
1927 fs_.Create("header.h", "");
1928 fs_.Create("in1.d", "out: header.h");
1930 fs_.Create("header.in", "");
1933 EXPECT_TRUE(builder_.AddTarget("out", &err));
1935 EXPECT_TRUE(builder_.Build(&err));
1939 /// Check that a restat rule generating a header cancels compilations correctly,
1941 TEST_F(BuildWithDepsLogTest, RestatDepfileDependencyDepsLog) {
1943 // Note: in1 was created by the superclass SetUp().
1944 const char* manifest =
1946 " command = true\n" // Would be "write if out-of-date" in reality.
1948 "build header.h: true header.in\n"
1949 "build out: cat in1\n"
1951 " depfile = in1.d\n";
1954 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1955 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1957 // Run the build once, everything should be ok.
1959 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
1962 Builder builder(&state, config_, NULL, &deps_log, &fs_);
1963 builder.command_runner_.reset(&command_runner_);
1964 EXPECT_TRUE(builder.AddTarget("out", &err));
1966 fs_.Create("in1.d", "out: header.h");
1967 EXPECT_TRUE(builder.Build(&err));
1971 builder.command_runner_.release();
1976 ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
1977 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
1979 // Touch the input of the restat rule.
1981 fs_.Create("header.in", "");
1983 // Run the build again.
1985 ASSERT_TRUE(deps_log.Load("ninja_deps", &state, &err));
1986 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
1988 Builder builder(&state, config_, NULL, &deps_log, &fs_);
1989 builder.command_runner_.reset(&command_runner_);
1990 command_runner_.commands_ran_.clear();
1991 EXPECT_TRUE(builder.AddTarget("out", &err));
1993 EXPECT_TRUE(builder.Build(&err));
1996 // Rule "true" should have run again, but the build of "out" should have
1997 // been cancelled due to restat propagating through the depfile header.
1998 EXPECT_EQ(1u, command_runner_.commands_ran_.size());
2000 builder.command_runner_.release();
2004 TEST_F(BuildWithDepsLogTest, DepFileOKDepsLog) {
2006 const char* manifest =
2007 "rule cc\n command = cc $in\n depfile = $out.d\n deps = gcc\n"
2008 "build fo$ o.o: cc foo.c\n";
2010 fs_.Create("foo.c", "");
2014 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
2016 // Run the build once, everything should be ok.
2018 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
2021 Builder builder(&state, config_, NULL, &deps_log, &fs_);
2022 builder.command_runner_.reset(&command_runner_);
2023 EXPECT_TRUE(builder.AddTarget("fo o.o", &err));
2025 fs_.Create("fo o.o.d", "fo\\ o.o: blah.h bar.h\n");
2026 EXPECT_TRUE(builder.Build(&err));
2030 builder.command_runner_.release();
2035 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
2038 ASSERT_TRUE(deps_log.Load("ninja_deps", &state, &err));
2039 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
2042 Builder builder(&state, config_, NULL, &deps_log, &fs_);
2043 builder.command_runner_.reset(&command_runner_);
2045 Edge* edge = state.edges_.back();
2047 state.GetNode("bar.h", 0)->MarkDirty(); // Mark bar.h as missing.
2048 EXPECT_TRUE(builder.AddTarget("fo o.o", &err));
2051 // Expect three new edges: one generating fo o.o, and two more from
2052 // loading the depfile.
2053 ASSERT_EQ(3u, state.edges_.size());
2054 // Expect our edge to now have three inputs: foo.c and two headers.
2055 ASSERT_EQ(3u, edge->inputs_.size());
2057 // Expect the command line we generate to only use the original input.
2058 ASSERT_EQ("cc foo.c", edge->EvaluateCommand());
2061 builder.command_runner_.release();
2066 TEST_F(BuildWithDepsLogTest, DepFileDepsLogCanonicalize) {
2068 const char* manifest =
2069 "rule cc\n command = cc $in\n depfile = $out.d\n deps = gcc\n"
2070 "build a/b\\c\\d/e/fo$ o.o: cc x\\y/z\\foo.c\n";
2072 fs_.Create("x/y/z/foo.c", "");
2076 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
2078 // Run the build once, everything should be ok.
2080 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
2083 Builder builder(&state, config_, NULL, &deps_log, &fs_);
2084 builder.command_runner_.reset(&command_runner_);
2085 EXPECT_TRUE(builder.AddTarget("a/b/c/d/e/fo o.o", &err));
2087 // Note, different slashes from manifest.
2088 fs_.Create("a/b\\c\\d/e/fo o.o.d",
2089 "a\\b\\c\\d\\e\\fo\\ o.o: blah.h bar.h\n");
2090 EXPECT_TRUE(builder.Build(&err));
2094 builder.command_runner_.release();
2099 ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
2102 ASSERT_TRUE(deps_log.Load("ninja_deps", &state, &err));
2103 ASSERT_TRUE(deps_log.OpenForWrite("ninja_deps", &err));
2106 Builder builder(&state, config_, NULL, &deps_log, &fs_);
2107 builder.command_runner_.reset(&command_runner_);
2109 Edge* edge = state.edges_.back();
2111 state.GetNode("bar.h", 0)->MarkDirty(); // Mark bar.h as missing.
2112 EXPECT_TRUE(builder.AddTarget("a/b/c/d/e/fo o.o", &err));
2115 // Expect three new edges: one generating fo o.o, and two more from
2116 // loading the depfile.
2117 ASSERT_EQ(3u, state.edges_.size());
2118 // Expect our edge to now have three inputs: foo.c and two headers.
2119 ASSERT_EQ(3u, edge->inputs_.size());
2121 // Expect the command line we generate to only use the original input.
2122 // Note, slashes from manifest, not .d.
2123 ASSERT_EQ("cc x\\y/z\\foo.c", edge->EvaluateCommand());
2126 builder.command_runner_.release();
2131 /// Check that a restat rule doesn't clear an edge if the depfile is missing.
2132 /// Follows from: https://github.com/ninja-build/ninja/issues/603
2133 TEST_F(BuildTest, RestatMissingDepfile) {
2134 const char* manifest =
2136 " command = true\n" // Would be "write if out-of-date" in reality.
2138 "build header.h: true header.in\n"
2139 "build out: cat header.h\n"
2140 " depfile = out.d\n";
2142 fs_.Create("header.h", "");
2144 fs_.Create("out", "");
2145 fs_.Create("header.in", "");
2147 // Normally, only 'header.h' would be rebuilt, as
2148 // its rule doesn't touch the output and has 'restat=1' set.
2149 // But we are also missing the depfile for 'out',
2150 // which should force its command to run anyway!
2151 RebuildTarget("out", manifest);
2152 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
2155 /// Check that a restat rule doesn't clear an edge if the deps are missing.
2156 /// https://github.com/ninja-build/ninja/issues/603
2157 TEST_F(BuildWithDepsLogTest, RestatMissingDepfileDepslog) {
2159 const char* manifest =
2161 " command = true\n" // Would be "write if out-of-date" in reality.
2163 "build header.h: true header.in\n"
2164 "build out: cat header.h\n"
2166 " depfile = out.d\n";
2168 // Build once to populate ninja deps logs from out.d
2169 fs_.Create("header.in", "");
2170 fs_.Create("out.d", "out: header.h");
2171 fs_.Create("header.h", "");
2173 RebuildTarget("out", manifest, "build_log", "ninja_deps");
2174 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
2176 // Sanity: this rebuild should be NOOP
2177 RebuildTarget("out", manifest, "build_log", "ninja_deps");
2178 ASSERT_EQ(0u, command_runner_.commands_ran_.size());
2180 // Touch 'header.in', blank dependencies log (create a different one).
2181 // Building header.h triggers 'restat' outputs cleanup.
2182 // Validate that out is rebuilt netherless, as deps are missing.
2184 fs_.Create("header.in", "");
2186 // (switch to a new blank deps_log "ninja_deps2")
2187 RebuildTarget("out", manifest, "build_log", "ninja_deps2");
2188 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
2190 // Sanity: this build should be NOOP
2191 RebuildTarget("out", manifest, "build_log", "ninja_deps2");
2192 ASSERT_EQ(0u, command_runner_.commands_ran_.size());
2194 // Check that invalidating deps by target timestamp also works here
2195 // Repeat the test but touch target instead of blanking the log.
2197 fs_.Create("header.in", "");
2198 fs_.Create("out", "");
2199 RebuildTarget("out", manifest, "build_log", "ninja_deps2");
2200 ASSERT_EQ(2u, command_runner_.commands_ran_.size());
2202 // And this build should be NOOP again
2203 RebuildTarget("out", manifest, "build_log", "ninja_deps2");
2204 ASSERT_EQ(0u, command_runner_.commands_ran_.size());
2207 TEST_F(BuildTest, WrongOutputInDepfileCausesRebuild) {
2209 const char* manifest =
2211 " command = cc $in\n"
2212 " depfile = $out.d\n"
2213 "build foo.o: cc foo.c\n";
2215 fs_.Create("foo.c", "");
2216 fs_.Create("foo.o", "");
2217 fs_.Create("header.h", "");
2218 fs_.Create("foo.o.d", "bar.o.d: header.h\n");
2220 RebuildTarget("foo.o", manifest, "build_log", "ninja_deps");
2221 ASSERT_EQ(1u, command_runner_.commands_ran_.size());
2224 TEST_F(BuildTest, Console) {
2225 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
2227 " command = console\n"
2229 "build cons: console in.txt\n"));
2231 fs_.Create("in.txt", "");
2234 EXPECT_TRUE(builder_.AddTarget("cons", &err));
2236 EXPECT_TRUE(builder_.Build(&err));
2238 ASSERT_EQ(1u, command_runner_.commands_ran_.size());