diff options
author | Evan Martin <martine@danga.com> | 2012-07-03 16:45:37 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-07-03 16:45:37 (GMT) |
commit | 0ca93baf35d3c2b1e70e008276555b5bec2f9f3e (patch) | |
tree | 9d6ab7ec67f13cfe08f1bf1037023e2ae780784e /src/build_test.cc | |
parent | 358eefbce2f62e8685b6797d395c06f4118b6e05 (diff) | |
parent | 4a083599bb654e894a1f6ce0dc1080b4e8df6f63 (diff) | |
download | Ninja-0ca93baf35d3c2b1e70e008276555b5bec2f9f3e.zip Ninja-0ca93baf35d3c2b1e70e008276555b5bec2f9f3e.tar.gz Ninja-0ca93baf35d3c2b1e70e008276555b5bec2f9f3e.tar.bz2 |
Merge pull request #313 from wolfp/restat_missing_input
Do not reset restat_mtime if an input is missing
Diffstat (limited to 'src/build_test.cc')
-rw-r--r-- | src/build_test.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/build_test.cc b/src/build_test.cc index 23f1909..a3f345b 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -802,6 +802,60 @@ TEST_F(BuildWithLogTest, RestatMissingFile) { ASSERT_EQ(1u, commands_ran_.size()); } +// Test scenario, in which an input file is removed, but output isn't changed +// https://github.com/martine/ninja/issues/295 +TEST_F(BuildWithLogTest, RestatMissingInput) { + ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, + "rule true\n" + " command = true\n" + " depfile = $out.d\n" + " restat = 1\n" + "rule cc\n" + " command = cc\n" + "build out1: true in\n" + "build out2: cc out1\n")); + + // Create all necessary files + fs_.Create("in", now_, ""); + + // The implicit dependencies and the depfile itself + // are newer than the output + TimeStamp restat_mtime = ++now_; + fs_.Create("out1.d", now_, "out1: will.be.deleted restat.file\n"); + fs_.Create("will.be.deleted", now_, ""); + fs_.Create("restat.file", now_, ""); + + // Run the build, out1 and out2 get built + string err; + EXPECT_TRUE(builder_.AddTarget("out2", &err)); + ASSERT_EQ("", err); + EXPECT_TRUE(builder_.Build(&err)); + ASSERT_EQ(2u, commands_ran_.size()); + + // See that an entry in the logfile is created, capturing + // the right mtime + BuildLog::LogEntry * log_entry = build_log_.LookupByOutput("out1"); + ASSERT_TRUE(NULL != log_entry); + ASSERT_EQ(restat_mtime, log_entry->restat_mtime); + + // Now remove a file, referenced from depfile, so that target becomes + // dirty, but the output does not change + fs_.RemoveFile("will.be.deleted"); + + // Trigger the build again - only out1 gets built + commands_ran_.clear(); + state_.Reset(); + EXPECT_TRUE(builder_.AddTarget("out2", &err)); + ASSERT_EQ("", err); + EXPECT_TRUE(builder_.Build(&err)); + ASSERT_EQ(1u, commands_ran_.size()); + + // Check that the logfile entry remains correctly set + log_entry = build_log_.LookupByOutput("out1"); + ASSERT_TRUE(NULL != log_entry); + ASSERT_EQ(restat_mtime, log_entry->restat_mtime); +} + struct BuildDryRun : public BuildWithLogTest { BuildDryRun() { config_.dry_run = true; |