Skip to content

Commit e92dcf2

Browse files
hlopkoemilio
authored andcommitted
Make clang version parsing logic more robust
Previously the function assumed that the version number appeared in the third word. This PR adds a heuristic - take the first word that starts with a number. This way we can also parse: `debian clang version 11.0` that my clang reports.
1 parent b1c4178 commit e92dcf2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2444,10 +2444,12 @@ pub struct ClangVersion {
24442444
pub fn clang_version() -> ClangVersion {
24452445
ensure_libclang_is_loaded();
24462446

2447+
//Debian clang version 11.0.1-2
24472448
let raw_v: String = clang::extract_clang_version();
24482449
let split_v: Option<Vec<&str>> = raw_v
24492450
.split_whitespace()
2450-
.nth(2)
2451+
.filter(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit()))
2452+
.next()
24512453
.map(|v| v.split('.').collect());
24522454
match split_v {
24532455
Some(v) => {

0 commit comments

Comments
 (0)