Skip to content

Commit

Permalink
[DEBUG] fix libclang version parsing
Browse files Browse the repository at this point in the history
Change-Id: Ie57ea25ae6f62d0349f8e01fe1e5df156f8524d3
  • Loading branch information
ndessart committed Mar 29, 2021
1 parent 0c1e569 commit a11a63c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ctypeslib/codegen/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import packaging.version
import collections.abc as collections_abc
import os
import re
from clang import cindex
from ctypes import byref, c_int
import ctypes
Expand Down Expand Up @@ -281,18 +282,28 @@ def set_include_dir(library_include_dir):

@cindex.CachedProperty
def clang_version(self):
lib = self.lib
try:
lib = self.lib
except cindex.LibclangError:
return None
version = lib.clang_getClangVersion()
version_start = [c.isdigit() for c in version].index(True)
version = version[version_start:]
match = re.search(r"((?:[^:\s]+:([^-\s]*)[^\s]*)|(([^-\s]+)-?(?:[^\s]*)))$", version)
if not match:
return None
version = match.group(2) or match.group(4)
if not version:
return None
version = packaging.version.parse(version)
return version

@cindex.CachedProperty
def include_path(self):
if Config.library_include_dir is not None:
return Config.library_include_dir
version = ".".join(map(str, self.clang_version.release[2:]))
version = self.clang_version
if version is None or version.release is None:
return None
version = ".".join(map(str, version.release[:2]))
path = f"/usr/include/clang/{version}"
if not os.path.exists(path):
return None
Expand Down

0 comments on commit a11a63c

Please sign in to comment.