From ed5185c613992dd803a91a03165a38cd43970933 Mon Sep 17 00:00:00 2001 From: rami3l Date: Fri, 13 Nov 2026 16:41:55 +0100 Subject: [PATCH 1/2] fix(test): restore old directory for tmp rustup installations --- src/test.rs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/test.rs b/src/test.rs index 90909262ec..ba22a5dce6 100644 --- a/src/test.rs +++ b/src/test.rs @@ -75,12 +75,33 @@ impl Env for HashMap { /// The path to a dir for this test binaries state fn exe_test_dir() -> io::Result { - let current_exe_path = env::current_exe().unwrap(); - let mut exe_dir = current_exe_path.parent().unwrap(); - if exe_dir.ends_with("deps") { - exe_dir = exe_dir.parent().unwrap(); - } - Ok(exe_dir.parent().unwrap().to_owned()) + let curr_exe = env::current_exe().unwrap(); + let curr_exe_dir = curr_exe.parent().unwrap(); + let mut comps = curr_exe_dir.components().collect::>(); + + let retained_comps = match &comps[..] { + // New `cargo` output directory layout since Rust v1.100.0: + // /(debug|release)/build/rustup//out/ + [base @ .., _profile, build, rustup, _hash, out] + if build.as_os_str() == "build" + && rustup.as_os_str() == "rustup" + && out.as_os_str() == "out" => + { + base.len() + } + // Legacy layout before Rust v1.100.0: + // /(debug|release)/deps/ + [base @ .., _profile, deps] if deps.as_os_str() == "deps" => base.len(), + _ => { + return Err(io::Error::other(format!( + "unexpected current exe path format: {}", + curr_exe.display() + ))); + } + }; + + comps.truncate(retained_comps); + Ok(PathBuf::from_iter(comps)) } /// Returns a tempdir for running tests in From 32f410d8fed61536120672f6c12eb392121ee4b8 Mon Sep 17 00:00:00 2001 From: rami3l Date: Fri, 13 Nov 2026 16:46:30 +0100 Subject: [PATCH 2/2] perf(test): try putting tmp rustup installations in OS' tmp directory --- src/test.rs | 24 +++++++++++++++++++++--- tests/suite/cli_rustup.rs | 3 +-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test.rs b/src/test.rs index ba22a5dce6..19115a5d1e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -19,11 +19,11 @@ use std::{ use sha2::{Digest, Sha256}; -use crate::{dist::TargetTuple, process::TestProcess}; +use crate::{dist::TargetTuple, process::TestProcess, utils::raw}; #[cfg(all(windows, any(test, feature = "test")))] pub(crate) fn test_id() -> String { - crate::utils::raw::random_string(8) + raw::random_string(8) } #[cfg(windows)] @@ -77,8 +77,26 @@ impl Env for HashMap { fn exe_test_dir() -> io::Result { let curr_exe = env::current_exe().unwrap(); let curr_exe_dir = curr_exe.parent().unwrap(); - let mut comps = curr_exe_dir.components().collect::>(); + // Make an empty dir and try to rename it to under the OS' tmp dir to check if they are on the + // same device. If they are, we can conveniently use the renamed dir as the base for our test + // directories. If not, we try to put the base dir in `./target/` as before. + let probe_dir = curr_exe_dir.join(format!("rustup-test-{}", raw::random_string(8))); + raw::ensure_dir_exists(&probe_dir, |_| ())?; + let tmp_test_dir = env::temp_dir().join("rustup-test"); + + let Err(e) = fs::rename(&probe_dir, &tmp_test_dir) else { + return Ok(tmp_test_dir); + }; + + fs::remove_dir(&probe_dir)?; + match e.kind() { + io::ErrorKind::DirectoryNotEmpty => return Ok(tmp_test_dir), + io::ErrorKind::CrossesDevices => (), + _ => return Err(e), + } + + let mut comps = curr_exe_dir.components().collect::>(); let retained_comps = match &comps[..] { // New `cargo` output directory layout since Rust v1.100.0: // /(debug|release)/build/rustup//out/ diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index a8bba8cecf..fa9ce8fcfb 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -4315,10 +4315,9 @@ async fn only_toml_in_rust_toolchain_toml() { cx.config .expect(["rustc", "--version"]) .await - .extend_redactions([("[CWD]", &cwd)]) .with_stderr(snapbox::str![[r#" ... -error: could not parse override file: '[CWD]/rust-toolchain.toml'[..] +error: could not parse override file: '[..]/rust-toolchain.toml'[..] ... "#]]) .is_err();