Skip to content

Commit a4f57b0

Browse files
committed
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
1 parent ceb67af commit a4f57b0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/driver.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ pub fn main() {
7171
exit(0);
7272
}
7373

74-
let sys_root = option_env!("SYSROOT")
75-
.map(String::from)
74+
let mut orig_args: Vec<String> = env::args().collect();
75+
76+
// Get the sysroot, looking from most specific to this invocation to the least:
77+
// - command line
78+
// - runtime environment
79+
// - SYSROOT
80+
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
81+
// - sysroot from rustc in the path
82+
// - compile-time environment
83+
let sys_root = arg_value(&orig_args, "--sysroot", |_| true)
84+
.map(|s| s.to_string())
7685
.or_else(|| std::env::var("SYSROOT").ok())
7786
.or_else(|| {
7887
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
@@ -88,11 +97,11 @@ pub fn main() {
8897
.and_then(|out| String::from_utf8(out.stdout).ok())
8998
.map(|s| s.trim().to_owned())
9099
})
100+
.or_else(|| option_env!("SYSROOT").map(String::from))
91101
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
92102

93103
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
94104
// We're invoking the compiler programmatically, so we ignore this/
95-
let mut orig_args: Vec<String> = env::args().collect();
96105
if orig_args.len() <= 1 {
97106
std::process::exit(1);
98107
}

0 commit comments

Comments
 (0)