Browse Source

Swift/Ninja: Always restat swift build commands

The swift toolchain leaves output files untouched
if there are no meaningful input changes; without
restat, this causes ninja to needlessly rebuild
targets that are not actually out-of-date

Fixes: #25496
Jeremy Day 2 years ago
parent
commit
1161ad76ac

+ 4 - 0
Source/cmNinjaTargetGenerator.cxx

@@ -1948,6 +1948,10 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement(
     this->LanguageCompilerRule(language, config, WithScanning::No));
   cmNinjaVars& vars = objBuild.Variables;
 
+  // The swift toolchain leaves outputs untouched if there are no meaningful
+  // changes to input files (e.g. addition of a comment).
+  vars.emplace("restat", "1");
+
   std::string const moduleName =
     getTargetPropertyOrDefault(target, "Swift_MODULE_NAME", target.GetName());
   std::string const moduleDirectory = getTargetPropertyOrDefault(

+ 2 - 0
Tests/RunCMake/Swift/NoWorkToDo-norelink-stdout.txt

@@ -0,0 +1,2 @@
+.*\[1\/4\].*
+.*\[2\/3\].*

+ 5 - 2
Tests/RunCMake/Swift/NoWorkToDo.cmake

@@ -1,6 +1,9 @@
 cmake_policy(SET CMP0157 NEW)
 enable_language(Swift)
-add_executable(hello1 hello.swift)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/hello.swift "")
+
+add_executable(hello1 ${CMAKE_CURRENT_BINARY_DIR}/hello.swift)
 set_target_properties(hello1 PROPERTIES ENABLE_EXPORTS TRUE)
 
-add_executable(hello2 hello.swift)
+add_executable(hello2 ${CMAKE_CURRENT_BINARY_DIR}/hello.swift)

+ 3 - 0
Tests/RunCMake/Swift/RunCMakeTest.cmake

@@ -27,6 +27,9 @@ elseif(RunCMake_GENERATOR STREQUAL Ninja)
       set(RunCMake_TEST_OUTPUT_MERGE 1)
       run_cmake_command(NoWorkToDo-build ${CMAKE_COMMAND} --build .)
       run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain)
+      file(WRITE ${RunCMake_TEST_BINARY_DIR}/hello.swift "//No-op change\n")
+      run_cmake_command(NoWorkToDo-norelink ${CMAKE_COMMAND} --build . -- -d explain)
+      run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain)
     endblock()
 
     # Test that intermediate static libraries are rebuilt when the public