From 866c75dedd42fae9dd05be402bdc94d51ffc7713 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 19 Nov 2015 14:47:36 -0500 Subject: Ninja: Refactor generation of 'restat' on custom commands Move generation of 'restat = 1' from the CUSTOM_COMMAND rule to every build statement using it. This will allow future selection of this option on a per-custom-command basis. --- Source/cmGlobalNinjaGenerator.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index a8a307c..64c2625 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -275,7 +275,7 @@ void cmGlobalNinjaGenerator::AddCustomCommandRule() /*deptype*/ "", /*rspfile*/ "", /*rspcontent*/ "", - /*restat*/ "1", + /*restat*/ "", // bound on each build statement as needed /*generator*/ false); } @@ -300,6 +300,7 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command, cmNinjaVars vars; vars["COMMAND"] = cmd; vars["DESC"] = EncodeLiteral(description); + vars["restat"] = "1"; if (uses_terminal && SupportsConsolePool()) { vars["pool"] = "console"; -- cgit v0.12 From 7d64a0598db5da2c4c1874f9fe8726fd6c9b18a7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 19 Nov 2015 15:09:40 -0500 Subject: Ninja: Add 'restat' parameter to custom command generation method Pass 'true' from all call sites to preserve existing behavior. --- Source/cmGlobalNinjaGenerator.cxx | 7 ++++++- Source/cmGlobalNinjaGenerator.h | 1 + Source/cmLocalNinjaGenerator.cxx | 1 + Source/cmNinjaUtilityTargetGenerator.cxx | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 64c2625..0f06e43 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -284,6 +284,7 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command, const std::string& description, const std::string& comment, bool uses_terminal, + bool restat, const cmNinjaDeps& outputs, const cmNinjaDeps& deps, const cmNinjaDeps& orderOnly) @@ -300,7 +301,10 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command, cmNinjaVars vars; vars["COMMAND"] = cmd; vars["DESC"] = EncodeLiteral(description); - vars["restat"] = "1"; + if (restat) + { + vars["restat"] = "1"; + } if (uses_terminal && SupportsConsolePool()) { vars["pool"] = "console"; @@ -924,6 +928,7 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies() WriteCustomCommandBuild(/*command=*/"", /*description=*/"", "Assume dependencies for generated source file.", /*uses_terminal*/false, + /*restat*/true, cmNinjaDeps(1, i->first), deps); } } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index c494d36..8656590 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -112,6 +112,7 @@ public: const std::string& description, const std::string& comment, bool uses_terminal, + bool restat, const cmNinjaDeps& outputs, const cmNinjaDeps& deps = cmNinjaDeps(), const cmNinjaDeps& orderOnly = cmNinjaDeps()); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index ecaa269..d9517d8 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -434,6 +434,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0], cc->GetUsesTerminal(), + /*restat*/true, ninjaOutputs, ninjaDeps, orderOnlyDeps); diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index edc65f0..ac66fcd 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -131,6 +131,7 @@ void cmNinjaUtilityTargetGenerator::Generate() desc, "Utility command for " + this->GetTargetName(), uses_terminal, + /*restat*/true, util_outputs, deps); -- cgit v0.12 From 3477b26ff6c455b64421bf19000d7203acdd6024 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 19 Nov 2015 15:13:11 -0500 Subject: Ninja: Always re-run custom commands that have symbolic dependencies If a custom command has a SYMBOLIC output (that is never actually created) then do not mark the custom command build statement as 'restat'. Otherwise other custom commands that depend on the symbolic output may not always re-run because after running the first custom command Ninja 'restat' will detect that the output timestamp did not change and skip its dependents. This was observed with the ExternalProject BUILD_ALWAYS option where Ninja would not re-run the 'install' step each time 'build' re-runs. --- Source/cmLocalNinjaGenerator.cxx | 12 +++++++++++- Tests/RunCMake/BuildDepends/Custom-Always.cmake | 24 ++++++++++++++++++++++++ Tests/RunCMake/BuildDepends/RunCMakeTest.cmake | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/BuildDepends/Custom-Always.cmake diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index d9517d8..b2927a9 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -398,6 +398,16 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( const std::vector &byproducts = ccg.GetByproducts(); cmNinjaDeps ninjaOutputs(outputs.size()+byproducts.size()), ninjaDeps; + bool symbolic = false; + for (std::vector::const_iterator o = outputs.begin(); + o != outputs.end(); ++o) + { + if (cmSourceFile* sf = this->Makefile->GetSource(*o)) + { + symbolic = sf->GetPropertyAsBool("SYMBOLIC"); + } + } + #if 0 #error TODO: Once CC in an ExternalProject target must provide the \ file of each imported target that has an add_dependencies pointing \ @@ -434,7 +444,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0], cc->GetUsesTerminal(), - /*restat*/true, + /*restat*/!symbolic, ninjaOutputs, ninjaDeps, orderOnlyDeps); diff --git a/Tests/RunCMake/BuildDepends/Custom-Always.cmake b/Tests/RunCMake/BuildDepends/Custom-Always.cmake new file mode 100644 index 0000000..d412708 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/Custom-Always.cmake @@ -0,0 +1,24 @@ +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/before-always + COMMAND ${CMAKE_COMMAND} -E touch before-always + ) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/always + COMMAND ${CMAKE_COMMAND} -E touch always-updated + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/before-always + ) +set_property(SOURCE always PROPERTY SYMBOLIC 1) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/after-always + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/always + COMMAND ${CMAKE_COMMAND} -E touch after-always + ) + +add_custom_target(drive ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/after-always) + +file(GENERATE OUTPUT check-$>.cmake CONTENT " +set(check_pairs + \"${CMAKE_CURRENT_BINARY_DIR}/always-updated|${CMAKE_CURRENT_BINARY_DIR}/before-always\" + \"${CMAKE_CURRENT_BINARY_DIR}/after-always|${CMAKE_CURRENT_BINARY_DIR}/always-updated\" + ) +") diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake index a578408..31c72fb 100644 --- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake +++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake @@ -38,3 +38,5 @@ if(NOT RunCMake_GENERATOR MATCHES "Visual Studio [67]|Xcode") run_BuildDepends(C-Exe-Manifest) unset(run_BuildDepends_skip_step_2) endif() + +run_BuildDepends(Custom-Always) -- cgit v0.12