|
1 | 1 | use std::env;
|
2 |
| -use std::process::Command; |
| 2 | +use std::process::{Command, Output}; |
3 | 3 | use std::str;
|
4 | 4 |
|
5 | 5 | // List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
|
@@ -194,39 +194,59 @@ fn main() {
|
194 | 194 | }
|
195 | 195 | }
|
196 | 196 |
|
197 |
| -fn rustc_minor_nightly() -> (u32, bool) { |
198 |
| - macro_rules! otry { |
199 |
| - ($e:expr) => { |
200 |
| - match $e { |
201 |
| - Some(e) => e, |
202 |
| - None => panic!("Failed to get rustc version"), |
203 |
| - } |
204 |
| - }; |
205 |
| - } |
206 |
| - |
| 197 | +/// Run `rustc --version` and capture the output, adjusting arguments as needed if `clippy-driver` |
| 198 | +/// is used instead. |
| 199 | +fn rustc_version_cmd(is_clippy_driver: bool) -> Output { |
| 200 | + let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()); |
207 | 201 | let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env");
|
208 |
| - let mut cmd = match env::var_os("RUSTC_WRAPPER").as_ref() { |
209 |
| - Some(wrapper) if !wrapper.is_empty() => { |
| 202 | + |
| 203 | + let mut cmd = match rustc_wrapper { |
| 204 | + Some(wrapper) => { |
210 | 205 | let mut cmd = Command::new(wrapper);
|
211 | 206 | cmd.arg(rustc);
|
| 207 | + if is_clippy_driver { |
| 208 | + cmd.arg("--rustc"); |
| 209 | + } |
| 210 | + |
212 | 211 | cmd
|
213 | 212 | }
|
214 |
| - _ => Command::new(rustc), |
| 213 | + None => Command::new(rustc), |
215 | 214 | };
|
216 | 215 |
|
217 |
| - let output = cmd |
218 |
| - .arg("--version") |
219 |
| - .output() |
220 |
| - .ok() |
221 |
| - .expect("Failed to get rustc version"); |
| 216 | + cmd.arg("--version"); |
| 217 | + |
| 218 | + let output = cmd.output().ok().expect("Failed to get rustc version"); |
| 219 | + |
222 | 220 | if !output.status.success() {
|
223 | 221 | panic!(
|
224 | 222 | "failed to run rustc: {}",
|
225 | 223 | String::from_utf8_lossy(output.stderr.as_slice())
|
226 | 224 | );
|
227 | 225 | }
|
228 | 226 |
|
| 227 | + output |
| 228 | +} |
| 229 | + |
| 230 | +/// Return the minor version of `rustc`, as well as a bool indicating whether or not the version |
| 231 | +/// is a nightly. |
| 232 | +fn rustc_minor_nightly() -> (u32, bool) { |
| 233 | + macro_rules! otry { |
| 234 | + ($e:expr) => { |
| 235 | + match $e { |
| 236 | + Some(e) => e, |
| 237 | + None => panic!("Failed to get rustc version"), |
| 238 | + } |
| 239 | + }; |
| 240 | + } |
| 241 | + |
| 242 | + let mut output = rustc_version_cmd(false); |
| 243 | + |
| 244 | + if otry!(str::from_utf8(&output.stdout).ok()).starts_with("clippy") { |
| 245 | + output = rustc_version_cmd(true); |
| 246 | + } |
| 247 | + |
229 | 248 | let version = otry!(str::from_utf8(&output.stdout).ok());
|
| 249 | + |
230 | 250 | let mut pieces = version.split('.');
|
231 | 251 |
|
232 | 252 | if pieces.next() != Some("rustc 1") {
|
|
0 commit comments