Skip to content

Commit

Permalink
testsuite: Improve performance when using rustup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Feb 25, 2021
1 parent 572e201 commit c73765f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,16 @@ fn _process(t: &OsStr) -> cargo::util::ProcessBuilder {
p.env_remove(&k);
}
}
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.
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();
p.env("PATH", new_path);
}

p.cwd(&paths::root())
.env("HOME", paths::home())
Expand Down
7 changes: 5 additions & 2 deletions tests/testsuite/old_cargos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use semver::Version;
use std::fs;

fn tc_process(cmd: &str, toolchain: &str) -> ProcessBuilder {
if toolchain == "this" {
let mut p = if toolchain == "this" {
if cmd == "cargo" {
process(&cargo_exe())
} else {
Expand All @@ -29,7 +29,10 @@ fn tc_process(cmd: &str, toolchain: &str) -> ProcessBuilder {
let mut cmd = process(cmd);
cmd.arg(format!("+{}", toolchain));
cmd
}
};
// Reset PATH since `process` modifies it to remove rustup.
p.env("PATH", std::env::var_os("PATH").unwrap());
p
}

/// Returns a sorted list of all toolchains.
Expand Down

0 comments on commit c73765f

Please sign in to comment.