Skip to content

Commit

Permalink
Auto merge of #9206 - ehuss:testsuite-rustup, r=Eh2406
Browse files Browse the repository at this point in the history
testsuite: Improve performance when using rustup.

The rustup wrapper adds a considerable amount of overhead when running processes like `rustc`.  This overrides `PATH` when running the testsuite to prioritize the actual executables to avoid the wrapper.

I'm not 100% confident this won't break something somewhere, but it seems like it should be safe.

In my tests, this makes the testsuite 1.5 to 1.7 times faster.
  • Loading branch information
bors committed Feb 25, 2021
2 parents 572e201 + c73765f commit 5d97225
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 5d97225

Please sign in to comment.