From 88f54fba435e95faad9b9535bd153eeb19e228b0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 15 Apr 2025 10:39:23 -0400 Subject: cmLocalGenerator: Avoid unnecessary const-ness propagation --- Source/cmLocalGenerator.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 6fae5e1..87247d1 100644 --- a/Source/cmLocalGenerator.h +++ b/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; } -- cgit v0.12 From 0aabf325904cf60b60e0fbba9617dd893c35032f Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 15 Apr 2025 10:38:32 -0400 Subject: cmGeneratorExpression: Constify use of cmLocalGenerator --- Source/cmGeneratorExpression.cxx | 4 ++-- Source/cmGeneratorExpression.h | 8 ++++---- Source/cmGeneratorExpressionContext.cxx | 2 +- Source/cmGeneratorExpressionContext.h | 4 ++-- Source/cmGeneratorExpressionNode.cxx | 14 +++++++------- Source/cmGeneratorExpressionNode.h | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index f0dcde7..f35ee52 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -43,7 +43,7 @@ std::unique_ptr 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 diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 3ffc39d..e5269b1 100644 --- a/Source/cmGeneratorExpression.h +++ b/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 CompiledGeneratorExpression; - cmLocalGenerator* LocalGenerator = nullptr; + cmLocalGenerator const* LocalGenerator = nullptr; std::string Config; cmGeneratorTarget const* HeadTarget = nullptr; std::string Language; diff --git a/Source/cmGeneratorExpressionContext.cxx b/Source/cmGeneratorExpressionContext.cxx index a934717..21d45b9 100644 --- a/Source/cmGeneratorExpressionContext.cxx +++ b/Source/cmGeneratorExpressionContext.cxx @@ -5,7 +5,7 @@ #include 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) diff --git a/Source/cmGeneratorExpressionContext.h b/Source/cmGeneratorExpressionContext.h index d013477..20ce592 100644 --- a/Source/cmGeneratorExpressionContext.h +++ b/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 SourceSensitiveTargets; std::map> MaxLanguageStandard; - cmLocalGenerator* LG; + cmLocalGenerator const* LG; std::string Config; std::string Language; // The target whose property is being evaluated. diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index ed61993..90bb06b 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/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( diff --git a/Source/cmGeneratorExpressionNode.h b/Source/cmGeneratorExpressionNode.h index 865f71c..df4ee5f 100644 --- a/Source/cmGeneratorExpressionNode.h +++ b/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); -- cgit v0.12 From 89ab14b05bd8a189b56dd0b7a151143edc152149 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 15 Apr 2025 10:38:03 -0400 Subject: cmGlobalGenerator: Constify IsExcluded use of cmLocalGenerator --- Source/cmGlobalGenerator.cxx | 6 +++--- Source/cmGlobalGenerator.h | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 9fff4dc..b027244 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/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()) { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index b7ea6a9..609f7bd 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -724,8 +724,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() {} -- cgit v0.12 From 5781cf406f4bcc0d340449ea52c5b206c14053d9 Mon Sep 17 00:00:00 2001 From: xndcn Date: Tue, 15 Apr 2025 21:22:31 +0800 Subject: Makefile: Fix progress with non-excluded targets in excluded dirs Fixes: #26871 --- Source/cmGlobalUnixMakefileGenerator3.cxx | 14 ++++++-------- .../ExcludeFromAll-build-progress-stderr.txt | 1 + .../add_subdirectory/ExcludeFromAll/check-progress.cmake | 7 +++++++ Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake | 3 +++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-progress-stderr.txt create mode 100644 Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-progress.cmake diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index db23fa6..78de8f4 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/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& targetSet = this->DirectoryTargetsMap[csnp]; @@ -854,7 +850,9 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll( std::set 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; } diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-progress-stderr.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-progress-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll-build-progress-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-progress.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check-progress.cmake new file mode 100644 index 0000000..b55ec18 --- /dev/null +++ b/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() diff --git a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake index f29697c..d6133bc 100644 --- a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake +++ b/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) -- cgit v0.12