Skip to content

Commit c793d60

Browse files
committed
handle binary suffices (for Windows); stop deleting fake binary
1 parent 53eab71 commit c793d60

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

cargo-miri/bin.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ impl CrateRunInfo {
5959
let env = env::vars_os().collect();
6060
CrateRunInfo { args, env }
6161
}
62+
63+
fn store(&self, filename: &Path) {
64+
let file = File::create(filename)
65+
.unwrap_or_else(|_| show_error(format!("Cannot create `{}`", filename.display())));
66+
let file = BufWriter::new(file);
67+
serde_json::ser::to_writer(file, self)
68+
.unwrap_or_else(|_| show_error(format!("Cannot write to `{}`", filename.display())));
69+
}
6270
}
6371

6472
fn show_help() {
@@ -482,18 +490,16 @@ fn phase_cargo_rustc(args: env::Args) {
482490
// Instead of compiling, we write JSON into the output file with all the relevant command-line flags
483491
// and environment variables; this is used when cargo calls us again in the CARGO_TARGET_RUNNER phase.
484492
let info = CrateRunInfo::collect(args);
485-
// FIXME: Windows might need a ".exe" suffix.
486493
let filename = out_filename("", "");
487-
488494
if verbose {
489495
eprintln!("[cargo-miri rustc] writing run info to `{}`", filename.display());
490496
}
491497

492-
let file = File::create(&filename)
493-
.unwrap_or_else(|_| show_error(format!("Cannot create `{}`", filename.display())));
494-
let file = BufWriter::new(file);
495-
serde_json::ser::to_writer(file, &info)
496-
.unwrap_or_else(|_| show_error(format!("Cannot write to `{}`", filename.display())));
498+
info.store(&filename);
499+
// For Windows, do the same thing again with `.exe` appended to the filename.
500+
// (Need to do this here as cargo moves that "binary" to a different place before running it.)
501+
info.store(&out_filename("", ".exe"));
502+
497503
return;
498504
}
499505

@@ -558,16 +564,11 @@ fn phase_cargo_rustc(args: env::Args) {
558564
fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
559565
let verbose = std::env::var_os("MIRI_VERBOSE").is_some();
560566

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

572573
let mut cmd = miri();
573574
// Forward rustc arguments. We need to patch "--extern" filenames because
@@ -593,10 +594,10 @@ fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
593594
if let Ok(a) = env::var("MIRIFLAGS") {
594595
// This code is taken from `RUSTFLAGS` handling in cargo.
595596
let args = a
596-
.split(' ')
597-
.map(str::trim)
598-
.filter(|s| !s.is_empty())
599-
.map(str::to_string);
597+
.split(' ')
598+
.map(str::trim)
599+
.filter(|s| !s.is_empty())
600+
.map(str::to_string);
600601
cmd.args(args);
601602
}
602603

0 commit comments

Comments
 (0)