From 09c962a6a43fecd5d14d3a43654ef9bb5c48a536 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 27 Oct 2023 23:25:49 -0400 Subject: Tests/CXXModules: test forced rsp files with ninja Fixes: #25367 --- Source/cmNinjaTargetGenerator.cxx | 3 +-- .../CXXModules/NinjaForceResponseFile-check.cmake | 23 ++++++++++++++++++ .../CXXModules/NinjaForceResponseFile.cmake | 27 ++++++++++++++++++++++ Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 1 + 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/CXXModules/NinjaForceResponseFile-check.cmake create mode 100644 Tests/RunCMake/CXXModules/NinjaForceResponseFile.cmake diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 05b6690..dabb078 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1257,8 +1257,6 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName, { cmNinjaBuild scanBuild(ruleName); - scanBuild.RspFile = "$out.rsp"; - if (compilePP) { // Move compilation dependencies to the scan/preprocessing build statement. std::swap(scanBuild.ExplicitDeps, objBuild.ExplicitDeps); @@ -1299,6 +1297,7 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName, // Tell dependency scanner where to store dyndep intermediate results. std::string ddiFileName = cmStrCat(objectFileName, ".ddi"); scanBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFileName; + scanBuild.RspFile = cmStrCat(ddiFileName, ".rsp"); // Outputs of the scan/preprocessor build statement. if (compilePP) { diff --git a/Tests/RunCMake/CXXModules/NinjaForceResponseFile-check.cmake b/Tests/RunCMake/CXXModules/NinjaForceResponseFile-check.cmake new file mode 100644 index 0000000..b8863e7 --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaForceResponseFile-check.cmake @@ -0,0 +1,23 @@ +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(path "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/impl-Debug.ninja") +else () + set(path "${RunCMake_TEST_BINARY_DIR}/build.ninja") +endif () + +if (NOT EXISTS "${path}") + list(APPEND RunCMake_TEST_FAILED + "Failed to find `ninja` build file: '${path}'") +endif () + +file(READ "${path}" rspfiles + REGEX "^ *RSP_FILE =") + +if (rspfiles MATCHES "\\$out\\.rsp$") + message(FATAL_ERROR + "rspfiles for modules should be specified explicitly") +elseif (NOT rspfiles MATCHES "ddi\\.rsp") + message(FATAL_ERROR + "rspfiles for scanning rules should be specified according to scan output filenames") +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/NinjaForceResponseFile.cmake b/Tests/RunCMake/CXXModules/NinjaForceResponseFile.cmake new file mode 100644 index 0000000..bac3263 --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaForceResponseFile.cmake @@ -0,0 +1,27 @@ +# Fake out that we have dyndep; we only need to generate, not actually build +# here. +set(CMAKE_CXX_SCANDEP_SOURCE "") + +enable_language(CXX) + +if (NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "This test requires a 'Ninja' generator to be used.") +endif () + +set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1) + +add_library(ninja-forced-response-file) +target_sources(ninja-forced-response-file + PRIVATE + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/sources" + FILES + sources/module.cxx + sources/module-part.cxx + FILE_SET internal_partitions TYPE CXX_MODULES FILES + sources/module-internal-part.cxx) +target_compile_features(ninja-forced-response-file + PRIVATE + cxx_std_20) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index e687e9f..c1c42c4 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -94,6 +94,7 @@ if (RunCMake_GENERATOR MATCHES "Ninja") run_cmake(NinjaDependInfoFileSet) run_cmake(NinjaDependInfoExport) run_cmake(NinjaDependInfoBMIInstall) + run_cmake(NinjaForceResponseFile) # issue#25367 elseif (RunCMake_GENERATOR MATCHES "Visual Studio") run_cmake(VisualStudioNoSyntheticTargets) else () -- cgit v0.12