Browse Source

Merge topic 'ninja-symbolic-custom-command'

3477b26f Ninja: Always re-run custom commands that have symbolic dependencies
7d64a059 Ninja: Add 'restat' parameter to custom command generation method
866c75de Ninja: Refactor generation of 'restat' on custom commands
Brad King 10 years ago
parent
commit
b6f471773d

+ 7 - 1
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);
 }
 
@@ -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,6 +301,10 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
   cmNinjaVars vars;
   vars["COMMAND"] = cmd;
   vars["DESC"] = EncodeLiteral(description);
+  if (restat)
+    {
+    vars["restat"] = "1";
+    }
   if (uses_terminal && SupportsConsolePool())
     {
     vars["pool"] = "console";
@@ -923,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);
   }
 }

+ 1 - 0
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());

+ 11 - 0
Source/cmLocalNinjaGenerator.cxx

@@ -398,6 +398,16 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
   const std::vector<std::string> &byproducts = ccg.GetByproducts();
   cmNinjaDeps ninjaOutputs(outputs.size()+byproducts.size()), ninjaDeps;
 
+  bool symbolic = false;
+  for (std::vector<std::string>::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,6 +444,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
       this->ConstructComment(ccg),
       "Custom command for " + ninjaOutputs[0],
       cc->GetUsesTerminal(),
+      /*restat*/!symbolic,
       ninjaOutputs,
       ninjaDeps,
       orderOnlyDeps);

+ 1 - 0
Source/cmNinjaUtilityTargetGenerator.cxx

@@ -131,6 +131,7 @@ void cmNinjaUtilityTargetGenerator::Generate()
       desc,
       "Utility command for " + this->GetTargetName(),
       uses_terminal,
+      /*restat*/true,
       util_outputs,
       deps);
 

+ 24 - 0
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-$<LOWER_CASE:$<CONFIG>>.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\"
+  )
+")

+ 2 - 0
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)