|
1 | 1 | use std::env; |
2 | | -use std::process::Command; |
| 2 | +use std::ffi::{OsStr, OsString}; |
| 3 | +use std::process::{Command, Output}; |
3 | 4 | use std::str; |
4 | 5 |
|
5 | 6 | // 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() { |
111 | 112 | } |
112 | 113 | } |
113 | 114 |
|
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()); |
124 | 117 | 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 { |
126 | 120 | let mut cmd = Command::new(wrapper); |
127 | 121 | cmd.arg(rustc); |
| 122 | + if is_clippy_driver { |
| 123 | + cmd.arg("--rustc"); |
| 124 | + } |
| 125 | + |
128 | 126 | cmd |
129 | 127 | } else { |
130 | 128 | Command::new(rustc) |
131 | 129 | }; |
132 | 130 |
|
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 | + |
137 | 135 | if !output.status.success() { |
138 | 136 | panic!( |
139 | 137 | "failed to run rustc: {}", |
140 | 138 | String::from_utf8_lossy(output.stderr.as_slice()) |
141 | 139 | ); |
142 | 140 | } |
143 | 141 |
|
| 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 | + |
144 | 161 | let version = otry!(str::from_utf8(&output.stdout).ok()); |
| 162 | + |
145 | 163 | let mut pieces = version.split('.'); |
146 | 164 |
|
147 | 165 | if pieces.next() != Some("rustc 1") { |
|
0 commit comments