Skip to content

Commit

Permalink
Merge pull request #54 from dtolnay/mirai
Browse files Browse the repository at this point in the history
Disregard MIRAI's rustc wrapper
  • Loading branch information
dtolnay authored Oct 14, 2024
2 parents 6346c4e + 79670bd commit 837b529
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 837b529

Please sign in to comment.