From f50fb77a4f95472e816e0c6cc483f905671abcce Mon Sep 17 00:00:00 2001 From: Martin Duffy Date: Tue, 29 Oct 2024 13:37:27 -0400 Subject: [PATCH] Ninja: Regenerate when test or install scripts are missing Rerun CMake when `cmake_install.cmake` or `CTestTestfile.cmake` are out of date. This enables regeneration if a subdirectory is removed before invoking `ninja`. Fixes: #26396 --- Source/cmGlobalGenerator.cxx | 13 +++++++++++++ Source/cmGlobalGenerator.h | 3 +++ Source/cmGlobalNinjaGenerator.cxx | 1 + Source/cmGlobalNinjaGenerator.h | 1 + Source/cmLocalGenerator.cxx | 1 + .../Configure/RerunCMake-build5-check.cmake | 4 ++++ Tests/RunCMake/Configure/RunCMakeTest.cmake | 9 +++++++++ 7 files changed, 32 insertions(+) create mode 100644 Tests/RunCMake/Configure/RerunCMake-build5-check.cmake diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 3d99aa68ba..382b656585 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -4023,3 +4023,16 @@ void cmGlobalGenerator::AddInstallScript(std::string const& file) { this->InstallScripts.push_back(file); } + +void cmGlobalGenerator::AddTestFile(std::string const& file) +{ + this->TestFiles.push_back(file); +} + +void cmGlobalGenerator::AddCMakeFilesToRebuild( + std::vector& files) const +{ + files.insert(files.end(), this->InstallScripts.begin(), + this->InstallScripts.end()); + files.insert(files.end(), this->TestFiles.begin(), this->TestFiles.end()); +} diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 2a1afa82ef..92e974c9d0 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -675,6 +675,8 @@ public: bool CheckCMP0171() const; void AddInstallScript(std::string const& file); + void AddTestFile(std::string const& file); + void AddCMakeFilesToRebuild(std::vector& files) const; protected: // for a project collect all its targets by following depend @@ -916,6 +918,7 @@ private: RuntimeDependencySetsByName; std::vector InstallScripts; + std::vector TestFiles; #if !defined(CMAKE_BOOTSTRAP) // Pool of file locks diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 17e9c440a8..d46ec81ad3 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -3293,6 +3293,7 @@ void cmGlobalNinjaMultiGenerator::AddRebuildManifestOutputs( if (!this->DefaultFileConfig.empty()) { outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE)); } + this->AddCMakeFilesToRebuild(outputs); } void cmGlobalNinjaMultiGenerator::GetQtAutoGenConfigs( diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 69b2361dc8..7bd7206a21 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -382,6 +382,7 @@ public: virtual void AddRebuildManifestOutputs(cmNinjaDeps& outputs) const { outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE)); + this->AddCMakeFilesToRebuild(outputs); } int GetRuleCmdLength(const std::string& name) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f1860db3a8..b011747561 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -366,6 +366,7 @@ void cmLocalGenerator::GenerateTestFiles() std::string file = cmStrCat(this->StateSnapshot.GetDirectory().GetCurrentBinary(), "/CTestTestfile.cmake"); + this->GlobalGenerator->AddTestFile(file); cmGeneratedFileStream fout(file); diff --git a/Tests/RunCMake/Configure/RerunCMake-build5-check.cmake b/Tests/RunCMake/Configure/RerunCMake-build5-check.cmake new file mode 100644 index 0000000000..d740671b07 --- /dev/null +++ b/Tests/RunCMake/Configure/RerunCMake-build5-check.cmake @@ -0,0 +1,4 @@ +file(READ ${stamp} content) +if(NOT content STREQUAL 5) + set(RunCMake_TEST_FAILED "Expected stamp '5' but got: '${content}'") +endif() diff --git a/Tests/RunCMake/Configure/RunCMakeTest.cmake b/Tests/RunCMake/Configure/RunCMakeTest.cmake index 00d3272585..9b686e4bff 100644 --- a/Tests/RunCMake/Configure/RunCMakeTest.cmake +++ b/Tests/RunCMake/Configure/RunCMakeTest.cmake @@ -37,6 +37,15 @@ block() set(RunCMake_TEST_OUTPUT_MERGE 0) run_cmake_command(RerunCMake-build4 ${CMAKE_COMMAND} --build .) endif() + if(RunCMake_GENERATOR MATCHES "^Ninja") + file(REMOVE "${error}") + run_cmake(RerunCMake) + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) # handle 1s resolution + # remove cmake_install.cmake to trigger rerun + file(REMOVE "${RunCMake_TEST_BINARY_DIR}/cmake_install.cmake") + file(WRITE "${input}" "5") + run_cmake_command(RerunCMake-build5 ${CMAKE_COMMAND} --build .) + endif() endblock() block()