Skip to content

Commit 5907e91

Browse files
onur-ozkanflip1995
authored andcommitted
pass clippy sysroot env if given r=ozkanonur
Signed-off-by: ozkanonur <[email protected]>
1 parent 661f13c commit 5907e91

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/driver.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,24 @@ pub fn main() {
252252
exit(rustc_driver::catch_with_exit_code(move || {
253253
let mut orig_args: Vec<String> = env::args().collect();
254254

255+
let sys_root_env = std::env::var("SYSROOT").ok();
256+
let pass_sysroot_env_if_given = |args: &mut Vec<String>, sys_root_env| {
257+
if let Some(sys_root) = sys_root_env {
258+
args.extend(vec!["--sysroot".into(), sys_root]);
259+
};
260+
};
261+
255262
// make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc"
256263
// for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver
257264
// uses
258265
if let Some(pos) = orig_args.iter().position(|arg| arg == "--rustc") {
259266
orig_args.remove(pos);
260267
orig_args[0] = "rustc".to_string();
261268

262-
return rustc_driver::RunCompiler::new(&orig_args, &mut DefaultCallbacks).run();
269+
let mut args: Vec<String> = orig_args.clone();
270+
pass_sysroot_env_if_given(&mut args, sys_root_env);
271+
272+
return rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run();
263273
}
264274

265275
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
@@ -282,6 +292,9 @@ pub fn main() {
282292
exit(0);
283293
}
284294

295+
let mut args: Vec<String> = orig_args.clone();
296+
pass_sysroot_env_if_given(&mut args, sys_root_env);
297+
285298
let mut no_deps = false;
286299
let clippy_args_var = env::var("CLIPPY_ARGS").ok();
287300
let clippy_args = clippy_args_var
@@ -310,11 +323,10 @@ pub fn main() {
310323

311324
let clippy_enabled = !cap_lints_allow && (!no_deps || in_primary_package);
312325
if clippy_enabled {
313-
let mut args: Vec<String> = orig_args.clone();
314326
args.extend(clippy_args);
315327
rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }).run()
316328
} else {
317-
rustc_driver::RunCompiler::new(&orig_args, &mut RustcCallbacks { clippy_args_var }).run()
329+
rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }).run()
318330
}
319331
}))
320332
}

0 commit comments

Comments
 (0)