Skip to content

Commit

Permalink
make our filename handling work better across platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 8, 2020
1 parent 868dcbb commit 6c260a4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@ fn phase_cargo_rustc(args: env::ArgsOs) {
let filename = out_filename("", "");

if verbose {
eprintln!("[cargo-miri rustc] writing run info to {:?}", filename.display());
eprintln!("[cargo-miri rustc] writing run info to `{}`", filename.display());
}

let file = File::create(&filename)
.unwrap_or_else(|_| show_error(format!("Cannot create {:?}", filename.display())));
.unwrap_or_else(|_| show_error(format!("Cannot create `{}`", filename.display())));
let file = BufWriter::new(file);
serde_json::ser::to_writer(file, &info)
.unwrap_or_else(|_| show_error(format!("Cannot write to {:?}", filename.display())));
.unwrap_or_else(|_| show_error(format!("Cannot write to `{}`", filename.display())));
return;
}

Expand Down Expand Up @@ -547,21 +547,26 @@ fn phase_cargo_rustc(args: env::ArgsOs) {

// Create a stub .rlib file if "link" was requested by cargo.
if emit_link_hack {
// FIXME: is "lib" always right?
// Some platforms prepend "lib", some do not... let's just create both files.
let filename = out_filename("lib", ".rlib");
File::create(filename).expect("Failed to create rlib file");
let filename = out_filename("", ".rlib");
File::create(filename).expect("Failed to create rlib file");
}
}

fn phase_cargo_runner(binary: &OsStr, binary_args: env::ArgsOs) {
let verbose = std::env::var_os("MIRI_VERBOSE").is_some();

let file = File::open(binary)
// Strip extension from binary name (Windows adds ".exe").
let mut filename = PathBuf::from(binary);
filename.set_extension("");
let file = File::open(&filename)
.unwrap_or_else(|_| show_error(format!("File {:?} not found or `cargo-miri` invoked incorrectly; please only invoke this binary through `cargo miri`", binary)));
let file = BufReader::new(file);
let info: CrateRunInfo = serde_json::from_reader(file)
.unwrap_or_else(|_| show_error(format!("File {:?} does not contain valid JSON", binary)));
fs::remove_file(binary)
fs::remove_file(&filename)
.unwrap_or_else(|_| show_error(format!("Unable to remove file {:?}", binary)));

let mut cmd = miri();
Expand Down

0 comments on commit 6c260a4

Please sign in to comment.