diff options
| author | Jeremy Fitzhardinge <jsgf@fb.com> | 2019-01-15 11:39:23 -0800 |
|---|---|---|
| committer | Jeremy Fitzhardinge <jeremy@goop.org> | 2019-02-02 11:43:21 -0800 |
| commit | 71d03ae29b175c5e99f4e978e90bab830cfbd530 (patch) | |
| tree | 5d993485309664ff1e5be03a05ea725ca7d22c83 | |
| parent | b5fd0108b3a6b8a9626645ac174cf653de576135 (diff) | |
| download | rust-71d03ae29b175c5e99f4e978e90bab830cfbd530.tar.gz rust-71d03ae29b175c5e99f4e978e90bab830cfbd530.zip | |
clippy-driver: if --sysroot is specified on the command line, use that
If the user explicitly sets sysroot on the command line, then use that value. Issue #3663
| -rw-r--r-- | src/driver.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/driver.rs b/src/driver.rs index d290e403a31..fbff693f887 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -72,8 +72,19 @@ pub fn main() { exit(0); } - let sys_root = option_env!("SYSROOT") - .map(String::from) + let mut orig_args: Vec<String> = env::args().collect(); + + // Get the sysroot, looking from most specific to this invocation to the least: + // - command line + // - runtime environment + // - SYSROOT + // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN + // - sysroot from rustc in the path + // - compile-time environment + let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true); + let have_sys_root_arg = sys_root_arg.is_some(); + let sys_root = sys_root_arg + .map(|s| s.to_string()) .or_else(|| std::env::var("SYSROOT").ok()) .or_else(|| { let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); @@ -89,11 +100,11 @@ pub fn main() { .and_then(|out| String::from_utf8(out.stdout).ok()) .map(|s| s.trim().to_owned()) }) + .or_else(|| option_env!("SYSROOT").map(String::from)) .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. // We're invoking the compiler programmatically, so we ignore this/ - let mut orig_args: Vec<String> = env::args().collect(); if orig_args.len() <= 1 { std::process::exit(1); } @@ -104,7 +115,7 @@ pub fn main() { // this conditional check for the --sysroot flag is there so users can call // `clippy_driver` directly // without having to pass --sysroot or anything - let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") { + let mut args: Vec<String> = if have_sys_root_arg { orig_args.clone() } else { orig_args |
