Skip to content

pass clippy sysroot env if given #104619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/tools/clippy/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,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 @@ -247,6 +257,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 @@ -275,11 +288,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()
}
}))
}