Skip to content

Commit 5d97225

Browse files
committed
Auto merge of #9206 - ehuss:testsuite-rustup, r=Eh2406
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.
2 parents 572e201 + c73765f commit 5d97225

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,16 @@ fn _process(t: &OsStr) -> cargo::util::ProcessBuilder {
15821582
p.env_remove(&k);
15831583
}
15841584
}
1585+
if env::var_os("RUSTUP_TOOLCHAIN").is_some() {
1586+
// Override the PATH to avoid executing the rustup wrapper thousands
1587+
// of times. This makes the testsuite run substantially faster.
1588+
let path = env::var_os("PATH").unwrap_or_default();
1589+
let paths = env::split_paths(&path);
1590+
let mut outer_cargo = PathBuf::from(env::var_os("CARGO").unwrap());
1591+
outer_cargo.pop();
1592+
let new_path = env::join_paths(std::iter::once(outer_cargo).chain(paths)).unwrap();
1593+
p.env("PATH", new_path);
1594+
}
15851595

15861596
p.cwd(&paths::root())
15871597
.env("HOME", paths::home())

tests/testsuite/old_cargos.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use semver::Version;
1919
use std::fs;
2020

2121
fn tc_process(cmd: &str, toolchain: &str) -> ProcessBuilder {
22-
if toolchain == "this" {
22+
let mut p = if toolchain == "this" {
2323
if cmd == "cargo" {
2424
process(&cargo_exe())
2525
} else {
@@ -29,7 +29,10 @@ fn tc_process(cmd: &str, toolchain: &str) -> ProcessBuilder {
2929
let mut cmd = process(cmd);
3030
cmd.arg(format!("+{}", toolchain));
3131
cmd
32-
}
32+
};
33+
// Reset PATH since `process` modifies it to remove rustup.
34+
p.env("PATH", std::env::var_os("PATH").unwrap());
35+
p
3336
}
3437

3538
/// Returns a sorted list of all toolchains.

0 commit comments

Comments
 (0)