Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7e12dc0

Browse files
committed
run_make_support: move env_var{,_os} into env_checked module
1 parent 60764e6 commit 7e12dc0

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::ffi::OsString;
2+
use std::env;
3+
4+
#[track_caller]
5+
#[must_use]
6+
pub fn env_var(name: &str) -> String {
7+
match env::var(name) {
8+
Ok(v) => v,
9+
Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"),
10+
}
11+
}
12+
13+
#[track_caller]
14+
#[must_use]
15+
pub fn env_var_os(name: &str) -> OsString {
16+
match env::var_os(name) {
17+
Some(v) => v,
18+
None => panic!("failed to retrieve environment variable {name:?}"),
19+
}
20+
}

src/tools/run-make-support/src/lib.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod cc;
77
pub mod clang;
88
mod command;
99
pub mod diff;
10+
pub mod env_checked;
1011
pub mod fs_wrapper;
1112
pub mod llvm;
1213
mod macros;
@@ -15,8 +16,6 @@ pub mod rustc;
1516
pub mod rustdoc;
1617
pub mod targets;
1718

18-
use std::env;
19-
use std::ffi::OsString;
2019
use std::fs;
2120
use std::io;
2221
use std::panic;
@@ -31,6 +30,7 @@ pub use wasmparser;
3130
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3231
pub use clang::{clang, Clang};
3332
pub use diff::{diff, Diff};
33+
pub use env_checked::{env_var, env_var_os};
3434
pub use llvm::{
3535
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
3636
LlvmProfdata, LlvmReadobj,
@@ -42,24 +42,6 @@ pub use targets::{is_darwin, is_msvc, is_windows, target, uname};
4242

4343
use command::{Command, CompletedProcess};
4444

45-
#[track_caller]
46-
#[must_use]
47-
pub fn env_var(name: &str) -> String {
48-
match env::var(name) {
49-
Ok(v) => v,
50-
Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"),
51-
}
52-
}
53-
54-
#[track_caller]
55-
#[must_use]
56-
pub fn env_var_os(name: &str) -> OsString {
57-
match env::var_os(name) {
58-
Some(v) => v,
59-
None => panic!("failed to retrieve environment variable {name:?}"),
60-
}
61-
}
62-
6345
/// `AR`
6446
#[track_caller]
6547
pub fn ar(inputs: &[impl AsRef<Path>], output_path: impl AsRef<Path>) {
@@ -206,7 +188,7 @@ pub fn bin_name(name: &str) -> String {
206188
/// Return the current working directory.
207189
#[must_use]
208190
pub fn cwd() -> PathBuf {
209-
env::current_dir().unwrap()
191+
std::env::current_dir().unwrap()
210192
}
211193

212194
// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
@@ -343,10 +325,10 @@ pub fn set_host_rpath(cmd: &mut Command) {
343325
let mut paths = vec![];
344326
paths.push(cwd());
345327
paths.push(PathBuf::from(env_var("HOST_RPATH_DIR")));
346-
for p in env::split_paths(&env_var(&ld_lib_path_envvar)) {
328+
for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) {
347329
paths.push(p.to_path_buf());
348330
}
349-
env::join_paths(paths.iter()).unwrap()
331+
std::env::join_paths(paths.iter()).unwrap()
350332
});
351333
}
352334

@@ -498,8 +480,8 @@ pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
498480
let tmpdir = original_dir.join("../temporary-directory");
499481
copy_dir_all(".", &tmpdir);
500482

501-
env::set_current_dir(&tmpdir).unwrap();
483+
std::env::set_current_dir(&tmpdir).unwrap();
502484
callback();
503-
env::set_current_dir(original_dir).unwrap();
485+
std::env::set_current_dir(original_dir).unwrap();
504486
fs::remove_dir_all(tmpdir).unwrap();
505487
}

0 commit comments

Comments
 (0)