diff options
Diffstat (limited to 'src/tools/cargo/crates/cargo-test-support')
5 files changed, 28 insertions, 20 deletions
diff --git a/src/tools/cargo/crates/cargo-test-support/src/containers.rs b/src/tools/cargo/crates/cargo-test-support/src/containers.rs index 17040d82a..22fd5fd85 100644 --- a/src/tools/cargo/crates/cargo-test-support/src/containers.rs +++ b/src/tools/cargo/crates/cargo-test-support/src/containers.rs @@ -94,7 +94,9 @@ impl Container { let image_base = self.build_context.file_name().unwrap(); let image_name = format!("cargo-test-{}", image_base.to_str().unwrap()); - let _lock = BUILD_LOCK.lock().unwrap(); + let _lock = BUILD_LOCK + .lock() + .map_err(|_| panic!("previous docker build failed, unable to run test")); ProcessBuilder::new("docker") .args(&["build", "--tag", image_name.as_str()]) .arg(&self.build_context) diff --git a/src/tools/cargo/crates/cargo-test-support/src/lib.rs b/src/tools/cargo/crates/cargo-test-support/src/lib.rs index d27aab44f..a2fa54c60 100644 --- a/src/tools/cargo/crates/cargo-test-support/src/lib.rs +++ b/src/tools/cargo/crates/cargo-test-support/src/lib.rs @@ -110,7 +110,9 @@ impl FileBuilder { fn mk(&mut self) { if self.executable { - self.path.set_extension(env::consts::EXE_EXTENSION); + let mut path = self.path.clone().into_os_string(); + write!(path, "{}", env::consts::EXE_SUFFIX).unwrap(); + self.path = path.into(); } self.dirname().mkdir_p(); @@ -1259,6 +1261,8 @@ pub trait TestEnv: Sized { .env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "stable") // Keeps cargo within its sandbox. .env("__CARGO_TEST_DISABLE_GLOBAL_KNOWN_HOST", "1") + // Set retry sleep to 1 millisecond. + .env("__CARGO_TEST_FIXED_RETRY_SLEEP_MS", "1") // Incremental generates a huge amount of data per test, which we // don't particularly need. Tests that specifically need to check // the incremental behavior should turn this back on. diff --git a/src/tools/cargo/crates/cargo-test-support/src/paths.rs b/src/tools/cargo/crates/cargo-test-support/src/paths.rs index ef1fddb70..50040e1d4 100644 --- a/src/tools/cargo/crates/cargo-test-support/src/paths.rs +++ b/src/tools/cargo/crates/cargo-test-support/src/paths.rs @@ -1,7 +1,6 @@ use filetime::{self, FileTime}; -use lazy_static::lazy_static; + use std::cell::RefCell; -use std::collections::HashMap; use std::env; use std::fs; use std::io::{self, ErrorKind}; @@ -9,15 +8,11 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; +use std::sync::OnceLock; static CARGO_INTEGRATION_TEST_DIR: &str = "cit"; -lazy_static! { - // TODO: Use `SyncOnceCell` when stable - static ref GLOBAL_ROOT: Mutex<Option<PathBuf>> = Mutex::new(None); - - static ref TEST_ROOTS: Mutex<HashMap<String, PathBuf>> = Default::default(); -} +static GLOBAL_ROOT: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new(); /// This is used when running cargo is pre-CARGO_TARGET_TMPDIR /// TODO: Remove when CARGO_TARGET_TMPDIR grows old enough. @@ -31,7 +26,10 @@ fn global_root_legacy() -> PathBuf { } fn set_global_root(tmp_dir: Option<&'static str>) { - let mut lock = GLOBAL_ROOT.lock().unwrap(); + let mut lock = GLOBAL_ROOT + .get_or_init(|| Default::default()) + .lock() + .unwrap(); if lock.is_none() { let mut root = match tmp_dir { Some(tmp_dir) => PathBuf::from(tmp_dir), @@ -44,7 +42,10 @@ fn set_global_root(tmp_dir: Option<&'static str>) { } pub fn global_root() -> PathBuf { - let lock = GLOBAL_ROOT.lock().unwrap(); + let lock = GLOBAL_ROOT + .get_or_init(|| Default::default()) + .lock() + .unwrap(); match lock.as_ref() { Some(p) => p.clone(), None => unreachable!("GLOBAL_ROOT not set yet"), diff --git a/src/tools/cargo/crates/cargo-test-support/src/registry.rs b/src/tools/cargo/crates/cargo-test-support/src/registry.rs index 0cf82cb70..910f95bfa 100644 --- a/src/tools/cargo/crates/cargo-test-support/src/registry.rs +++ b/src/tools/cargo/crates/cargo-test-support/src/registry.rs @@ -1342,7 +1342,7 @@ impl Package { /// Sets the index schema version for this package. /// - /// See `cargo::sources::registry::RegistryPackage` for more information. + /// See `cargo::sources::registry::IndexPackage` for more information. pub fn schema_version(&mut self, version: u32) -> &mut Package { self.v = Some(version); self diff --git a/src/tools/cargo/crates/cargo-test-support/src/tools.rs b/src/tools/cargo/crates/cargo-test-support/src/tools.rs index 7c056b6fa..2ce2849ae 100644 --- a/src/tools/cargo/crates/cargo-test-support/src/tools.rs +++ b/src/tools/cargo/crates/cargo-test-support/src/tools.rs @@ -1,20 +1,21 @@ //! Common executables that can be reused by various tests. use crate::{basic_manifest, paths, project, Project}; -use lazy_static::lazy_static; use std::path::{Path, PathBuf}; use std::sync::Mutex; +use std::sync::OnceLock; -lazy_static! { - static ref ECHO_WRAPPER: Mutex<Option<PathBuf>> = Mutex::new(None); - static ref ECHO: Mutex<Option<PathBuf>> = Mutex::new(None); -} +static ECHO_WRAPPER: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new(); +static ECHO: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new(); /// Returns the path to an executable that works as a wrapper around rustc. /// /// The wrapper will echo the command line it was called with to stderr. pub fn echo_wrapper() -> PathBuf { - let mut lock = ECHO_WRAPPER.lock().unwrap(); + let mut lock = ECHO_WRAPPER + .get_or_init(|| Default::default()) + .lock() + .unwrap(); if let Some(path) = &*lock { return path.clone(); } @@ -53,7 +54,7 @@ pub fn echo_wrapper() -> PathBuf { /// /// Do not expect this to be anything fancy. pub fn echo() -> PathBuf { - let mut lock = ECHO.lock().unwrap(); + let mut lock = ECHO.get_or_init(|| Default::default()).lock().unwrap(); if let Some(path) = &*lock { return path.clone(); } |