Skip to content

Commit cff67a9

Browse files
committed
Auto merge of #14212 - ehuss:fix-compatible_with_older_cargo, r=epage
Fix compatible_with_older_cargo test. This fixes the `global_cache_tracker::compatible_with_older_cargo` test which is failing with the latest nightly, with the following error: ``` thread 'main' panicked at src/cargo/core/compiler/fingerprint/mod.rs:1834:9: assertion `left == right` failed left: "0b455c154b949b0d" right: "ce6d4698ea4438f2" ``` The problem is that it was running stable `cargo` from CARGO_HOME, but was always using nightly `rustc`. The assertion was triggering because it was reusing the same fingerprint file between stable and nightly, but the Hash impl changed in nightly via rust-lang/rust#127297. Under normal circumstances, when switching between toolchains, the hash should change ensuring the toolchains each use a separate directory. The fix here is to ensure that when running stable cargo that it also uses stable rustc. This helps ensure that the hashes between cargo invocations changes, and they use separate directories.
2 parents e98f702 + 95e8b1c commit cff67a9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/testsuite/global_cache_tracker.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use cargo_test_support::{
2020
thread_wait_timeout, Execs, Project,
2121
};
2222
use itertools::Itertools;
23+
use std::env;
2324
use std::fmt::Write;
2425
use std::path::Path;
2526
use std::path::PathBuf;
@@ -169,12 +170,19 @@ fn populate_cache(
169170
(cache_dir, src_dir)
170171
}
171172

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

180188
#[cargo_test]

0 commit comments

Comments
 (0)