From a443dc4ecdc2e85fbfabdd972028d51616ee20c0 Mon Sep 17 00:00:00 2001 From: "许杰友 Jieyou Xu (Joe)" Date: Wed, 17 Jul 2024 11:17:28 +0000 Subject: run_make_support: rename `env_checked` -> `env` --- src/tools/run-make-support/src/env.rs | 19 +++++++++++++++++++ src/tools/run-make-support/src/env_checked.rs | 20 -------------------- src/tools/run-make-support/src/external_deps/llvm.rs | 2 +- .../run-make-support/src/external_deps/python.rs | 2 +- .../run-make-support/src/external_deps/rustc.rs | 2 +- .../run-make-support/src/external_deps/rustdoc.rs | 2 +- src/tools/run-make-support/src/lib.rs | 4 ++-- src/tools/run-make-support/src/path_helpers.rs | 2 +- src/tools/run-make-support/src/util.rs | 2 +- 9 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 src/tools/run-make-support/src/env.rs delete mode 100644 src/tools/run-make-support/src/env_checked.rs (limited to 'src') diff --git a/src/tools/run-make-support/src/env.rs b/src/tools/run-make-support/src/env.rs new file mode 100644 index 00000000000..f52524e7d54 --- /dev/null +++ b/src/tools/run-make-support/src/env.rs @@ -0,0 +1,19 @@ +use std::ffi::OsString; + +#[track_caller] +#[must_use] +pub fn env_var(name: &str) -> String { + match std::env::var(name) { + Ok(v) => v, + Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"), + } +} + +#[track_caller] +#[must_use] +pub fn env_var_os(name: &str) -> OsString { + match std::env::var_os(name) { + Some(v) => v, + None => panic!("failed to retrieve environment variable {name:?}"), + } +} diff --git a/src/tools/run-make-support/src/env_checked.rs b/src/tools/run-make-support/src/env_checked.rs deleted file mode 100644 index 9f9d2445ef6..00000000000 --- a/src/tools/run-make-support/src/env_checked.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::env; -use std::ffi::OsString; - -#[track_caller] -#[must_use] -pub fn env_var(name: &str) -> String { - match env::var(name) { - Ok(v) => v, - Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"), - } -} - -#[track_caller] -#[must_use] -pub fn env_var_os(name: &str) -> OsString { - match env::var_os(name) { - Some(v) => v, - None => panic!("failed to retrieve environment variable {name:?}"), - } -} diff --git a/src/tools/run-make-support/src/external_deps/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs index 9c821dfc03d..5e8ad7ed312 100644 --- a/src/tools/run-make-support/src/external_deps/llvm.rs +++ b/src/tools/run-make-support/src/external_deps/llvm.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; /// Construct a new `llvm-readobj` invocation with the `GNU` output style. /// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`. diff --git a/src/tools/run-make-support/src/external_deps/python.rs b/src/tools/run-make-support/src/external_deps/python.rs index 59e725fd73e..fb885069371 100644 --- a/src/tools/run-make-support/src/external_deps/python.rs +++ b/src/tools/run-make-support/src/external_deps/python.rs @@ -1,5 +1,5 @@ use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; /// Obtain path of python as provided by the `PYTHON` environment variable. It is up to the caller /// to document and check if the python version is compatible with its intended usage. diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index ce04caf6d34..71d28dd9675 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -2,7 +2,7 @@ use std::ffi::{OsStr, OsString}; use std::path::Path; use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; use crate::path_helpers::cwd; use crate::util::set_host_rpath; diff --git a/src/tools/run-make-support/src/external_deps/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs index db324f07c7e..96c2218a563 100644 --- a/src/tools/run-make-support/src/external_deps/rustdoc.rs +++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs @@ -2,7 +2,7 @@ use std::ffi::OsStr; use std::path::Path; use crate::command::Command; -use crate::env_checked::{env_var, env_var_os}; +use crate::env::{env_var, env_var_os}; use crate::util::set_host_rpath; /// Construct a plain `rustdoc` invocation with no flags set. diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5befea53351..38070f79edc 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -10,7 +10,7 @@ mod util; pub mod artifact_names; pub mod assertion_helpers; pub mod diff; -pub mod env_checked; +pub mod env; pub mod external_deps; pub mod fs_helpers; pub mod fs_wrapper; @@ -48,7 +48,7 @@ pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; pub use diff::{diff, Diff}; /// Panic-on-fail [`std::env::var`] and [`std::env::var_os`] wrappers. -pub use env_checked::{env_var, env_var_os}; +pub use env::{env_var, env_var_os}; /// Convenience helpers for running binaries and other commands. pub use run::{cmd, run, run_fail, run_with_args}; diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index a35c32cbe48..f46368b53f8 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -4,7 +4,7 @@ use std::panic; use std::path::{Path, PathBuf}; use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; use crate::util::handle_failed_output; /// Return the current working directory. diff --git a/src/tools/run-make-support/src/util.rs b/src/tools/run-make-support/src/util.rs index 9ed92ac4156..703e3ad1c6c 100644 --- a/src/tools/run-make-support/src/util.rs +++ b/src/tools/run-make-support/src/util.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use crate::command::{Command, CompletedProcess}; -use crate::env_checked::env_var; +use crate::env::env_var; use crate::path_helpers::cwd; /// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the -- cgit 1.4.1-3-g733a5