Continue looping if candidate cxx isn't found in verify_fips_clang_version

A basic LLVM 12 build provides clang-12 but not clang++-12, but
it does provide both clang and clang++, so we shouldn't hard fail
when first checking for clang-12 and clang++-12.
This commit is contained in:
Anthony Ramine 2023-10-16 10:29:38 +02:00 committed by Alessandro Ghedini
parent 1ca7f76607
commit d8c2122c73
1 changed files with 9 additions and 6 deletions

View File

@ -295,20 +295,20 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
/// See "Installation Instructions" under section 12.1. /// See "Installation Instructions" under section 12.1.
// TODO: maybe this should also verify the Go and Ninja versions? But those haven't been an issue in practice ... // TODO: maybe this should also verify the Go and Ninja versions? But those haven't been an issue in practice ...
fn verify_fips_clang_version() -> (&'static str, &'static str) { fn verify_fips_clang_version() -> (&'static str, &'static str) {
fn version(tool: &str) -> String { fn version(tool: &str) -> Option<String> {
let output = match Command::new(tool).arg("--version").output() { let output = match Command::new(tool).arg("--version").output() {
Ok(o) => o, Ok(o) => o,
Err(e) => { Err(e) => {
eprintln!("warning: missing {}, trying other compilers: {}", tool, e); eprintln!("warning: missing {}, trying other compilers: {}", tool, e);
// NOTE: hard-codes that the loop below checks the version // NOTE: hard-codes that the loop below checks the version
return String::new(); return None;
} }
}; };
if !output.status.success() { if !output.status.success() {
return String::new(); return Some(String::new());
} }
let output = std::str::from_utf8(&output.stdout).expect("invalid utf8 output"); let output = std::str::from_utf8(&output.stdout).expect("invalid utf8 output");
output.lines().next().expect("empty output").to_string() Some(output.lines().next().expect("empty output").to_string())
} }
const REQUIRED_CLANG_VERSION: &str = "12.0.0"; const REQUIRED_CLANG_VERSION: &str = "12.0.0";
@ -317,10 +317,13 @@ fn verify_fips_clang_version() -> (&'static str, &'static str) {
("clang", "clang++"), ("clang", "clang++"),
("cc", "c++"), ("cc", "c++"),
] { ] {
let cc_version = version(cc); let (Some(cc_version), Some(cxx_version)) = (version(cc), version(cxx)) else {
continue;
};
if cc_version.contains(REQUIRED_CLANG_VERSION) { if cc_version.contains(REQUIRED_CLANG_VERSION) {
assert!( assert!(
version(cxx).contains(REQUIRED_CLANG_VERSION), cxx_version.contains(REQUIRED_CLANG_VERSION),
"mismatched versions of cc and c++" "mismatched versions of cc and c++"
); );
return (cc, cxx); return (cc, cxx);