Skip to content

Commit

Permalink
Auto merge of #9679 - ehuss:testsuite-custom-toolchain, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 12, 2021
2 parents f2496ee + b67454c commit 197e657
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,27 @@ fn _process(t: &OsStr) -> ProcessBuilder {
if env::var_os("RUSTUP_TOOLCHAIN").is_some() {
// Override the PATH to avoid executing the rustup wrapper thousands
// of times. This makes the testsuite run substantially faster.
lazy_static::lazy_static! {
static ref RUSTC_DIR: PathBuf = {
match ProcessBuilder::new("rustup")
.args(&["which", "rustc"])
.exec_with_output()
{
Ok(output) => {
let s = str::from_utf8(&output.stdout).expect("utf8").trim();
let mut p = PathBuf::from(s);
p.pop();
p
}
Err(e) => {
panic!("RUSTUP_TOOLCHAIN was set, but could not run rustup: {}", e);
}
}
};
}
let path = env::var_os("PATH").unwrap_or_default();
let paths = env::split_paths(&path);
let mut outer_cargo = PathBuf::from(env::var_os("CARGO").unwrap());
outer_cargo.pop();
let new_path = env::join_paths(std::iter::once(outer_cargo).chain(paths)).unwrap();
let new_path = env::join_paths(std::iter::once(RUSTC_DIR.clone()).chain(paths)).unwrap();
p.env("PATH", new_path);
}

Expand Down

0 comments on commit 197e657

Please sign in to comment.