From 3999d7d5105f431960b805422ea6601be8aac304 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 8 Jan 2024 17:04:44 +0000 Subject: [PATCH] Truncate standalone test files instead of removing (#2778) --- crates/tests/standalone/build.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/tests/standalone/build.rs b/crates/tests/standalone/build.rs index 8af6e7a589..9ed95c152a 100644 --- a/crates/tests/standalone/build.rs +++ b/crates/tests/standalone/build.rs @@ -165,7 +165,14 @@ fn write_no_inner_attr(output: &str, filter: &[&str]) { } fn riddle(output: &str, filter: &[&str], config: &[&str]) { - _ = std::fs::remove_file(output); + // Rust-analyzer may re-run build scripts whenever a source file is deleted + // which causes an endless loop if the file is deleted from a build script. + // To workaround this, we truncate the file instead of deleting it. + // See https://github.com/microsoft/windows-rs/issues/2777 + _ = std::fs::File::options() + .truncate(true) + .write(true) + .open(output); let mut command = std::process::Command::new("cargo");