Don't record deps in dry runs.
authorNico Weber <nicolasweber@gmx.de>
Mon, 22 Apr 2013 00:55:10 +0000 (17:55 -0700)
committerNico Weber <nicolasweber@gmx.de>
Mon, 22 Apr 2013 00:56:43 +0000 (17:56 -0700)
deps_log() is NULL during dry runs, so this fixes a crash. It also
matches ninja 1.2.0's behavior as far as I can tell.

Fixes issue #551.

src/build.cc
src/build_test.cc

index fed3065..c9842ce 100644 (file)
@@ -715,7 +715,9 @@ void Builder::FinishCommand(CommandRunner::Result* result) {
   // extraction itself can fail, which makes the command fail from a
   // build perspective.
   vector<Node*> deps_nodes;
-  string deps_type = edge->GetBinding("deps");
+  string deps_type;
+  if (!config_.dry_run)
+    deps_type = edge->GetBinding("deps");
   if (!deps_type.empty()) {
     string extract_err;
     if (!ExtractDeps(result, deps_type, &deps_nodes, &extract_err) &&
index 827998b..68a5142 100644 (file)
@@ -1353,7 +1353,7 @@ TEST_F(BuildTest, PhonyWithNoInputs) {
   ASSERT_EQ(1u, command_runner_.commands_ran_.size());
 }
 
-TEST_F(BuildTest, DepsGccWithEmptyDeps) {
+TEST_F(BuildTest, DepsGccWithEmptyDepfileErrorsOut) {
   ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
 "rule cc\n"
 "  command = cc\n"
@@ -1554,3 +1554,32 @@ TEST_F(BuildWithDepsLogTest, ObsoleteDeps) {
     builder.command_runner_.release();
   }
 }
+
+TEST_F(BuildWithDepsLogTest, DepsIgnoredInDryRun) {
+  const char* manifest =
+      "build out: cat in1\n"
+      "  deps = gcc\n"
+      "  depfile = in1.d\n";
+
+  fs_.Create("out", "");
+  fs_.Tick();
+  fs_.Create("in1", "");
+
+  State state;
+  ASSERT_NO_FATAL_FAILURE(AddCatRule(&state));
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state, manifest));
+
+  // The deps log is NULL in dry runs.
+  config_.dry_run = true;
+  Builder builder(&state, config_, NULL, NULL, &fs_);
+  builder.command_runner_.reset(&command_runner_);
+  command_runner_.commands_ran_.clear();
+
+  string err;
+  EXPECT_TRUE(builder.AddTarget("out", &err));
+  ASSERT_EQ("", err);
+  EXPECT_TRUE(builder.Build(&err));
+  ASSERT_EQ(1u, command_runner_.commands_ran_.size());
+
+  builder.command_runner_.release();
+}