Skip to content

Commit 3d217f7

Browse files
authored
Merge pull request #75 from cuviper/probe_cleanup
Remove probe output files
2 parents d07df66 + b1928ba commit 3d217f7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,11 @@ impl AutoCfg {
272272
}
273273

274274
fn probe_fmt<'a>(&self, source: Arguments<'a>) -> Result<(), Error> {
275+
let crate_name = self.new_crate_name();
275276
let mut command = self.rustc.command();
276277
command
277278
.arg("--crate-name")
278-
.arg(self.new_crate_name())
279+
.arg(&crate_name)
279280
.arg("--crate-type=lib")
280281
.arg("--out-dir")
281282
.arg(&self.out_dir)
@@ -295,7 +296,16 @@ impl AutoCfg {
295296
drop(stdin);
296297

297298
match child.wait() {
298-
Ok(status) if status.success() => Ok(()),
299+
Ok(status) if status.success() => {
300+
// Try to remove the output file so it doesn't look like a build product for
301+
// systems like bazel -- but this is best-effort, so we can ignore failure.
302+
// The probe itself is already considered successful at this point.
303+
let mut file = self.out_dir.join(crate_name);
304+
file.set_extension("ll");
305+
let _ = fs::remove_file(file);
306+
307+
Ok(())
308+
}
299309
Ok(status) => Err(error::from_exit(status)),
300310
Err(error) => Err(error::from_io(error)),
301311
}

tests/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,16 @@ fn probe_raw() {
136136
.probe_raw(&f("#![deny(dead_code)] pub fn x() {}"))
137137
.is_ok());
138138
}
139+
140+
#[test]
141+
fn probe_cleanup() {
142+
let dir = support::out_dir().join("autocfg_test_probe_cleanup");
143+
std::fs::create_dir(&dir).unwrap();
144+
145+
let ac = AutoCfg::with_dir(&dir).unwrap();
146+
assert!(ac.probe_type("i32"));
147+
148+
// NB: this is not `remove_dir_all`, so it will only work if the directory
149+
// is empty -- i.e. the probe should have removed any output files.
150+
std::fs::remove_dir(&dir).unwrap();
151+
}

0 commit comments

Comments
 (0)