Skip to content

Commit

Permalink
Retrieve LLVM version from llvm-filecheck binary if it is not set yet
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 18, 2022
1 parent e0f8e60 commit d5fd1af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::Command;

use tracing::*;

Expand Down Expand Up @@ -843,6 +844,20 @@ pub fn extract_llvm_version(version: &str) -> Option<u32> {
Some(version)
}

pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<u32> {
let output = Command::new(binary_path).arg("--version").output().ok()?;
if !output.status.success() {
return None;
}
let version = String::from_utf8(output.stdout).ok()?;
for line in version.lines() {
if let Some(version) = line.split("LLVM version ").skip(1).next() {
return extract_llvm_version(version);
}
}
None
}

/// Takes a directive of the form "<version1> [- <version2>]",
/// returns the numeric representation of <version1> and <version2> as
/// tuple: (<version1> as u32, <version2> as u32)
Expand Down
4 changes: 3 additions & 1 deletion src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x),
};
let llvm_version =
matches.opt_str("llvm-version").as_deref().and_then(header::extract_llvm_version);
matches.opt_str("llvm-version").as_deref().and_then(header::extract_llvm_version).or_else(
|| header::extract_llvm_version_from_binary(&matches.opt_str("llvm-filecheck")?),
);

let src_base = opt_path(matches, "src-base");
let run_ignored = matches.opt_present("ignored");
Expand Down

0 comments on commit d5fd1af

Please sign in to comment.