Skip to content

Commit 237f3e7

Browse files
authored
Merge pull request #3893 from nathaniel-bennett/clippy-rustc-wrapper
Handle version output correctly when `clippy-driver` used
2 parents 0e6afd5 + 18b8da9 commit 237f3e7

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

build.rs

+34-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env;
2-
use std::process::Command;
2+
use std::ffi::{OsStr, OsString};
3+
use std::process::{Command, Output};
34
use std::str;
45

56
// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
@@ -111,37 +112,54 @@ fn main() {
111112
}
112113
}
113114

114-
fn rustc_minor_nightly() -> (u32, bool) {
115-
macro_rules! otry {
116-
($e:expr) => {
117-
match $e {
118-
Some(e) => e,
119-
None => panic!("Failed to get rustc version"),
120-
}
121-
};
122-
}
123-
115+
fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
116+
let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty());
124117
let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env");
125-
let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()) {
118+
119+
let mut cmd = if let Some(wrapper) = rustc_wrapper {
126120
let mut cmd = Command::new(wrapper);
127121
cmd.arg(rustc);
122+
if is_clippy_driver {
123+
cmd.arg("--rustc");
124+
}
125+
128126
cmd
129127
} else {
130128
Command::new(rustc)
131129
};
132130

133-
let output = cmd
134-
.arg("--version")
135-
.output()
136-
.expect("Failed to get rustc version");
131+
cmd.arg("--version");
132+
133+
let output = cmd.output().expect("Failed to get rustc version");
134+
137135
if !output.status.success() {
138136
panic!(
139137
"failed to run rustc: {}",
140138
String::from_utf8_lossy(output.stderr.as_slice())
141139
);
142140
}
143141

142+
output
143+
}
144+
145+
fn rustc_minor_nightly() -> (u32, bool) {
146+
macro_rules! otry {
147+
($e:expr) => {
148+
match $e {
149+
Some(e) => e,
150+
None => panic!("Failed to get rustc version"),
151+
}
152+
};
153+
}
154+
155+
let mut output = rustc_version_cmd(false);
156+
157+
if otry!(str::from_utf8(&output.stdout).ok()).starts_with("clippy") {
158+
output = rustc_version_cmd(true);
159+
}
160+
144161
let version = otry!(str::from_utf8(&output.stdout).ok());
162+
145163
let mut pieces = version.split('.');
146164

147165
if pieces.next() != Some("rustc 1") {

0 commit comments

Comments
 (0)