Browse Source

Merge topic 'cxxmodules-visibility-change-rebuild'

60a8736378 cmNinjaTargetGenerator: scanning depends on the module metadata
52036ce090 Tests/CXXModules: test that objects depend on dependent modules json files
9a45c9fbd5 cmNinjaTargetGenerator: use `emplace_back` for scanning deps

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !9247
Brad King 1 year ago
parent
commit
4c4951efa8

+ 7 - 3
Source/cmNinjaTargetGenerator.cxx

@@ -1222,11 +1222,13 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
 
 
     cmNinjaBuild build(this->LanguageDyndepRule(language, config));
     cmNinjaBuild build(this->LanguageDyndepRule(language, config));
     build.Outputs.push_back(this->GetDyndepFilePath(language, config));
     build.Outputs.push_back(this->GetDyndepFilePath(language, config));
-    build.ImplicitOuts.push_back(
+    build.ImplicitOuts.emplace_back(
       cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
       cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
                this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
                this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
                this->GetGlobalGenerator()->ConfigDirectory(config), '/',
                this->GetGlobalGenerator()->ConfigDirectory(config), '/',
                language, "Modules.json"));
                language, "Modules.json"));
+    build.ImplicitDeps.emplace_back(
+      this->GetTargetDependInfoPath(language, config));
     for (auto const& scanFiles : scanningFiles) {
     for (auto const& scanFiles : scanningFiles) {
       if (!scanFiles.ScanningOutput.empty()) {
       if (!scanFiles.ScanningOutput.empty()) {
         build.ExplicitDeps.push_back(scanFiles.ScanningOutput);
         build.ExplicitDeps.push_back(scanFiles.ScanningOutput);
@@ -1241,10 +1243,12 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
     auto const linked_directories =
     auto const linked_directories =
       this->GetLinkedTargetDirectories(language, config);
       this->GetLinkedTargetDirectories(language, config);
     for (std::string const& l : linked_directories.Direct) {
     for (std::string const& l : linked_directories.Direct) {
-      build.ImplicitDeps.push_back(cmStrCat(l, '/', language, "Modules.json"));
+      build.ImplicitDeps.emplace_back(
+        cmStrCat(l, '/', language, "Modules.json"));
     }
     }
     for (std::string const& l : linked_directories.Forward) {
     for (std::string const& l : linked_directories.Forward) {
-      build.ImplicitDeps.push_back(cmStrCat(l, '/', language, "Modules.json"));
+      build.ImplicitDeps.emplace_back(
+        cmStrCat(l, '/', language, "Modules.json"));
     }
     }
 
 
     this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
     this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),

+ 1 - 0
Tests/RunCMake/CXXModules/RunCMakeTest.cmake

@@ -216,6 +216,7 @@ if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
   run_cxx_module_test(req-private-other-target)
   run_cxx_module_test(req-private-other-target)
   unset(RunCMake_CXXModules_NO_TEST)
   unset(RunCMake_CXXModules_NO_TEST)
   run_cxx_module_test_rebuild(depchain-modmap)
   run_cxx_module_test_rebuild(depchain-modmap)
+  run_cxx_module_test_rebuild(depchain-modules-json-file)
 endif ()
 endif ()
 
 
 # Tests which use named modules in shared libraries.
 # Tests which use named modules in shared libraries.

+ 12 - 0
Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake

@@ -0,0 +1,12 @@
+if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
+  set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/Debug/CXXModules.json")
+  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(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/CXXModules.json")
+endif ()
+
+if ("${RunCMake_TEST_BINARY_DIR}/${modules_json_path}" IS_NEWER_THAN "${RunCMake_TEST_BINARY_DIR}/${dep_modules_json_path}")
+  list(APPEND RunCMake_TEST_FAILED
+    "Object '${dep_modules_json_path}' should have recompiled if '${modules_json_path}' changed.")
+endif ()

+ 23 - 0
Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/CMakeLists.txt

@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.28)
+project(cxx_modules_depchain_modules_json_file CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+add_library(depchain_with_modules_json_file)
+target_sources(depchain_with_modules_json_file
+  PUBLIC
+    FILE_SET CXX_MODULES
+      BASE_DIRS
+        "${CMAKE_CURRENT_SOURCE_DIR}"
+      FILES
+        importable.cxx)
+target_compile_features(depchain_with_modules_json_file PUBLIC cxx_std_20)
+
+add_executable(depchain_modules_json_file)
+target_sources(depchain_modules_json_file
+  PRIVATE
+    main.cxx)
+target_link_libraries(depchain_modules_json_file
+  PRIVATE
+    depchain_with_modules_json_file)
+add_test(NAME depchain_modules_json_file COMMAND depchain_modules_json_file)

+ 6 - 0
Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/importable.cxx

@@ -0,0 +1,6 @@
+export module importable;
+
+export int from_import()
+{
+  return 0;
+}

+ 6 - 0
Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/main.cxx

@@ -0,0 +1,6 @@
+import importable;
+
+int main(int argc, char* argv[])
+{
+  return from_import();
+}

+ 7 - 0
Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/pre-rebuild.cmake

@@ -0,0 +1,7 @@
+if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
+  set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/Debug/CXXModules.json")
+else ()
+  set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/CXXModules.json")
+endif ()
+
+file(TOUCH_NOCREATE "${RunCMake_TEST_BINARY_DIR}/${modules_json_path}")