From 1ec6b0f7f48133a18bc02d04fa6149adf8b7f599 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Tue, 7 Apr 2026 13:01:56 +1000 Subject: [PATCH] test: Rebuild object files if command-line changes We previously did this by including the command-line hash in the filename, but we removed the hashes a while ago. --- wild/tests/integration_tests.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/wild/tests/integration_tests.rs b/wild/tests/integration_tests.rs index c385a212f..f54508746 100644 --- a/wild/tests/integration_tests.rs +++ b/wild/tests/integration_tests.rs @@ -2272,7 +2272,7 @@ fn build_obj( output_path.clone() }; - if is_newer(&output_file, deps.iter()) { + if command_line_unchanged(&command, &output_file) && is_newer(&output_file, deps.iter()) { return Ok(BuiltObject { path: output_path, inputs, @@ -2295,6 +2295,8 @@ fn build_obj( ); } + write_cmd_file(&command, &output_file)?; + if needs_run_with { post_process_rust_run_script(&output_path).with_context(|| { format!( @@ -2312,6 +2314,26 @@ fn build_obj( }) } +fn cmd_path(output_path: &Path) -> PathBuf { + add_to_path(output_path, ".cmd") +} + +/// Returns whether the command-line used to produce `output_path` is the same as previously used. +fn command_line_unchanged(command: &Command, output_path: &Path) -> bool { + let cmd_path = cmd_path(output_path); + if let Ok(existing_cmd) = std::fs::read_to_string(&cmd_path) { + existing_cmd == command_as_str(command) + } else { + false + } +} + +fn write_cmd_file(command: &Command, output_file: &Path) -> Result { + let cmd_path = cmd_path(output_file); + std::fs::write(&cmd_path, command_as_str(command))?; + Ok(()) +} + /// Verifies that if we've created or considered creating `output_path` previously in this process, /// that it was with the same command-line. fn verify_path_unique_for_args(output_path: &Path, command: &Command) -> Result {