From 5907e9155ed7f1312d108aa2110853472da3b029 Mon Sep 17 00:00:00 2001 From: ozkanonur Date: Sun, 20 Nov 2022 02:40:31 +0300 Subject: [PATCH] pass clippy sysroot env if given r=ozkanonur Signed-off-by: ozkanonur --- src/driver.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 51ae27fbb..ee2a3ad20 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -252,6 +252,13 @@ pub fn main() { exit(rustc_driver::catch_with_exit_code(move || { let mut orig_args: Vec = env::args().collect(); + let sys_root_env = std::env::var("SYSROOT").ok(); + let pass_sysroot_env_if_given = |args: &mut Vec, sys_root_env| { + if let Some(sys_root) = sys_root_env { + args.extend(vec!["--sysroot".into(), sys_root]); + }; + }; + // make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc" // for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver // uses @@ -259,7 +266,10 @@ pub fn main() { orig_args.remove(pos); orig_args[0] = "rustc".to_string(); - return rustc_driver::RunCompiler::new(&orig_args, &mut DefaultCallbacks).run(); + let mut args: Vec = orig_args.clone(); + pass_sysroot_env_if_given(&mut args, sys_root_env); + + return rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); } if orig_args.iter().any(|a| a == "--version" || a == "-V") { @@ -282,6 +292,9 @@ pub fn main() { exit(0); } + let mut args: Vec = orig_args.clone(); + pass_sysroot_env_if_given(&mut args, sys_root_env); + let mut no_deps = false; let clippy_args_var = env::var("CLIPPY_ARGS").ok(); let clippy_args = clippy_args_var @@ -310,11 +323,10 @@ pub fn main() { let clippy_enabled = !cap_lints_allow && (!no_deps || in_primary_package); if clippy_enabled { - let mut args: Vec = orig_args.clone(); args.extend(clippy_args); rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }).run() } else { - rustc_driver::RunCompiler::new(&orig_args, &mut RustcCallbacks { clippy_args_var }).run() + rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }).run() } })) }