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
This commit is contained in:
Jeremy Day
2023-12-15 12:18:39 -08:00
parent edb10c5325
commit 1161ad76ac
4 changed files with 14 additions and 2 deletions

View File

@@ -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(

View File

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

View File

@@ -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)

View File

@@ -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