Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ impl AutoCfg {
}

fn probe_fmt<'a>(&self, source: Arguments<'a>) -> Result<(), Error> {
let crate_name = self.new_crate_name();
let mut command = self.rustc.command();
command
.arg("--crate-name")
.arg(self.new_crate_name())
.arg(&crate_name)
.arg("--crate-type=lib")
.arg("--out-dir")
.arg(&self.out_dir)
Expand All @@ -295,7 +296,16 @@ impl AutoCfg {
drop(stdin);

match child.wait() {
Ok(status) if status.success() => Ok(()),
Ok(status) if status.success() => {
// Try to remove the output file so it doesn't look like a build product for
// systems like bazel -- but this is best-effort, so we can ignore failure.
// The probe itself is already considered successful at this point.
let mut file = self.out_dir.join(crate_name);
file.set_extension("ll");
let _ = fs::remove_file(file);

Ok(())
}
Ok(status) => Err(error::from_exit(status)),
Err(error) => Err(error::from_io(error)),
}
Expand Down
13 changes: 13 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ fn probe_raw() {
.probe_raw(&f("#![deny(dead_code)] pub fn x() {}"))
.is_ok());
}

#[test]
fn probe_cleanup() {
let dir = support::out_dir().join("autocfg_test_probe_cleanup");
std::fs::create_dir(&dir).unwrap();

let ac = AutoCfg::with_dir(&dir).unwrap();
assert!(ac.probe_type("i32"));

// NB: this is not `remove_dir_all`, so it will only work if the directory
// is empty -- i.e. the probe should have removed any output files.
std::fs::remove_dir(&dir).unwrap();
}