From ff805113c766371677b97d94cd3092cf6ff0bbf6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 5 Apr 2016 15:31:47 -0400 Subject: [PATCH 1/2] Ninja: Fix detection of custom command symbolic outputs Fix logic introduced by commit v3.5.0-rc1~198^2 (Ninja: Always re-run custom commands that have symbolic dependencies, 2015-11-19) to not consider only the last output. We need to know if any output is SYMBOLIC, so stop checking as soon as one is found. --- Source/cmLocalNinjaGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index b2927a96e..6a5949c2a 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -400,7 +400,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( bool symbolic = false; for (std::vector::const_iterator o = outputs.begin(); - o != outputs.end(); ++o) + !symbolic && o != outputs.end(); ++o) { if (cmSourceFile* sf = this->Makefile->GetSource(*o)) { From add7abc8352b87184579401cb2493c72e07aa212 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 5 Apr 2016 16:20:28 -0400 Subject: [PATCH 2/2] Ninja: Restat custom command byproducts even with a SYMBOLIC output (#16049) The change in commit v3.5.0-rc1~198^2 (Ninja: Always re-run custom commands that have symbolic dependencies, 2015-11-19) broke the byproducts feature added by commit v3.2.0-rc1~340^2~2 (Add an option for explicit BYPRODUCTS of custom commands, 2014-11-13) when SYMBOLIC outputs also appear. This case occurs with AUTORCC-generated custom targets because the output is SYMBOLIC (to always run) and the generated file is a byproduct (for restat so dependents do not run unnecessarily). The two use cases conflict because Ninja does not support per-output restat. Favor restat whenever byproducts are present because it is required for byproducts to work correctly. In use cases where we want an always-run chain we simply will not be able to also use byproducts. --- Source/cmLocalNinjaGenerator.cxx | 2 +- .../Custom-Symbolic-and-Byproduct.cmake | 28 +++++++++++++++++++ .../RunCMake/BuildDepends/RunCMakeTest.cmake | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 6a5949c2a..2d13507ec 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -444,7 +444,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0], cc->GetUsesTerminal(), - /*restat*/!symbolic, + /*restat*/!symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps, orderOnlyDeps); diff --git a/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake b/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake new file mode 100644 index 000000000..6948c35bf --- /dev/null +++ b/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake @@ -0,0 +1,28 @@ +add_custom_command( + OUTPUT gen-byproduct gen-byproduct-stamp + BYPRODUCTS byproduct + COMMAND ${CMAKE_COMMAND} -E touch gen-byproduct-stamp + COMMAND ${CMAKE_COMMAND} -E copy_if_different gen-byproduct-stamp byproduct + ) +set_property(SOURCE gen-byproduct PROPERTY SYMBOLIC 1) +add_custom_target(produce DEPENDS gen-byproduct) + +add_custom_command( + OUTPUT use-byproduct + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/byproduct + COMMAND ${CMAKE_COMMAND} -E touch use-byproduct + ) +add_custom_target(drive ALL DEPENDS use-byproduct) +add_dependencies(drive produce) + +file(GENERATE OUTPUT check-$>.cmake CONTENT " +if (check_step EQUAL 1) + set(check_pairs + \"${CMAKE_CURRENT_BINARY_DIR}/use-byproduct|${CMAKE_CURRENT_BINARY_DIR}/gen-byproduct-stamp\" + ) +else() + set(check_pairs + \"${CMAKE_CURRENT_BINARY_DIR}/gen-byproduct-stamp|${CMAKE_CURRENT_BINARY_DIR}/use-byproduct\" + ) +endif() +") diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake index 31c72fbe1..0dd27d426 100644 --- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake +++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake @@ -39,4 +39,5 @@ if(NOT RunCMake_GENERATOR MATCHES "Visual Studio [67]|Xcode") unset(run_BuildDepends_skip_step_2) endif() +run_BuildDepends(Custom-Symbolic-and-Byproduct) run_BuildDepends(Custom-Always)