Skip to content

Commit 18e031a

Browse files
authored
Merge pull request #1327 from oli-obk/master
--sysroot isn't necessary anymore for the outer cargo clippy call
2 parents ea1d432 + 6a73c8f commit 18e031a

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/main.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,6 @@ pub fn main() {
149149

150150
let dep_path = env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps");
151151

152-
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
153-
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
154-
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
155-
format!("{}/toolchains/{}", home, toolchain)
156-
} else {
157-
option_env!("SYSROOT")
158-
.map(|s| s.to_owned())
159-
.or(Command::new("rustc")
160-
.arg("--print")
161-
.arg("sysroot")
162-
.output()
163-
.ok()
164-
.and_then(|out| String::from_utf8(out.stdout).ok())
165-
.map(|s| s.trim().to_owned()))
166-
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust")
167-
};
168-
169152
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
170153
// this arm is executed on the initial call to `cargo clippy`
171154

@@ -201,11 +184,11 @@ pub fn main() {
201184
let args = std::env::args().skip(2);
202185
if let Some(first) = target.kind.get(0) {
203186
if target.kind.len() > 1 || first.ends_with("lib") {
204-
if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root) {
187+
if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args), &dep_path) {
205188
std::process::exit(code);
206189
}
207190
} else if ["bin", "example", "test", "bench"].contains(&&**first) {
208-
if let Err(code) = process(vec![format!("--{}", first), target.name].into_iter().chain(args), &dep_path, &sys_root) {
191+
if let Err(code) = process(vec![format!("--{}", first), target.name].into_iter().chain(args), &dep_path) {
209192
std::process::exit(code);
210193
}
211194
}
@@ -216,6 +199,23 @@ pub fn main() {
216199
} else {
217200
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC` env var set to itself
218201

202+
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
203+
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
204+
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
205+
format!("{}/toolchains/{}", home, toolchain)
206+
} else {
207+
option_env!("SYSROOT")
208+
.map(|s| s.to_owned())
209+
.or(Command::new("rustc")
210+
.arg("--print")
211+
.arg("sysroot")
212+
.output()
213+
.ok()
214+
.and_then(|out| String::from_utf8(out.stdout).ok())
215+
.map(|s| s.trim().to_owned()))
216+
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust")
217+
};
218+
219219
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
220220
// without having to pass --sysroot or anything
221221
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
@@ -239,7 +239,7 @@ pub fn main() {
239239
}
240240
}
241241

242-
fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
242+
fn process<P, I>(old_args: I, dep_path: P) -> Result<(), i32>
243243
where P: AsRef<Path>,
244244
I: Iterator<Item = String>
245245
{
@@ -256,8 +256,6 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
256256
}
257257
args.push("-L".to_owned());
258258
args.push(dep_path.as_ref().to_string_lossy().into_owned());
259-
args.push(String::from("--sysroot"));
260-
args.push(sysroot.to_owned());
261259
args.push("-Zno-trans".to_owned());
262260
args.push("--cfg".to_owned());
263261
args.push(r#"feature="cargo-clippy""#.to_owned());

0 commit comments

Comments
 (0)