Skip to content

Commit cc8727e

Browse files
committed
Report which required build-time environment variable is not set
1 parent 2d1d4d1 commit cc8727e

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

src/bootstrap/bin/rustc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ fn main() {
5555
} else {
5656
("RUSTC_REAL", "RUSTC_LIBDIR")
5757
};
58-
let stage = env::var("RUSTC_STAGE").unwrap();
58+
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
5959

60-
let rustc = env::var_os(rustc).unwrap();
61-
let libdir = env::var_os(libdir).unwrap();
60+
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
61+
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
6262
let mut dylib_path = bootstrap::util::dylib_path();
6363
dylib_path.insert(0, PathBuf::from(libdir));
6464

@@ -71,7 +71,7 @@ fn main() {
7171
if let Some(target) = target {
7272
// The stage0 compiler has a special sysroot distinct from what we
7373
// actually downloaded, so we just always pass the `--sysroot` option.
74-
cmd.arg("--sysroot").arg(env::var_os("RUSTC_SYSROOT").unwrap());
74+
cmd.arg("--sysroot").arg(env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"));
7575

7676
// When we build Rust dylibs they're all intended for intermediate
7777
// usage, so make sure we pass the -Cprefer-dynamic flag instead of

src/bootstrap/bin/rustdoc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ use std::path::PathBuf;
2020

2121
fn main() {
2222
let args = env::args_os().skip(1).collect::<Vec<_>>();
23-
let rustdoc = env::var_os("RUSTDOC_REAL").unwrap();
24-
let libdir = env::var_os("RUSTC_LIBDIR").unwrap();
23+
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
24+
let libdir = env::var_os("RUSTC_LIBDIR").expect("RUSTC_LIBDIR was not set");
25+
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
2526

2627
let mut dylib_path = bootstrap::util::dylib_path();
2728
dylib_path.insert(0, PathBuf::from(libdir));
2829

2930
let mut cmd = Command::new(rustdoc);
3031
cmd.args(&args)
31-
.arg("--cfg").arg(format!("stage{}", env::var("RUSTC_STAGE").unwrap()))
32+
.arg("--cfg").arg(format!("stage{}", stage))
3233
.arg("--cfg").arg("dox")
3334
.env(bootstrap::util::dylib_path_var(),
3435
env::join_paths(&dylib_path).unwrap());
@@ -37,4 +38,3 @@ fn main() {
3738
Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e),
3839
})
3940
}
40-

src/liballoc_jemalloc/build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ fn main() {
2222
println!("cargo:rustc-cfg=cargobuild");
2323
println!("cargo:rerun-if-changed=build.rs");
2424

25-
let target = env::var("TARGET").unwrap();
26-
let host = env::var("HOST").unwrap();
25+
let target = env::var("TARGET").expect("TARGET was not set");
26+
let host = env::var("HOST").expect("HOST was not set");
2727
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
2828
let src_dir = env::current_dir().unwrap();
2929

@@ -140,7 +140,7 @@ fn main() {
140140
.current_dir(&build_dir)
141141
.arg("build_lib_static")
142142
.arg("-j")
143-
.arg(env::var("NUM_JOBS").unwrap()));
143+
.arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
144144

145145
if target.contains("windows") {
146146
println!("cargo:rustc-link-lib=static=jemalloc");

src/libcompiler_builtins/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Sources {
7272
}
7373

7474
fn main() {
75-
let target = env::var("TARGET").unwrap();
75+
let target = env::var("TARGET").expect("TARGET was not set");
7676
let cfg = &mut gcc::Config::new();
7777

7878
if target.contains("msvc") {

src/librustc_llvm/build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use build_helper::output;
2020
fn main() {
2121
println!("cargo:rustc-cfg=cargobuild");
2222

23-
let target = env::var("TARGET").unwrap();
23+
let target = env::var("TARGET").expect("TARGET was not set");
2424
let llvm_config = env::var_os("LLVM_CONFIG")
2525
.map(PathBuf::from)
2626
.unwrap_or_else(|| {
@@ -62,8 +62,8 @@ fn main() {
6262
// can't trust all the output of llvm-config becaues it might be targeted
6363
// for the host rather than the target. As a result a bunch of blocks below
6464
// are gated on `if !is_crossed`
65-
let target = env::var("TARGET").unwrap();
66-
let host = env::var("HOST").unwrap();
65+
let target = env::var("TARGET").expect("TARGET was not set");
66+
let host = env::var("HOST").expect("HOST was not set");
6767
let is_crossed = target != host;
6868

6969
let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc", "pnacl", "systemz"];

src/libstd/build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ fn main() {
2323
println!("cargo:rustc-cfg=cargobuild");
2424
println!("cargo:rerun-if-changed=build.rs");
2525

26-
let target = env::var("TARGET").unwrap();
27-
let host = env::var("HOST").unwrap();
26+
let target = env::var("TARGET").expect("TARGET was not set");
27+
let host = env::var("HOST").expect("HOST was not set");
2828
if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") &&
2929
!target.contains("emscripten") {
3030
build_libbacktrace(&host, &target);
@@ -103,5 +103,5 @@ fn build_libbacktrace(host: &str, target: &str) {
103103
run(Command::new("make")
104104
.current_dir(&build_dir)
105105
.arg(format!("INCDIR={}", src_dir.display()))
106-
.arg("-j").arg(env::var("NUM_JOBS").unwrap()));
106+
.arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
107107
}

src/libunwind/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::env;
1313
fn main() {
1414
println!("cargo:rustc-cfg=cargobuild");
1515

16-
let target = env::var("TARGET").unwrap();
16+
let target = env::var("TARGET").expect("TARGET was not set");
1717

1818
if target.contains("linux") {
1919
if target.contains("musl") && !target.contains("mips") {

0 commit comments

Comments
 (0)