about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJoshua Nelson <github@jyn.dev>2023-01-03 18:04:28 +0000
committerPhilipp Krones <hello@philkrones.com>2023-01-12 18:32:47 +0100
commit321c530fadb766c594698be7c83ab7cbc443bf1c (patch)
tree2eca63c107f0fdd2af615012c9c5f23fbca91ff6 /src
parentdecaba97cc0e682a7b44b3f06f10ad1a8ebe9cba (diff)
Don't pass `--sysroot` twice if SYSROOT is set
This is useful for rust-lang/rust to allow setting a sysroot that's
*only* for build scripts, different from the regular sysroot passed in
RUSTFLAGS (since cargo doesn't apply RUSTFLAGS to build scripts or
proc-macros).

That said, the exact motivation is not particularly important: this
fixes a regression from
https://github.com/rust-lang/rust-clippy/pull/9881/commits/5907e9155ed7f1312d108aa2110853472da3b029#r1060215684.

Note that only RUSTFLAGS is tested in the new integration test; passing
--sysroot through `clippy-driver` never worked as far as I can tell, and
no one is using it, so I didn't fix it here.
Diffstat (limited to 'src')
-rw-r--r--src/driver.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/driver.rs b/src/driver.rs
index bcc096c570e..d521e8d8839 100644
--- a/src/driver.rs
+++ b/src/driver.rs
@@ -256,11 +256,14 @@ pub fn main() {
     LazyLock::force(&ICE_HOOK);
     exit(rustc_driver::catch_with_exit_code(move || {
         let mut orig_args: Vec<String> = env::args().collect();
+        let has_sysroot_arg = arg_value(&orig_args, "--sysroot", |_| true).is_some();
 
         let sys_root_env = std::env::var("SYSROOT").ok();
         let pass_sysroot_env_if_given = |args: &mut Vec<String>, sys_root_env| {
             if let Some(sys_root) = sys_root_env {
-                args.extend(vec!["--sysroot".into(), sys_root]);
+                if !has_sysroot_arg {
+                    args.extend(vec!["--sysroot".into(), sys_root]);
+                }
             };
         };