Skip to content

Commit

Permalink
Use --version --verbose to get rustc version out of clippy-driver
Browse files Browse the repository at this point in the history
Fixes issue dtolnay#13
  • Loading branch information
jsgf committed Feb 12, 2020
1 parent b1f7dcc commit 4e85e2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ use std::process::{self, Command};

fn main() {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));
let output = match Command::new(&rustc).arg("--version").output() {
let output = match Command::new(&rustc)
.args(&["--version", "--verbose"])
.output()
{
Ok(output) => output,
Err(e) => {
let rustc = rustc.to_string_lossy();
eprintln!("Error: failed to run `{} --version`: {}", rustc, e);
eprintln!(
"Error: failed to run `{} --version --verbose`: {}",
rustc, e
);
process::exit(1);
}
};
Expand Down
6 changes: 4 additions & 2 deletions build/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ pub struct Date {
}

pub fn parse(string: &str) -> Option<Version> {
let last_line = string.lines().last().unwrap_or(&string);
let mut words = last_line.trim().split(' ');
let rustc_line = string
.lines()
.find(|l| l.trim_start().starts_with("rustc "))?;
let mut words = rustc_line.trim().split(' ');

if words.next()? != "rustc" {
return None;
Expand Down
8 changes: 7 additions & 1 deletion tests/test_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ fn test_parse() {
];

for (string, expected) in cases {
assert_eq!(parse(string).unwrap(), *expected);
assert_eq!(
parse(string).as_ref(),
Some(expected),
"string {} expected {:#?}",
string,
expected
);
}
}

0 comments on commit 4e85e2d

Please sign in to comment.