Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detection of clang version and v14+ unit tests #1878

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

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
Loading