Skip to content

Commit 3e8962c

Browse files
committed
Clean up dep-info files from OUT_DIR
1 parent 6b3395a commit 3e8962c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

build.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
use std::env;
55
use std::ffi::OsString;
6+
use std::fs;
7+
use std::io::ErrorKind;
68
use std::iter;
79
use std::path::Path;
810
use std::process::{self, Command, Stdio};
@@ -146,8 +148,16 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
146148

147149
let rustc = cargo_env_var("RUSTC");
148150
let out_dir = cargo_env_var("OUT_DIR");
151+
let out_subdir = Path::new(&out_dir).join("probe");
149152
let probefile = Path::new("build").join("probe.rs");
150153

154+
if let Err(err) = fs::create_dir(&out_subdir) {
155+
if err.kind() != ErrorKind::AlreadyExists {
156+
eprintln!("Failed to create {}: {}", out_subdir.display(), err);
157+
process::exit(1);
158+
}
159+
}
160+
151161
let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty());
152162
let rustc_workspace_wrapper =
153163
env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty());
@@ -169,7 +179,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
169179
.arg("--cap-lints=allow")
170180
.arg("--emit=dep-info,metadata")
171181
.arg("--out-dir")
172-
.arg(out_dir)
182+
.arg(&out_subdir)
173183
.arg(probefile);
174184

175185
if let Some(target) = env::var_os("TARGET") {
@@ -185,10 +195,22 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
185195
}
186196
}
187197

188-
match cmd.status() {
198+
let success = match cmd.status() {
189199
Ok(status) => status.success(),
190200
Err(_) => false,
201+
};
202+
203+
// Clean up to avoid leaving nondeterministic absolute paths in the dep-info
204+
// file in OUT_DIR, which causes nonreproducible builds in build systems
205+
// that treat the entire OUT_DIR as an artifact.
206+
if let Err(err) = fs::remove_dir_all(&out_subdir) {
207+
if err.kind() != ErrorKind::NotFound {
208+
eprintln!("Failed to clean up {}: {}", out_subdir.display(), err);
209+
process::exit(1);
210+
}
191211
}
212+
213+
success
192214
}
193215

194216
fn rustc_minor_version() -> Option<u32> {

0 commit comments

Comments
 (0)