Tests/CXXModules: add a test to ensure that `restat` works for collation
Also update the `modules-json-file` test to account for the fact that
`CXXModules.json` is not updated for timestamp-only rebuild triggers.
See: #25511
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index 7958166..8b614cd 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -216,6 +216,9 @@
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 ()