Skip to content

Commit

Permalink
pass clippy sysroot env if given r=ozkanonur
Browse files Browse the repository at this point in the history
Signed-off-by: ozkanonur <work@onurozkan.dev>
  • Loading branch information
onur-ozkan authored and flip1995 committed Nov 21, 2022
1 parent 661f13c commit 5907e91
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,24 @@ pub fn main() {
exit(rustc_driver::catch_with_exit_code(move || {
let mut orig_args: Vec<String> = env::args().collect();

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]);
};
};

// 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
if let Some(pos) = orig_args.iter().position(|arg| arg == "--rustc") {
orig_args.remove(pos);
orig_args[0] = "rustc".to_string();

return rustc_driver::RunCompiler::new(&orig_args, &mut DefaultCallbacks).run();
let mut args: Vec<String> = 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") {
Expand All @@ -282,6 +292,9 @@ pub fn main() {
exit(0);
}

let mut args: Vec<String> = 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
Expand Down Expand Up @@ -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<String> = 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()
}
}))
}

0 comments on commit 5907e91

Please sign in to comment.