summary refs log tree commit diff
path: root/src/bootstrap/bin/_helper.rs
blob: 09aa471dba4453af9666d0b6df4d42cc0a82a91d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// Parses the value of the "RUSTC_VERBOSE" environment variable and returns it as a `usize`.
/// If it was not defined, returns 0 by default.
///
/// Panics if "RUSTC_VERBOSE" is defined with the value that is not an unsigned integer.
fn parse_rustc_verbose() -> usize {
    use std::str::FromStr;

    match std::env::var("RUSTC_VERBOSE") {
        Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
        Err(_) => 0,
    }
}

/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
///
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
fn parse_rustc_stage() -> String {
    std::env::var("RUSTC_STAGE").unwrap_or_else(|_| {
        // Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
        eprintln!("rustc shim: fatal: RUSTC_STAGE was not set");
        eprintln!("rustc shim: note: use `x.py build -vvv` to see all environment variables set by bootstrap");
        exit(101);
    })
}