Skip to content

Commit

Permalink
Auto merge of #14212 - ehuss:fix-compatible_with_older_cargo, r=epage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 8, 2024
2 parents e98f702 + 95e8b1c commit cff67a9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use cargo_test_support::{
thread_wait_timeout, Execs, Project,
};
use itertools::Itertools;
use std::env;
use std::fmt::Write;
use std::path::Path;
use std::path::PathBuf;
Expand Down Expand Up @@ -169,12 +170,19 @@ fn populate_cache(
(cache_dir, src_dir)
}

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

#[cargo_test]
Expand Down

0 comments on commit cff67a9

Please sign in to comment.