Skip to content

Commit 0a9f9e0

Browse files
committed
factor out common code to determine miri binary
1 parent 3b7ae04 commit 0a9f9e0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/bin/cargo-miri.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,29 @@ fn list_targets() -> impl Iterator<Item=cargo_metadata::Target> {
119119
package.targets.into_iter()
120120
}
121121

122+
/// Returns the path to the `miri` binary
123+
fn find_miri() -> PathBuf {
124+
let mut path = std::env::current_exe().expect("current executable path invalid");
125+
path.set_file_name("miri");
126+
path
127+
}
128+
122129
/// Make sure that the `miri` and `rustc` binary are from the same sysroot.
123130
/// This can be violated e.g. when miri is locally built and installed with a different
124131
/// toolchain than what is used when `cargo miri` is run.
125132
fn test_sysroot_consistency() {
126133
fn get_sysroot(mut cmd: Command) -> PathBuf {
127134
let out = cmd.arg("--print").arg("sysroot")
128135
.output().expect("Failed to run rustc to get sysroot info");
129-
assert!(out.status.success(), "Bad statuc code when getting sysroot info");
136+
assert!(out.status.success(), "Bad status code when getting sysroot info");
130137
let sysroot = out.stdout.lines().nth(0)
131138
.expect("didn't get at least one line for the sysroot").unwrap();
132139
PathBuf::from(sysroot).canonicalize()
133140
.expect("Failed to canonicalize sysroot")
134141
}
135142

136143
let rustc_sysroot = get_sysroot(Command::new("rustc"));
137-
let miri_sysroot = {
138-
let mut path = std::env::current_exe().expect("current executable path invalid");
139-
path.set_file_name("miri");
140-
get_sysroot(Command::new(path))
141-
};
144+
let miri_sysroot = get_sysroot(Command::new(find_miri()));
142145

143146
if rustc_sysroot != miri_sysroot {
144147
show_error(format!(
@@ -451,9 +454,7 @@ fn inside_cargo_rustc() {
451454
};
452455

453456
let mut command = if needs_miri {
454-
let mut path = std::env::current_exe().expect("current executable path invalid");
455-
path.set_file_name("miri");
456-
Command::new(path)
457+
Command::new(find_miri())
457458
} else {
458459
Command::new("rustc")
459460
};

0 commit comments

Comments
 (0)