Skip to content

Commit 197e657

Browse files
committed
Auto merge of #9679 - ehuss:testsuite-custom-toolchain, r=alexcrichton
Make it easier to run testsuite with a custom toolchain. The optimization added in #9206 to circumvent the rustup wrapper for rustc had a bad interaction when using a custom toolchain (like `cargo +stage1 test`). It was using the `rustc` from where `cargo` is located, but custom toolchains often don't have cargo. This would instead use the nightly rustc (due to rustup's [fallback](https://github.com/rust-lang/rustup/blob/eaee3e723cd44b4b968b79b0ec2e8f766f1dfc77/src/config.rs#L942-L975)). This changes it to query rustup directly to ask it where the overridden rustc is located.
2 parents f2496ee + b67454c commit 197e657

File tree

1 file changed

+19
-3
lines changed
  • crates/cargo-test-support/src

1 file changed

+19
-3
lines changed

crates/cargo-test-support/src/lib.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,27 @@ fn _process(t: &OsStr) -> ProcessBuilder {
10641064
if env::var_os("RUSTUP_TOOLCHAIN").is_some() {
10651065
// Override the PATH to avoid executing the rustup wrapper thousands
10661066
// of times. This makes the testsuite run substantially faster.
1067+
lazy_static::lazy_static! {
1068+
static ref RUSTC_DIR: PathBuf = {
1069+
match ProcessBuilder::new("rustup")
1070+
.args(&["which", "rustc"])
1071+
.exec_with_output()
1072+
{
1073+
Ok(output) => {
1074+
let s = str::from_utf8(&output.stdout).expect("utf8").trim();
1075+
let mut p = PathBuf::from(s);
1076+
p.pop();
1077+
p
1078+
}
1079+
Err(e) => {
1080+
panic!("RUSTUP_TOOLCHAIN was set, but could not run rustup: {}", e);
1081+
}
1082+
}
1083+
};
1084+
}
10671085
let path = env::var_os("PATH").unwrap_or_default();
10681086
let paths = env::split_paths(&path);
1069-
let mut outer_cargo = PathBuf::from(env::var_os("CARGO").unwrap());
1070-
outer_cargo.pop();
1071-
let new_path = env::join_paths(std::iter::once(outer_cargo).chain(paths)).unwrap();
1087+
let new_path = env::join_paths(std::iter::once(RUSTC_DIR.clone()).chain(paths)).unwrap();
10721088
p.env("PATH", new_path);
10731089
}
10741090

0 commit comments

Comments
 (0)