Skip to content

Commit 2aa0773

Browse files
authored
Remove legacy tmpdir support (rust-lang#16342)
This removes the legacy tmp directory support in cargo's integration test. This has been around since 2021, and I'm pretty sure is no longer needed.
2 parents e95cf56 + 2cb8682 commit 2aa0773

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

crates/cargo-test-macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
219219

220220
let mut new_body = to_token_stream(
221221
r#"let _test_guard = {
222-
let tmp_dir = option_env!("CARGO_TARGET_TMPDIR");
222+
let tmp_dir = env!("CARGO_TARGET_TMPDIR");
223223
cargo_test_support::paths::init_root(tmp_dir)
224224
};"#,
225225
);

crates/cargo-test-support/src/paths.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use itertools::Itertools;
55
use walkdir::WalkDir;
66

77
use std::cell::RefCell;
8-
use std::env;
98
use std::fs;
109
use std::io::{self, ErrorKind};
1110
use std::path::{Path, PathBuf};
@@ -21,28 +20,13 @@ static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
2120

2221
static GLOBAL_ROOT: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
2322

24-
/// This is used when running cargo is pre-CARGO_TARGET_TMPDIR
25-
/// TODO: Remove when `CARGO_TARGET_TMPDIR` grows old enough.
26-
fn global_root_legacy() -> PathBuf {
27-
let mut path = t!(env::current_exe());
28-
path.pop(); // chop off exe name
29-
path.pop(); // chop off "deps"
30-
path.push("tmp");
31-
path.mkdir_p();
32-
path
33-
}
34-
35-
fn set_global_root(tmp_dir: Option<&'static str>) {
23+
fn set_global_root(tmp_dir: &'static str) {
3624
let mut lock = GLOBAL_ROOT
3725
.get_or_init(|| Default::default())
3826
.lock()
3927
.unwrap();
4028
if lock.is_none() {
41-
let mut root = match tmp_dir {
42-
Some(tmp_dir) => PathBuf::from(tmp_dir),
43-
None => global_root_legacy(),
44-
};
45-
29+
let mut root = PathBuf::from(tmp_dir);
4630
root.push(CARGO_INTEGRATION_TEST_DIR);
4731
*lock = Some(root);
4832
}
@@ -80,7 +64,7 @@ pub struct TestIdGuard {
8064
}
8165

8266
/// For test harnesses like [`crate::cargo_test`]
83-
pub fn init_root(tmp_dir: Option<&'static str>) -> TestIdGuard {
67+
pub fn init_root(tmp_dir: &'static str) -> TestIdGuard {
8468
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
8569

8670
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);

0 commit comments

Comments
 (0)