Browse Source

Merge topic 'makefile-progress'

5781cf406f Makefile: Fix progress with non-excluded targets in excluded dirs
89ab14b05b cmGlobalGenerator: Constify IsExcluded use of cmLocalGenerator
0aabf32590 cmGeneratorExpression: Constify use of cmLocalGenerator
88f54fba43 cmLocalGenerator: Avoid unnecessary const-ness propagation

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10658
Brad King 6 months ago
parent
commit
e78cf73b52

+ 2 - 2
Source/cmGeneratorExpression.cxx

@@ -43,7 +43,7 @@ std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
 }
 
 std::string cmGeneratorExpression::Evaluate(
-  std::string input, cmLocalGenerator* lg, std::string const& config,
+  std::string input, cmLocalGenerator const* lg, std::string const& config,
   cmGeneratorTarget const* headTarget,
   cmGeneratorExpressionDAGChecker* dagChecker,
   cmGeneratorTarget const* currentTarget, std::string const& language)
@@ -63,7 +63,7 @@ std::string cmGeneratorExpression::Evaluate(
 }
 
 std::string const& cmCompiledGeneratorExpression::Evaluate(
-  cmLocalGenerator* lg, std::string const& config,
+  cmLocalGenerator const* lg, std::string const& config,
   cmGeneratorTarget const* headTarget,
   cmGeneratorExpressionDAGChecker* dagChecker,
   cmGeneratorTarget const* currentTarget, std::string const& language) const

+ 4 - 4
Source/cmGeneratorExpression.h

@@ -46,7 +46,7 @@ public:
     std::string input) const;
 
   static std::string Evaluate(
-    std::string input, cmLocalGenerator* lg, std::string const& config,
+    std::string input, cmLocalGenerator const* lg, std::string const& config,
     cmGeneratorTarget const* headTarget = nullptr,
     cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
     cmGeneratorTarget const* currentTarget = nullptr,
@@ -103,7 +103,7 @@ public:
     cmCompiledGeneratorExpression const&) = delete;
 
   std::string const& Evaluate(
-    cmLocalGenerator* lg, std::string const& config,
+    cmLocalGenerator const* lg, std::string const& config,
     cmGeneratorTarget const* headTarget = nullptr,
     cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
     cmGeneratorTarget const* currentTarget = nullptr,
@@ -185,7 +185,7 @@ private:
 class cmGeneratorExpressionInterpreter
 {
 public:
-  cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
+  cmGeneratorExpressionInterpreter(cmLocalGenerator const* localGenerator,
                                    std::string config,
                                    cmGeneratorTarget const* headTarget,
                                    std::string language = std::string())
@@ -208,7 +208,7 @@ public:
 protected:
   cmGeneratorExpression GeneratorExpression;
   std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpression;
-  cmLocalGenerator* LocalGenerator = nullptr;
+  cmLocalGenerator const* LocalGenerator = nullptr;
   std::string Config;
   cmGeneratorTarget const* HeadTarget = nullptr;
   std::string Language;

+ 1 - 1
Source/cmGeneratorExpressionContext.cxx

@@ -5,7 +5,7 @@
 #include <utility>
 
 cmGeneratorExpressionContext::cmGeneratorExpressionContext(
-  cmLocalGenerator* lg, std::string config, bool quiet,
+  cmLocalGenerator const* lg, std::string config, bool quiet,
   cmGeneratorTarget const* headTarget, cmGeneratorTarget const* currentTarget,
   bool evaluateForBuildsystem, cmListFileBacktrace backtrace,
   std::string language)

+ 2 - 2
Source/cmGeneratorExpressionContext.h

@@ -13,7 +13,7 @@ class cmLocalGenerator;
 
 struct cmGeneratorExpressionContext
 {
-  cmGeneratorExpressionContext(cmLocalGenerator* lg, std::string config,
+  cmGeneratorExpressionContext(cmLocalGenerator const* lg, std::string config,
                                bool quiet, cmGeneratorTarget const* headTarget,
                                cmGeneratorTarget const* currentTarget,
                                bool evaluateForBuildsystem,
@@ -27,7 +27,7 @@ struct cmGeneratorExpressionContext
   std::set<cmGeneratorTarget const*> SourceSensitiveTargets;
   std::map<cmGeneratorTarget const*, std::map<std::string, std::string>>
     MaxLanguageStandard;
-  cmLocalGenerator* LG;
+  cmLocalGenerator const* LG;
   std::string Config;
   std::string Language;
   // The target whose property is being evaluated.

+ 7 - 7
Source/cmGeneratorExpressionNode.cxx

@@ -52,7 +52,7 @@
 #include "cmake.h"
 
 std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
-  std::string const& prop, cmLocalGenerator* lg,
+  std::string const& prop, cmLocalGenerator const* lg,
   cmGeneratorExpressionContext* context, cmGeneratorTarget const* headTarget,
   cmGeneratorExpressionDAGChecker* dagChecker,
   cmGeneratorTarget const* currentTarget)
@@ -2337,7 +2337,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode
       return std::string();
     }
 
-    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    cmGlobalGenerator const* gg = context->LG->GetGlobalGenerator();
     std::string genName = gg->GetName();
     if (genName.find("Makefiles") == std::string::npos &&
         genName.find("Ninja") == std::string::npos &&
@@ -2387,7 +2387,7 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode
         "add_custom_target, or file(GENERATE) commands.");
       return std::string();
     }
-    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    cmGlobalGenerator const* gg = context->LG->GetGlobalGenerator();
     std::string genName = gg->GetName();
     if (genName.find("Makefiles") == std::string::npos &&
         genName.find("Ninja") == std::string::npos &&
@@ -2441,7 +2441,7 @@ static const struct LinkLanguageNode : public cmGeneratorExpressionNode
       return std::string();
     }
 
-    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    cmGlobalGenerator const* gg = context->LG->GetGlobalGenerator();
     std::string genName = gg->GetName();
     if (genName.find("Makefiles") == std::string::npos &&
         genName.find("Ninja") == std::string::npos &&
@@ -2532,7 +2532,7 @@ static const struct LinkLanguageAndIdNode : public cmGeneratorExpressionNode
       return std::string();
     }
 
-    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    cmGlobalGenerator const* gg = context->LG->GetGlobalGenerator();
     std::string genName = gg->GetName();
     if (genName.find("Makefiles") == std::string::npos &&
         genName.find("Ninja") == std::string::npos &&
@@ -3149,7 +3149,7 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
       reportError(context, content->GetOriginalExpression(), e.str());
       return std::string();
     }
-    cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+    cmGlobalGenerator const* gg = context->LG->GetGlobalGenerator();
     {
       std::string reason;
       if (!context->EvaluateForBuildsystem &&
@@ -3523,7 +3523,7 @@ struct TargetFilesystemArtifactDependencyCMP0112
                             cmGeneratorExpressionContext* context)
   {
     context->AllTargets.insert(target);
-    cmLocalGenerator* lg = context->LG;
+    cmLocalGenerator const* lg = context->LG;
     switch (target->GetPolicyStatusCMP0112()) {
       case cmPolicies::WARN:
         if (lg->GetMakefile()->PolicyOptionalWarningEnabled(

+ 1 - 1
Source/cmGeneratorExpressionNode.h

@@ -46,7 +46,7 @@ struct cmGeneratorExpressionNode
     cmGeneratorExpressionDAGChecker* dagChecker) const = 0;
 
   static std::string EvaluateDependentExpression(
-    std::string const& prop, cmLocalGenerator* lg,
+    std::string const& prop, cmLocalGenerator const* lg,
     cmGeneratorExpressionContext* context, cmGeneratorTarget const* headTarget,
     cmGeneratorExpressionDAGChecker* dagChecker,
     cmGeneratorTarget const* currentTarget);

+ 3 - 3
Source/cmGlobalGenerator.cxx

@@ -2407,8 +2407,8 @@ bool cmGlobalGenerator::IsExcluded(cmStateSnapshot const& rootSnp,
   return false;
 }
 
-bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
-                                   cmLocalGenerator* gen) const
+bool cmGlobalGenerator::IsExcluded(cmLocalGenerator const* root,
+                                   cmLocalGenerator const* gen) const
 {
   assert(gen);
 
@@ -2418,7 +2418,7 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
   return this->IsExcluded(rootSnp, snp);
 }
 
-bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
+bool cmGlobalGenerator::IsExcluded(cmLocalGenerator const* root,
                                    cmGeneratorTarget const* target) const
 {
   if (!target->IsInBuildSystem()) {

+ 3 - 2
Source/cmGlobalGenerator.h

@@ -725,8 +725,9 @@ protected:
   void CheckTargetProperties();
   bool IsExcluded(cmStateSnapshot const& root,
                   cmStateSnapshot const& snp) const;
-  bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const;
-  bool IsExcluded(cmLocalGenerator* root,
+  bool IsExcluded(cmLocalGenerator const* root,
+                  cmLocalGenerator const* gen) const;
+  bool IsExcluded(cmLocalGenerator const* root,
                   cmGeneratorTarget const* target) const;
   virtual void InitializeProgressMarks() {}
 

+ 6 - 8
Source/cmGlobalUnixMakefileGenerator3.cxx

@@ -801,19 +801,15 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
   // Loop over all targets in all local generators.
   for (auto const& lg : this->LocalGenerators) {
     for (auto const& gt : lg->GetGeneratorTargets()) {
-      cmLocalGenerator* tlg = gt->GetLocalGenerator();
-
       if (!gt->IsInBuildSystem() || this->IsExcluded(lg.get(), gt.get())) {
         continue;
       }
 
       cmStateSnapshot csnp = lg->GetStateSnapshot();
-      cmStateSnapshot tsnp = tlg->GetStateSnapshot();
 
-      // Consider the directory containing the target and all its
-      // parents until something excludes the target.
-      for (; csnp.IsValid() && !this->IsExcluded(csnp, tsnp);
-           csnp = csnp.GetBuildsystemDirectoryParent()) {
+      // Consider the directory containing the target and all its parents.
+      // An excluded directory may contains non-excluded targets.
+      for (; csnp.IsValid(); csnp = csnp.GetBuildsystemDirectoryParent()) {
         // This local generator includes the target.
         std::set<cmGeneratorTarget const*>& targetSet =
           this->DirectoryTargetsMap[csnp];
@@ -854,7 +850,9 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll(
   std::set<cmGeneratorTarget const*> emitted;
   for (cmGeneratorTarget const* target :
        this->DirectoryTargetsMap[lg.GetStateSnapshot()]) {
-    count += this->CountProgressMarksInTarget(target, emitted);
+    if (!this->IsExcluded(&lg, target)) {
+      count += this->CountProgressMarksInTarget(target, emitted);
+    }
   }
   return count;
 }

+ 1 - 4
Source/cmLocalGenerator.h

@@ -103,10 +103,7 @@ public:
   bool IsRootMakefile() const;
 
   //! Get the makefile for this generator
-  cmMakefile* GetMakefile() { return this->Makefile; }
-
-  //! Get the makefile for this generator, const version
-  cmMakefile const* GetMakefile() const { return this->Makefile; }
+  cmMakefile* GetMakefile() const { return this->Makefile; }
 
   //! Get the GlobalGenerator this is associated with
   cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-progress-stderr.txt

@@ -0,0 +1 @@
+.*

+ 7 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-progress.cmake

@@ -0,0 +1,7 @@
+if(EXISTS ${RunCMake_TEST_BINARY_DIR}/CMakeFiles/progress.marks)
+  file(STRINGS ${RunCMake_TEST_BINARY_DIR}/CMakeFiles/progress.marks progress_marks)
+  # 8: (zot.cpp.o + libzot.a) + (foo.cpp.o + libfoo.a) + (subinc.cpp.o + libsubinc.a) + (subsub.cpp.o + libsubsubinc.a)
+  if(NOT progress_marks STREQUAL "8")
+    set(RunCMake_TEST_FAILED "progress.marks should be 8, but got ${progress_marks}")
+  endif()
+endif()

+ 3 - 0
Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake

@@ -53,6 +53,9 @@ elseif(RunCMake_GENERATOR MATCHES "Make")
   set(RunCMake-check-file ExcludeFromAll/check-sub.cmake)
   set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}/ExcludeFromAll-build/ExcludeFromAll)
   run_cmake_command(ExcludeFromAll-build-sub "${RunCMake_MAKE_PROGRAM}")
+  set(RunCMake-check-file ExcludeFromAll/check-progress.cmake)
+  set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}/ExcludeFromAll-build/ExcludeFromAll)
+  run_cmake_command(ExcludeFromAll-build-progress "${RunCMake_MAKE_PROGRAM}")
 elseif(RunCMake_GENERATOR MATCHES "Visual Studio")
   set(RunCMake-check-file ExcludeFromAll/check-sub.cmake)
   run_cmake_command(ExcludeFromAll-build-sub ${CMAKE_COMMAND} --build ExcludeFromAll --config Debug)