diff --git a/Cargo.toml b/Cargo.toml index a318dee..b9091f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ diff = "0.1.10" filetime = "0.2" getopts = "0.2" log = "0.4" -once_cell = "1.20" regex = "1.0" rustfix = "0.8" rustversion = "1.0" diff --git a/src/runtest.rs b/src/runtest.rs index 69e89f5..e2bba55 100644 --- a/src/runtest.rs +++ b/src/runtest.rs @@ -21,7 +21,6 @@ use filetime::FileTime; use regex::Regex; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; -use once_cell::sync::Lazy; use std::collections::HashMap; use std::collections::HashSet; use std::env; @@ -33,20 +32,21 @@ use std::io::{self, BufReader}; use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::str; -use std::sync::{Arc, Mutex, RwLock}; +use std::sync::{Arc, Mutex, OnceLock, RwLock}; use crate::extract_gdb_version; fn get_or_create_coverage_file(path: &Path, create: impl FnOnce() -> File) -> Arc> { - static COVERAGE_FILE_LOCKS: Lazy>>>> = - Lazy::new(Default::default); + static COVERAGE_FILE_LOCKS: OnceLock>>>> = + OnceLock::new(); + let locks = COVERAGE_FILE_LOCKS.get_or_init(Default::default); { - let locks = COVERAGE_FILE_LOCKS.read().unwrap(); + let locks = locks.read().unwrap(); locks.get(path).map(Arc::clone) } .unwrap_or_else(|| { - let mut locks = COVERAGE_FILE_LOCKS.write().unwrap(); + let mut locks = locks.write().unwrap(); locks .entry(path.to_path_buf()) .or_insert_with(|| Arc::new(Mutex::new(create()))) diff --git a/tests/bless.rs b/tests/bless.rs index 1c161d8..6c057da 100644 --- a/tests/bless.rs +++ b/tests/bless.rs @@ -4,7 +4,7 @@ extern crate compiletest_rs as compiletest; mod test_support; use crate::compiletest::Config; -use crate::test_support::{testsuite, TestsuiteBuilder, GLOBAL_ROOT}; +use crate::test_support::{global_root, testsuite, TestsuiteBuilder}; fn setup(mode: &str) -> (Config, TestsuiteBuilder) { let builder = testsuite(mode); @@ -12,7 +12,7 @@ fn setup(mode: &str) -> (Config, TestsuiteBuilder) { let cfg_mode = mode.parse().expect("Invalid mode"); config.mode = cfg_mode; config.src_base = builder.root.clone(); - config.build_base = GLOBAL_ROOT.join("build_base"); + config.build_base = global_root().join("build_base"); (config, builder) } diff --git a/tests/test_support/mod.rs b/tests/test_support/mod.rs index 638f10c..140ca82 100644 --- a/tests/test_support/mod.rs +++ b/tests/test_support/mod.rs @@ -2,12 +2,15 @@ //! //! Inspired by cargo's `cargo-test-support` crate: //! https://github.com/rust-lang/cargo/tree/master/crates/cargo-test-support -use once_cell::sync::Lazy; + use std::cell::RefCell; use std::env; use std::fs; use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::{ + atomic::{AtomicUsize, Ordering}, + OnceLock, +}; static COMPILETEST_INTEGRATION_TEST_DIR: &str = "cit"; @@ -15,16 +18,19 @@ thread_local! { static TEST_ID: RefCell> = RefCell::new(None); } -pub static GLOBAL_ROOT: Lazy = Lazy::new(|| { - let mut path = env::current_exe().unwrap(); - path.pop(); // chop off exe name - path.pop(); // chop off 'deps' part - path.pop(); // chop off 'debug' - - path.push(COMPILETEST_INTEGRATION_TEST_DIR); - path.mkdir_p(); - path -}); +pub fn global_root() -> &'static Path { + static GLOBAL_ROOT: OnceLock = OnceLock::new(); + GLOBAL_ROOT.get_or_init(|| { + let mut path = env::current_exe().unwrap(); + path.pop(); // chop off exe name + path.pop(); // chop off 'deps' part + path.pop(); // chop off 'debug' + + path.push(COMPILETEST_INTEGRATION_TEST_DIR); + path.mkdir_p(); + path + }) +} pub fn testsuite(mode: &str) -> TestsuiteBuilder { let builder = TestsuiteBuilder::new(mode); @@ -42,7 +48,7 @@ impl TestsuiteBuilder { let id = NEXT_ID.fetch_add(1, Ordering::Relaxed); TEST_ID.with(|n| *n.borrow_mut() = Some(id)); - let root = GLOBAL_ROOT + let root = global_root() .join(format!("id{}", TEST_ID.with(|n| n.borrow().unwrap()))) .join(mode); root.mkdir_p();