mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-29 18:49:03 -06:00
Ninja: Avoid empty phony edges for target ordering
Since commit v3.9.0-rc1~230^2~2 (ninja: break unnecessary target
dependencies, 2017-04-17) we unconditionally generate a phony edge for
target ordering. It is needed in case a later target depends on it.
However, if the phony edge has no inputs then `ninja -d explain` prints:
ninja explain: output ... of phony edge with no inputs doesn't exist
Furthermore the phony edge's output is considered dirty and can cause
dependents to be incorrectly considered dirty. Avoid this by always
generating at least one input to the target ordering phony edges.
If we have no real dependencies just use a path that always exists.
Fixes: #17942
This commit is contained in:
@@ -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());
|
||||
|
||||
1
Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt
Normal file
1
Tests/RunCMake/Ninja/NoWorkToDo-nowork-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
^ninja: no work to do
|
||||
2
Tests/RunCMake/Ninja/NoWorkToDo.cmake
Normal file
2
Tests/RunCMake/Ninja/NoWorkToDo.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
enable_language(C)
|
||||
add_executable(hello hello.c)
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user