Skip to content

Commit 0553e37

Browse files
Handle rustc version output correctly when clippy-driver used
1 parent 0e6afd5 commit 0553e37

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

build.rs

Lines changed: 33 additions & 13 deletions
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,56 @@ 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

131+
cmd.arg("--version");
132+
133133
let output = cmd
134-
.arg("--version")
135134
.output()
136135
.expect("Failed to get rustc version");
136+
137137
if !output.status.success() {
138138
panic!(
139139
"failed to run rustc: {}",
140140
String::from_utf8_lossy(output.stderr.as_slice())
141141
);
142142
}
143143

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

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

0 commit comments

Comments
 (0)