Skip to content

Commit f130b76

Browse files
committed
Clean up dep-info files from OUT_DIR
1 parent a0b868a commit f130b76

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
@@ -1,5 +1,7 @@
11
use std::env;
22
use std::ffi::OsString;
3+
use std::fs;
4+
use std::io::ErrorKind;
35
use std::iter;
46
use std::path::Path;
57
use std::process::{self, Command, Stdio};
@@ -125,8 +127,16 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
125127

126128
let rustc = cargo_env_var("RUSTC");
127129
let out_dir = cargo_env_var("OUT_DIR");
130+
let out_subdir = Path::new(&out_dir).join("probe");
128131
let probefile = Path::new("build").join("probe.rs");
129132

133+
if let Err(err) = fs::create_dir(&out_subdir) {
134+
if err.kind() != ErrorKind::AlreadyExists {
135+
eprintln!("Failed to create {}: {}", out_subdir.display(), err);
136+
process::exit(1);
137+
}
138+
}
139+
130140
let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty());
131141
let rustc_workspace_wrapper =
132142
env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty());
@@ -148,7 +158,7 @@ fn compile_probe(rustc_bootstrap: bool) -> bool {
148158
.arg("--emit=dep-info,metadata")
149159
.arg("--cap-lints=allow")
150160
.arg("--out-dir")
151-
.arg(out_dir)
161+
.arg(&out_subdir)
152162
.arg(probefile);
153163

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

167-
match cmd.status() {
177+
let success = match cmd.status() {
168178
Ok(status) => status.success(),
169179
Err(_) => false,
180+
};
181+
182+
// Clean up to avoid leaving nondeterministic absolute paths in the dep-info
183+
// file in OUT_DIR, which causes nonreproducible builds in build systems
184+
// that treat the entire OUT_DIR as an artifact.
185+
if let Err(err) = fs::remove_dir_all(&out_subdir) {
186+
if err.kind() != ErrorKind::NotFound {
187+
eprintln!("Failed to clean up {}: {}", out_subdir.display(), err);
188+
process::exit(1);
189+
}
170190
}
191+
192+
success
171193
}
172194

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

0 commit comments

Comments
 (0)