From 8cc2faefce806fdc04a9025c128da6d982beed2a Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 6 Jan 2024 18:35:34 +0000 Subject: [PATCH] Truncate standalone test files instead of removing --- 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 8af6e7a5897..6c25b82e98b 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 workaroud this, we truncate the file instead of deleting it. + // See #2777. + _ = std::fs::File::options() + .truncate(true) + .write(true) + .open(output); let mut command = std::process::Command::new("cargo");