about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-10-18 21:18:48 +0200
committerGitHub <noreply@github.com>2022-10-18 21:18:48 +0200
commit4012538cf607780d4021f73f69c6b8ed40f36904 (patch)
tree9c4c7e4bb624aa2f57a53b0bcb083b9672044b20
parentaaee73765026b8e39a6843f2bb2deea2e1cd6d91 (diff)
parentd5fd1af7b43b4932eebfc26cfd1a35ce7951be60 (diff)
downloadrust-4012538cf607780d4021f73f69c6b8ed40f36904.tar.gz
rust-4012538cf607780d4021f73f69c6b8ed40f36904.zip
Rollup merge of #103203 - GuillaumeGomez:fix-llvm-runtools-condition, r=Amanieu
Retrieve LLVM version from llvm-filecheck binary if it is not set yet

In `rustc_codegen_gcc`, we run the `ASM` test suite. The problem is that, if a too recent version of the `llvm-filecheck` binary is provided, an extra argument needs to be passed and the to detect this version, it currently only expects a `--llvm-version` argument. With this, the version can be determined directly from the `llvm-filecheck` binary.

r? ``@Amanieu``
-rw-r--r--src/tools/compiletest/src/header.rs15
-rw-r--r--src/tools/compiletest/src/main.rs4
2 files changed, 18 insertions, 1 deletions
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::fs::File;
 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<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)
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 @@ 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");