Skip to content

Commit

Permalink
write_to_file
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Jun 7, 2024
1 parent 21d17ab commit e557207
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 8 additions & 1 deletion crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ fn write_to_file<C: AsRef<[u8]>>(path: &str, contents: C) -> Result<()> {
.map_err(|_| Error::new("failed to create directory").with_path(path))?;
}

std::fs::write(path, contents).map_err(|_| Error::new("failed to write file").with_path(path))
let existing = std::fs::read(path).unwrap_or_default();

if contents.as_ref() != existing {
std::fs::write(path, contents)
.map_err(|_| Error::new("failed to write file").with_path(path))?;
}

Ok(())
}

fn canonicalize(value: &str) -> Result<String> {
Expand Down
9 changes: 0 additions & 9 deletions crates/tests/standalone/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ fn write_vtbl(output: &str, filter: &[&str]) {
}

fn riddle(output: &str, filter: &[&str], config: &[&str]) {
// 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");

command.args([
Expand Down

0 comments on commit e557207

Please sign in to comment.