From 6c260a4aa9984604395ccfa3d4cf2ae8c9a0df47 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 8 Sep 2020 20:18:08 +0200 Subject: [PATCH] make our filename handling work better across platforms --- cargo-miri/bin.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 68ced8c58f..e71ac82e0e 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -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; } @@ -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();