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