Skip to content

Commit

Permalink
Merge pull request #388 from dtolnay/outdir
Browse files Browse the repository at this point in the history
Clean up dep-info files from OUT_DIR
  • Loading branch information
dtolnay authored Oct 22, 2024
2 parents a0b868a + f130b76 commit 4986853
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::env;
use std::ffi::OsString;
use std::fs;
use std::io::ErrorKind;
use std::iter;
use std::path::Path;
use std::process::{self, Command, Stdio};
Expand Down Expand Up @@ -125,8 +127,16 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {

let rustc = cargo_env_var("RUSTC");
let out_dir = cargo_env_var("OUT_DIR");
let out_subdir = Path::new(&out_dir).join("probe");
let probefile = Path::new("build").join("probe.rs");

if let Err(err) = fs::create_dir(&out_subdir) {
if err.kind() != ErrorKind::AlreadyExists {
eprintln!("Failed to create {}: {}", out_subdir.display(), err);
process::exit(1);
}
}

let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty());
let rustc_workspace_wrapper =
env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty());
Expand All @@ -148,7 +158,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
.arg("--emit=dep-info,metadata")
.arg("--cap-lints=allow")
.arg("--out-dir")
.arg(out_dir)
.arg(&out_subdir)
.arg(probefile);

if let Some(target) = env::var_os("TARGET") {
Expand All @@ -164,10 +174,22 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
}
}

match cmd.status() {
let success = match cmd.status() {
Ok(status) => status.success(),
Err(_) => false,
};

// Clean up to avoid leaving nondeterministic absolute paths in the dep-info
// file in OUT_DIR, which causes nonreproducible builds in build systems
// that treat the entire OUT_DIR as an artifact.
if let Err(err) = fs::remove_dir_all(&out_subdir) {
if err.kind() != ErrorKind::NotFound {
eprintln!("Failed to clean up {}: {}", out_subdir.display(), err);
process::exit(1);
}
}

success
}

fn rustc_minor_version() -> Option<u32> {
Expand Down

0 comments on commit 4986853

Please sign in to comment.