@@ -12,6 +12,7 @@ pub mod rustc;
12
12
pub mod rustdoc;
13
13
14
14
use std:: env;
15
+ use std:: ffi:: OsString ;
15
16
use std:: fs;
16
17
use std:: io;
17
18
use std:: path:: { Path , PathBuf } ;
@@ -30,14 +31,28 @@ pub use run::{run, run_fail};
30
31
pub use rustc:: { aux_build, rustc, Rustc } ;
31
32
pub use rustdoc:: { bare_rustdoc, rustdoc, Rustdoc } ;
32
33
34
+ pub fn env_var ( name : & str ) -> String {
35
+ match env:: var ( name) {
36
+ Ok ( v) => v,
37
+ Err ( err) => panic ! ( "failed to retrieve environment variable {name:?}: {err:?}" ) ,
38
+ }
39
+ }
40
+
41
+ pub fn env_var_os ( name : & str ) -> OsString {
42
+ match env:: var_os ( name) {
43
+ Some ( v) => v,
44
+ None => panic ! ( "failed to retrieve environment variable {name:?}" ) ,
45
+ }
46
+ }
47
+
33
48
/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`).
34
49
pub fn tmp_dir ( ) -> PathBuf {
35
- env :: var_os ( "TMPDIR" ) . unwrap ( ) . into ( )
50
+ env_var_os ( "TMPDIR" ) . into ( )
36
51
}
37
52
38
53
/// `TARGET`
39
54
pub fn target ( ) -> String {
40
- env :: var ( "TARGET" ) . unwrap ( )
55
+ env_var ( "TARGET" )
41
56
}
42
57
43
58
/// Check if target is windows-like.
@@ -62,7 +77,7 @@ pub fn static_lib(name: &str) -> PathBuf {
62
77
}
63
78
64
79
pub fn python_command ( ) -> Command {
65
- let python_path = std :: env :: var ( "PYTHON" ) . expect ( "PYTHON environment variable does not exist ") ;
80
+ let python_path = env_var ( "PYTHON" ) ;
66
81
Command :: new ( python_path)
67
82
}
68
83
@@ -73,7 +88,7 @@ pub fn htmldocck() -> Command {
73
88
}
74
89
75
90
pub fn source_path ( ) -> PathBuf {
76
- std :: env :: var ( "S" ) . expect ( "S variable does not exist ") . into ( )
91
+ env_var ( "S" ) . into ( )
77
92
}
78
93
79
94
/// Construct the static library name based on the platform.
@@ -208,12 +223,12 @@ fn handle_failed_output(cmd: &Command, output: Output, caller_line_number: u32)
208
223
209
224
/// Set the runtime library path as needed for running the host rustc/rustdoc/etc.
210
225
pub fn set_host_rpath ( cmd : & mut Command ) {
211
- let ld_lib_path_envvar = env :: var ( "LD_LIB_PATH_ENVVAR" ) . unwrap ( ) ;
226
+ let ld_lib_path_envvar = env_var ( "LD_LIB_PATH_ENVVAR" ) ;
212
227
cmd. env ( & ld_lib_path_envvar, {
213
228
let mut paths = vec ! [ ] ;
214
- paths. push ( PathBuf :: from ( env :: var ( "TMPDIR" ) . unwrap ( ) ) ) ;
215
- paths. push ( PathBuf :: from ( env :: var ( "HOST_RPATH_DIR" ) . unwrap ( ) ) ) ;
216
- for p in env:: split_paths ( & env :: var ( & ld_lib_path_envvar) . unwrap ( ) ) {
229
+ paths. push ( PathBuf :: from ( env_var ( "TMPDIR" ) ) ) ;
230
+ paths. push ( PathBuf :: from ( env_var ( "HOST_RPATH_DIR" ) ) ) ;
231
+ for p in env:: split_paths ( & env_var ( & ld_lib_path_envvar) ) {
217
232
paths. push ( p. to_path_buf ( ) ) ;
218
233
}
219
234
env:: join_paths ( paths. iter ( ) ) . unwrap ( )
0 commit comments