Просмотр исходного кода

Merge topic 'ninja-issue-17942'

ee44f390ce Ninja: Make assumed source dependencies order-only
625b8f9076 Ninja: Avoid empty phony edges for target ordering
ae6722483e Merge branch 'backport-ninja-issue-17942' into ninja-issue-17942
0826c20128 Ninja: Do not add empty custom command for file(GENERATE) outputs

Acked-by: Kitware Robot <[email protected]>
Merge-request: !2010
Brad King 7 лет назад
Родитель
Сommit
cca8bc88ba

+ 6 - 0
Source/cmGeneratorExpressionEvaluationFile.cxx

@@ -105,8 +105,14 @@ void cmGeneratorExpressionEvaluationFile::CreateOutputFile(
       lg, config, false, nullptr, nullptr, nullptr, le);
     cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource(
       name, false, cmSourceFileLocationKind::Known);
+    // Tell TraceDependencies that the file is not expected to exist
+    // on disk yet.  We generate it after that runs.
     sf->SetProperty("GENERATED", "1");
 
+    // Tell the build system generators that there is no build rule
+    // to generate the file.
+    sf->SetProperty("__CMAKE_GENERATED_BY_CMAKE", "1");
+
     gg->SetFilenameTargetDepends(
       sf, this->OutputFileExpr->GetSourceSensitiveTargets());
   }

+ 5 - 3
Source/cmGlobalNinjaGenerator.cxx

@@ -931,12 +931,14 @@ void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& input)
 void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
 {
   for (auto const& asd : this->AssumedSourceDependencies) {
-    cmNinjaDeps deps;
-    std::copy(asd.second.begin(), asd.second.end(), std::back_inserter(deps));
+    cmNinjaDeps orderOnlyDeps;
+    std::copy(asd.second.begin(), asd.second.end(),
+              std::back_inserter(orderOnlyDeps));
     WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
                             "Assume dependencies for generated source file.",
                             /*depfile*/ "", /*uses_terminal*/ false,
-                            /*restat*/ true, cmNinjaDeps(1, asd.first), deps);
+                            /*restat*/ true, cmNinjaDeps(1, asd.first),
+                            cmNinjaDeps(), orderOnlyDeps);
   }
 }
 

+ 16 - 1
Source/cmNinjaTargetGenerator.cxx

@@ -821,6 +821,19 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements()
   orderOnlyDeps.erase(std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()),
                       orderOnlyDeps.end());
 
+  // The phony target must depend on at least one input or ninja will explain
+  // that "output ... of phony edge with no inputs doesn't exist" and consider
+  // the phony output "dirty".
+  if (orderOnlyDeps.empty()) {
+    // Any path that always exists will work here.  It would be nice to
+    // use just "." but that is not supported by Ninja < 1.7.
+    std::string tgtDir;
+    tgtDir += this->LocalGenerator->GetCurrentBinaryDirectory();
+    tgtDir += "/";
+    tgtDir += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+    orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
+  }
+
   {
     cmNinjaDeps orderOnlyTarget;
     orderOnlyTarget.push_back(this->OrderDependsTargetForTarget());
@@ -948,7 +961,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
   // (either attached to this source file or another one), assume that one of
   // the target dependencies, OBJECT_DEPENDS or header file custom commands
   // will rebuild the file.
-  if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() &&
+  if (source->GetPropertyAsBool("GENERATED") &&
+      !source->GetPropertyAsBool("__CMAKE_GENERATED_BY_CMAKE") &&
+      !source->GetCustomCommand() &&
       !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
     this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName,
                                                              orderOnlyDeps);

+ 1 - 0
Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt

@@ -0,0 +1 @@
+^ninja: no work to do

+ 2 - 0
Tests/RunCMake/Ninja/NoWorkToDo.cmake

@@ -0,0 +1,2 @@
+enable_language(C)
+add_executable(hello hello.c)

+ 9 - 0
Tests/RunCMake/Ninja/RunCMakeTest.cmake

@@ -21,6 +21,15 @@ function(run_NinjaToolMissing)
 endfunction()
 run_NinjaToolMissing()
 
+function(run_NoWorkToDo)
+  run_cmake(NoWorkToDo)
+  set(RunCMake_TEST_NO_CLEAN 1)
+  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/NoWorkToDo-build)
+  run_cmake_command(NoWorkToDo-build ${CMAKE_COMMAND} --build .)
+  run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain)
+endfunction()
+run_NoWorkToDo()
+
 function(run_CMP0058 case)
   # Use a single build tree for a few tests without cleaning.
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0058-${case}-build)