summaryrefslogtreecommitdiffstats
path: root/src/build_test.cc
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-09-07 14:56:25 (GMT)
committerBrad King <brad.king@kitware.com>2017-09-08 13:07:52 (GMT)
commitc0dde0ff7911780152dbe86d5782ebdecfeb37f2 (patch)
treefa0c474dbf0d9254e8346fdc4f9b2c79c5bbc63e /src/build_test.cc
parente679202a14d9ca08ccd0f471f2bcbf6388ddb3de (diff)
downloadNinja-c0dde0ff7911780152dbe86d5782ebdecfeb37f2.zip
Ninja-c0dde0ff7911780152dbe86d5782ebdecfeb37f2.tar.gz
Ninja-c0dde0ff7911780152dbe86d5782ebdecfeb37f2.tar.bz2
Restore tolerance of self-referencing phony build statements
Since commit v1.8.0^2~3^2~1 (Teach RecomputeDirty to detect cycles in the build graph, 2015-11-13) we correctly reject self-referencing phony build statements like build a: phony a as cycles. Unfortunately this breaks support for CMake 2.8.12.x and 3.0.x because those versions incorrectly produce edges of this form (that we used to tolerate). In order to preserve compatibility with those CMake versions we need to restore tolerance of these edges. Add a special case to the manifest parser to filter out self-referencing inputs of phony edges of the form produced by those CMake versions. Warn by default, but add a `-w phonycycle={err,warn}` option to make it an error. Fixes: #1322
Diffstat (limited to 'src/build_test.cc')
-rw-r--r--src/build_test.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/build_test.cc b/src/build_test.cc
index a0f898f..46ab33e 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -1068,6 +1068,19 @@ TEST_F(BuildTest, PhonyNoWork) {
EXPECT_TRUE(builder_.AlreadyUpToDate());
}
+// Test a self-referencing phony. Ideally this should not work, but
+// ninja 1.7 and below tolerated and CMake 2.8.12.x and 3.0.x both
+// incorrectly produce it. We tolerate it for compatibility.
+TEST_F(BuildTest, PhonySelfReference) {
+ string err;
+ ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build a: phony a\n"));
+
+ EXPECT_TRUE(builder_.AddTarget("a", &err));
+ ASSERT_EQ("", err);
+ EXPECT_TRUE(builder_.AlreadyUpToDate());
+}
+
TEST_F(BuildTest, Fail) {
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
"rule fail\n"