Skip to content

Commit

Permalink
Fix detection of clang version and v14+ unit tests (#1878)
Browse files Browse the repository at this point in the history
* Fix detection of clang version and v14+ unit tests

Compiler version (__VERSION__) is always enclosed in quotes.
This only fixes version detection for clang to keep the scope small.
Stripping quotes could also be done globally in compiler.rs.
  • Loading branch information
grembo authored Sep 5, 2023
1 parent 1ab4cff commit 378c937
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
34 changes: 33 additions & 1 deletion src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Clang {
None => return false,
};

let parsed_version = match Version::parse(version_str) {
let parsed_version = match Version::parse(version_str.trim_end_matches('"')) {
Ok(parsed_version) => parsed_version,
Err(e) => return false,
};
Expand Down Expand Up @@ -252,6 +252,38 @@ mod test {
}
}

#[test]
fn test_is_minversion() {
assert!(Clang {
clangplusplus: false,
is_appleclang: false,
version: Some("\"Ubuntu Clang 14.0.0\"".to_string()),
}
.is_minversion(14));
assert!(!Clang {
clangplusplus: false,
is_appleclang: false,
version: Some("\"Ubuntu Clang 13.0.0\"".to_string()),
}
.is_minversion(14));
assert!(Clang {
clangplusplus: false,
is_appleclang: false,
version: Some("\"FreeBSD Clang 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)\"".to_string()),
}.is_minversion(14));
assert!(!Clang {
clangplusplus: false,
is_appleclang: false,
version: Some("\"FreeBSD Clang 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)\"".to_string()),
}.is_minversion(14));

assert!(!Clang {
clangplusplus: false,
is_appleclang: true,
version: Some("\"FreeBSD Clang 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)\"".to_string()),
}.is_minversion(14)); // is_appleclang wins
}

#[test]
fn test_parse_arguments_simple() {
let a = parses!("-c", "foo.c", "-o", "foo.o");
Expand Down
6 changes: 3 additions & 3 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path) {
}

// If we are testing with clang-14 or later, we expect the -fminimize-whitespace flag to be used.
if compiler.name == "clang" {
let version_cmd = Command::new(compiler.name)
if compiler.name == "clang" || compiler.name == "clang++" {
let version_cmd = Command::new(compiler.exe.clone())
.arg("--version")
.output()
.expect("Failure when getting compiler version");
Expand All @@ -432,7 +432,7 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path) {
let (major, is_appleclang) = match re.captures(version_output) {
Some(c) => (
c.name("major").unwrap().as_str().parse::<usize>().unwrap(),
c.name("apple").is_none(),
c.name("apple").is_some(),
),
None => panic!(
"Version info not found in --version output: {}",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clang_multicall.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <iostream>

// this is c++ code, but the extension is .c,
// so clang doesn't change it's behavior because of the extension
// so clang doesn't change its behavior because of the extension

int main() {
std::cout << "Hello, world!" << std::endl;
Expand Down

0 comments on commit 378c937

Please sign in to comment.