diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 6f852275003..0d9a629e179 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -4,6 +4,7 @@ use std::io::prelude::*; use std::io::BufReader; use std::path::{Path, PathBuf}; +use std::process::Command; use tracing::*; @@ -843,6 +844,20 @@ pub fn extract_llvm_version(version: &str) -> Option { Some(version) } +pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option { + 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 " [- ]", /// returns the numeric representation of and as /// tuple: ( as u32, as u32) diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index b48395035d4..417b429161f 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -200,7 +200,9 @@ fn make_absolute(path: PathBuf) -> PathBuf { 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");