Skip to content

Commit 7441fca

Browse files
ehussweihanglo
authored andcommitted
Fix compatible_with_older_cargo test.
1 parent 45d41ba commit 7441fca

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/testsuite/global_cache_tracker.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use cargo_test_support::{
1818
thread_wait_timeout, Execs, Project,
1919
};
2020
use itertools::Itertools;
21+
use std::env;
2122
use std::fmt::Write;
2223
use std::path::Path;
2324
use std::path::PathBuf;
@@ -167,12 +168,19 @@ fn populate_cache(
167168
(cache_dir, src_dir)
168169
}
169170

171+
/// Returns an `Execs` that will run the rustup `cargo` proxy from the global
172+
/// system's cargo home directory.
170173
fn rustup_cargo() -> Execs {
171-
// Get the path to the rustup cargo wrapper. This is necessary because
172-
// cargo adds the "deps" directory into PATH on Windows, which points to
173-
// the wrong cargo.
174-
let rustup_cargo = Path::new(&std::env::var_os("CARGO_HOME").unwrap()).join("bin/cargo");
175-
execs().with_process_builder(process(rustup_cargo))
174+
// Modify the PATH to ensure that `cargo` and `rustc` comes from
175+
// CARGO_HOME. This is necessary because cargo adds the "deps" directory
176+
// into PATH on Windows, which points to the wrong cargo.
177+
let real_cargo_home_bin = Path::new(&std::env::var_os("CARGO_HOME").unwrap()).join("bin");
178+
let mut paths = vec![real_cargo_home_bin];
179+
paths.extend(env::split_paths(&env::var_os("PATH").unwrap_or_default()));
180+
let path = env::join_paths(paths).unwrap();
181+
let mut e = execs().with_process_builder(process("cargo"));
182+
e.env("PATH", path);
183+
e
176184
}
177185

178186
#[cargo_test]

0 commit comments

Comments
 (0)