run_make_support/
env.rs

1use std::ffi::OsString;
2
3#[track_caller]
4#[must_use]
5pub fn env_var(name: &str) -> String {
6    match std::env::var(name) {
7        Ok(v) => v,
8        Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"),
9    }
10}
11
12#[track_caller]
13#[must_use]
14pub fn env_var_os(name: &str) -> OsString {
15    match std::env::var_os(name) {
16        Some(v) => v,
17        None => panic!("failed to retrieve environment variable {name:?}"),
18    }
19}
20
21/// Check if `NO_DEBUG_ASSERTIONS` is set (usually this may be set in CI jobs).
22#[track_caller]
23#[must_use]
24pub fn no_debug_assertions() -> bool {
25    std::env::var_os("NO_DEBUG_ASSERTIONS").is_some()
26}
27
28/// A wrapper around [`std::env::set_current_dir`] which includes the directory
29/// path in the panic message.
30#[track_caller]
31pub fn set_current_dir<P: AsRef<std::path::Path>>(dir: P) {
32    std::env::set_current_dir(dir.as_ref())
33        .expect(&format!("could not set current directory to \"{}\"", dir.as_ref().display()));
34}