summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-02-16 14:32:05 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-02-16 14:32:15 (GMT)
commit273463aaa99f4a6d046b76c29f86c4bbd61dbb6e (patch)
treeaf5f36ec968713cd8108260efef5e06ec86d2ecd
parent00fcb1dc812dd9578be831156e4c60c458af16c2 (diff)
parenta7424b636b28ce0b6f9d7156dd3e1fe0e487f643 (diff)
downloadCMake-273463aaa99f4a6d046b76c29f86c4bbd61dbb6e.zip
CMake-273463aaa99f4a6d046b76c29f86c4bbd61dbb6e.tar.gz
CMake-273463aaa99f4a6d046b76c29f86c4bbd61dbb6e.tar.bz2
Merge topic 'cxxmodules-collation-restat' into release-3.29
a7424b636b Ninja: make the collator rule use `restat = 1` e24eecfc33 Tests/CXXModules: add a test to ensure that `restat` works for collation Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !9259
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx2
-rw-r--r--Source/cmNinjaTargetGenerator.cxx5
-rw-r--r--Tests/RunCMake/CXXModules/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/CXXModules/examples/depchain-collation-restat-rebuild-check.cmake12
-rw-r--r--Tests/RunCMake/CXXModules/examples/depchain-collation-restat/CMakeLists.txt23
-rw-r--r--Tests/RunCMake/CXXModules/examples/depchain-collation-restat/importable.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/depchain-collation-restat/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/depchain-collation-restat/pre-rebuild.cmake7
-rw-r--r--Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake4
9 files changed, 66 insertions, 2 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 74a6bea..a3f20c3 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -2786,6 +2786,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
// `cmNinjaTargetGenerator::ExportObjectCompileCommand` to generate the
// corresponding file path.
cmGeneratedFileStream mmf(cmStrCat(object.PrimaryOutput, ".modmap"));
+ mmf.SetCopyIfDifferent(true);
mmf << mm;
}
@@ -2875,6 +2876,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
}
cmGeneratedFileStream tmf(target_mods_file);
+ tmf.SetCopyIfDifferent(true);
tmf << target_module_info;
cmDyndepMetadataCallbacks cb;
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index fe2cc04..a465b08 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -815,6 +815,11 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
// dyndep rules
rule.RspFile = "$out.rsp";
rule.RspContent = "$in";
+ // Ninja's collator writes all outputs using `cmGeneratedFileStream`, so
+ // they are only updated if contents actually change. Avoid running
+ // dependent jobs if the contents don't change by telling `ninja` to check
+ // the timestamp again.
+ rule.Restat = "1";
// Run CMake dependency scanner on the source file (using the preprocessed
// source if that was performed).
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index f11f82f..421c509 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -217,6 +217,9 @@ if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
unset(RunCMake_CXXModules_NO_TEST)
run_cxx_module_test_rebuild(depchain-modmap)
run_cxx_module_test_rebuild(depchain-modules-json-file)
+ if (RunCMake_GENERATOR MATCHES "Ninja")
+ run_cxx_module_test_rebuild(depchain-collation-restat)
+ endif ()
endif ()
# Tests which use named modules in shared libraries.
diff --git a/Tests/RunCMake/CXXModules/examples/depchain-collation-restat-rebuild-check.cmake b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat-rebuild-check.cmake
new file mode 100644
index 0000000..46c1d29
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat-rebuild-check.cmake
@@ -0,0 +1,12 @@
+if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(dep_collation_restat "CMakeFiles/depchain_collation_restat.dir/Debug/main.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
+ set(collation_restat "CMakeFiles/depchain_with_collation_restat.dir/Debug/CXXModules.json")
+else ()
+ set(dep_collation_restat "CMakeFiles/depchain_collation_restat.dir/main.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
+ set(collation_restat "CMakeFiles/depchain_with_collation_restat.dir/CXXModules.json")
+endif ()
+
+if (NOT "${RunCMake_TEST_BINARY_DIR}/${collation_restat}" IS_NEWER_THAN "${RunCMake_TEST_BINARY_DIR}/${dep_collation_restat}")
+ list(APPEND RunCMake_TEST_FAILED
+ "Object '${dep_collation_restat}' should not have recompiled if '${collation_restat}' did not change content.")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/CMakeLists.txt
new file mode 100644
index 0000000..54df83a
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.28)
+project(cxx_modules_depchain_collation_restat CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+add_library(depchain_with_collation_restat)
+target_sources(depchain_with_collation_restat
+ PUBLIC
+ FILE_SET CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+ FILES
+ importable.cxx)
+target_compile_features(depchain_with_collation_restat PUBLIC cxx_std_20)
+
+add_executable(depchain_collation_restat)
+target_sources(depchain_collation_restat
+ PRIVATE
+ main.cxx)
+target_link_libraries(depchain_collation_restat
+ PRIVATE
+ depchain_with_collation_restat)
+add_test(NAME depchain_collation_restat COMMAND depchain_collation_restat)
diff --git a/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/importable.cxx b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/importable.cxx
new file mode 100644
index 0000000..607680a
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/importable.cxx
@@ -0,0 +1,6 @@
+export module importable;
+
+export int from_import()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/main.cxx b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/main.cxx
new file mode 100644
index 0000000..feb38d2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/main.cxx
@@ -0,0 +1,6 @@
+import importable;
+
+int main(int argc, char* argv[])
+{
+ return from_import();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/pre-rebuild.cmake b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/pre-rebuild.cmake
new file mode 100644
index 0000000..e1ff979
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/depchain-collation-restat/pre-rebuild.cmake
@@ -0,0 +1,7 @@
+if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(collation_restat "CMakeFiles/depchain_with_collation_restat.dir/Debug/CXXModules.json")
+else ()
+ set(collation_restat "CMakeFiles/depchain_with_collation_restat.dir/CXXModules.json")
+endif ()
+
+file(TOUCH_NOCREATE "${RunCMake_TEST_BINARY_DIR}/${collation_restat}")
diff --git a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake
index 452f446..94e833a 100644
--- a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake
+++ b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake
@@ -1,8 +1,8 @@
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
- set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/Debug/CXXModules.json")
+ set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/Debug/CXX.dd")
set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/Debug/CXXModules.json")
else ()
- set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/CXXModules.json")
+ set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/CXX.dd")
set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/CXXModules.json")
endif ()