Lines 31-84
Link Here
|
31 |
exit(0); |
31 |
exit(0); |
32 |
} |
32 |
} |
33 |
|
33 |
|
34 |
let sys_root = option_env!("SYSROOT") |
|
|
35 |
.map(String::from) |
36 |
.or_else(|| std::env::var("SYSROOT").ok()) |
37 |
.or_else(|| { |
38 |
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); |
39 |
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); |
40 |
home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain))) |
41 |
}) |
42 |
.or_else(|| { |
43 |
Command::new("rustc") |
44 |
.arg("--print") |
45 |
.arg("sysroot") |
46 |
.output() |
47 |
.ok() |
48 |
.and_then(|out| String::from_utf8(out.stdout).ok()) |
49 |
.map(|s| s.trim().to_owned()) |
50 |
}) |
51 |
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); |
52 |
|
53 |
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. |
34 |
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. |
54 |
// We're invoking the compiler programmatically, so we ignore this/ |
35 |
// We're invoking the compiler programmatically, so we ignore this/ |
55 |
let mut orig_args: Vec<String> = env::args().collect(); |
36 |
let mut args: Vec<String> = env::args().collect(); |
56 |
if orig_args.len() <= 1 { |
37 |
if args.len() <= 1 { |
57 |
std::process::exit(1); |
38 |
std::process::exit(1); |
58 |
} |
39 |
} |
59 |
if Path::new(&orig_args[1]).file_stem() == Some("rustc".as_ref()) { |
40 |
if Path::new(&args[1]).file_stem() == Some("rustc".as_ref()) { |
60 |
// we still want to be able to invoke it normally though |
41 |
// we still want to be able to invoke it normally though |
61 |
orig_args.remove(1); |
42 |
args.remove(1); |
62 |
} |
43 |
} |
63 |
// this conditional check for the --sysroot flag is there so users can call |
|
|
64 |
// `clippy_driver` directly |
65 |
// without having to pass --sysroot or anything |
66 |
let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") { |
67 |
orig_args.clone() |
68 |
} else { |
69 |
orig_args |
70 |
.clone() |
71 |
.into_iter() |
72 |
.chain(Some("--sysroot".to_owned())) |
73 |
.chain(Some(sys_root)) |
74 |
.collect() |
75 |
}; |
76 |
|
44 |
|
77 |
// this check ensures that dependencies are built but not linted and the final |
45 |
// this check ensures that dependencies are built but not linted and the final |
78 |
// crate is |
46 |
// crate is |
79 |
// linted but not built |
47 |
// linted but not built |
80 |
let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true") |
48 |
let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true") |
81 |
|| orig_args.iter().any(|s| s == "--emit=dep-info,metadata"); |
49 |
|| args.iter().any(|s| s == "--emit=dep-info,metadata"); |
82 |
|
50 |
|
83 |
if clippy_enabled { |
51 |
if clippy_enabled { |
84 |
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); |
52 |
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); |