Skip to content

Commit

Permalink
Disregard MIRAI's rustc wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 14, 2024
1 parent 6346c4e commit 79670bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ fn main() {
let wrapped_rustc = rustc_wrapper.iter().chain(iter::once(&rustc));

let mut is_clippy_driver = false;
let mut is_mirai = false;
let version = loop {
let mut wrapped_rustc = wrapped_rustc.clone();
let mut command = Command::new(wrapped_rustc.next().unwrap());
command.args(wrapped_rustc);
let mut command;
if is_mirai {
command = Command::new(&rustc);
} else {
let mut wrapped_rustc = wrapped_rustc.clone();
command = Command::new(wrapped_rustc.next().unwrap());
command.args(wrapped_rustc);
}
if is_clippy_driver {
command.arg("--rustc");
}
Expand Down Expand Up @@ -57,7 +63,13 @@ fn main() {
is_clippy_driver = true;
continue;
}
rustc::ParseResult::Unrecognized | rustc::ParseResult::OopsClippy => {
rustc::ParseResult::OopsMirai if !is_mirai && rustc_wrapper.is_some() => {
is_mirai = true;
continue;
}
rustc::ParseResult::Unrecognized
| rustc::ParseResult::OopsClippy
| rustc::ParseResult::OopsMirai => {
eprintln!(
"Error: unexpected output from `rustc --version`: {:?}\n\n\
Please file an issue in https://github.com/dtolnay/rustversion",
Expand Down
2 changes: 2 additions & 0 deletions build/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::{self, Debug};
pub enum ParseResult {
Success(Version),
OopsClippy,
OopsMirai,
Unrecognized,
}

Expand Down Expand Up @@ -36,6 +37,7 @@ pub fn parse(string: &str) -> ParseResult {
match words.next() {
Some("rustc") => {}
Some(word) if word.starts_with("clippy") => return ParseResult::OopsClippy,
Some("mirai") => return ParseResult::OopsMirai,
Some(_) | None => return ParseResult::Unrecognized,
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn test_parse() {
for (string, expected) in cases {
match parse(string) {
ParseResult::Success(version) => assert_eq!(version, *expected),
ParseResult::OopsClippy | ParseResult::Unrecognized => {
ParseResult::OopsClippy | ParseResult::OopsMirai | ParseResult::Unrecognized => {
panic!("unrecognized: {:?}", string);
}
}
Expand Down

0 comments on commit 79670bd

Please sign in to comment.