Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle version output correctly when clippy-driver used #3893

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::process::Command;
use std::ffi::{OsStr, OsString};
use std::process::{Command, Output};
use std::str;

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

fn rustc_minor_nightly() -> (u32, bool) {
macro_rules! otry {
($e:expr) => {
match $e {
Some(e) => e,
None => panic!("Failed to get rustc version"),
}
};
}

fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty());
let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env");
let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()) {

let mut cmd = if let Some(wrapper) = rustc_wrapper {
let mut cmd = Command::new(wrapper);
cmd.arg(rustc);
if is_clippy_driver {
cmd.arg("--rustc");
}

cmd
} else {
Command::new(rustc)
};

let output = cmd
.arg("--version")
.output()
.expect("Failed to get rustc version");
cmd.arg("--version");

let output = cmd.output().expect("Failed to get rustc version");

if !output.status.success() {
panic!(
"failed to run rustc: {}",
String::from_utf8_lossy(output.stderr.as_slice())
);
}

output
}

fn rustc_minor_nightly() -> (u32, bool) {
macro_rules! otry {
($e:expr) => {
match $e {
Some(e) => e,
None => panic!("Failed to get rustc version"),
}
};
}

let mut output = rustc_version_cmd(false);

if otry!(str::from_utf8(&output.stdout).ok()).starts_with("clippy") {
output = rustc_version_cmd(true);
}

let version = otry!(str::from_utf8(&output.stdout).ok());

let mut pieces = version.split('.');

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