diff options
author | Brad King <brad.king@kitware.com> | 2018-04-26 12:45:31 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-04-26 12:48:45 (GMT) |
commit | cca8bc88ba245ed670ae1ec9ebf043a320b42763 (patch) | |
tree | 966c5e8765a1d5e77efc159053f8ddab3f93e602 | |
parent | 5858267df6a1538ae0af8d503cd7f20b69c3f503 (diff) | |
parent | ee44f390ceaadee1517043dfb5f21fce147e740e (diff) | |
download | CMake-cca8bc88ba245ed670ae1ec9ebf043a320b42763.zip CMake-cca8bc88ba245ed670ae1ec9ebf043a320b42763.tar.gz CMake-cca8bc88ba245ed670ae1ec9ebf043a320b42763.tar.bz2 |
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 <kwrobot@kitware.com>
Merge-request: !2010
-rw-r--r-- | Source/cmGeneratorExpressionEvaluationFile.cxx | 6 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 17 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/NoWorkToDo.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/RunCMakeTest.cmake | 9 |
6 files changed, 39 insertions, 4 deletions
diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index c544141..99b9261 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/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()); } diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 2a8576f..c19a61c 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/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); } } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index ddb1d54..7dfce57 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/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); diff --git a/Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt b/Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt new file mode 100644 index 0000000..60a9228 --- /dev/null +++ b/Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt @@ -0,0 +1 @@ +^ninja: no work to do diff --git a/Tests/RunCMake/Ninja/NoWorkToDo.cmake b/Tests/RunCMake/Ninja/NoWorkToDo.cmake new file mode 100644 index 0000000..a2fa0cb --- /dev/null +++ b/Tests/RunCMake/Ninja/NoWorkToDo.cmake @@ -0,0 +1,2 @@ +enable_language(C) +add_executable(hello hello.c) diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 3bb2b6b..b6e6cd4 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/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) |