From 698715bf61f57f789cffe8c5a199966be05b7355 Mon Sep 17 00:00:00 2001 From: Tao He Date: Sun, 17 Mar 2024 21:20:44 +0800 Subject: [PATCH] Upgrade llvm version to v18.1.1. Signed-off-by: Tao He --- .cirrus.yml | 2 +- .github/workflows/libclang-alpine-amd64.yml | 2 +- .github/workflows/libclang-linux-aarch64.yml | 2 +- .github/workflows/libclang-linux-amd64.yml | 2 +- .github/workflows/libclang-linux-arm.yml | 2 +- .github/workflows/libclang-macosx-amd64.yml | 2 +- .github/workflows/libclang-macosx-arm64.yml | 4 +- .../workflows/libclang-windows-aarch64.yml | 2 +- .github/workflows/libclang-windows-amd64.yml | 2 +- docs/conf.py | 4 +- docs/index.rst | 2 +- python/clang/cindex.py | 175 ++++++++---------- scripts/data/clang_bindings.patch | 16 +- scripts/update_python_clang_bindings.sh | 2 +- setup.py | 2 +- setup_ext.py | 2 +- 16 files changed, 100 insertions(+), 123 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index c791bd6..e835333 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -3,7 +3,7 @@ macos_instance: env: MACOSX_DEPLOYMENT_TARGET: "10.15" - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 task: checkout_script: diff --git a/.github/workflows/libclang-alpine-amd64.yml b/.github/workflows/libclang-alpine-amd64.yml index dd98852..8a48f58 100644 --- a/.github/workflows/libclang-alpine-amd64.yml +++ b/.github/workflows/libclang-alpine-amd64.yml @@ -3,7 +3,7 @@ name: libclang-alpine-amd64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/.github/workflows/libclang-linux-aarch64.yml b/.github/workflows/libclang-linux-aarch64.yml index 573e20e..f7d3de8 100644 --- a/.github/workflows/libclang-linux-aarch64.yml +++ b/.github/workflows/libclang-linux-aarch64.yml @@ -3,7 +3,7 @@ name: libclang-linux-aarch64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/.github/workflows/libclang-linux-amd64.yml b/.github/workflows/libclang-linux-amd64.yml index 5c32a9a..dc63188 100644 --- a/.github/workflows/libclang-linux-amd64.yml +++ b/.github/workflows/libclang-linux-amd64.yml @@ -3,7 +3,7 @@ name: libclang-linux-amd64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/.github/workflows/libclang-linux-arm.yml b/.github/workflows/libclang-linux-arm.yml index 62dd9bd..7fc332e 100644 --- a/.github/workflows/libclang-linux-arm.yml +++ b/.github/workflows/libclang-linux-arm.yml @@ -3,7 +3,7 @@ name: libclang-linux-arm on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/.github/workflows/libclang-macosx-amd64.yml b/.github/workflows/libclang-macosx-amd64.yml index 45a9834..28c931d 100644 --- a/.github/workflows/libclang-macosx-amd64.yml +++ b/.github/workflows/libclang-macosx-amd64.yml @@ -3,7 +3,7 @@ name: libclang-macosx-amd64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/.github/workflows/libclang-macosx-arm64.yml b/.github/workflows/libclang-macosx-arm64.yml index 39136ab..62d946c 100644 --- a/.github/workflows/libclang-macosx-arm64.yml +++ b/.github/workflows/libclang-macosx-arm64.yml @@ -3,7 +3,7 @@ name: libclang-macosx-arm64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 BIN: /usr/local/opt/llvm/bin concurrency: @@ -49,7 +49,7 @@ jobs: -DCMAKE_OSX_ARCHITECTURES=arm64 \ -DCMAKE_SYSTEM_NAME=Darwin \ -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \ - -DLLVM_DEFAULT_TARGET_TRIPLE=17.0.6-arm64-apple-darwin21.6 \ + -DLLVM_DEFAULT_TARGET_TRIPLE=18.1.1-arm64-apple-darwin21.6 \ -DLLVM_ENABLE_PIC=False \ -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_ENABLE_TERMINFO=OFF \ diff --git a/.github/workflows/libclang-windows-aarch64.yml b/.github/workflows/libclang-windows-aarch64.yml index 40fe2d6..d54ad6e 100644 --- a/.github/workflows/libclang-windows-aarch64.yml +++ b/.github/workflows/libclang-windows-aarch64.yml @@ -3,7 +3,7 @@ name: libclang-windows-aarch64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/.github/workflows/libclang-windows-amd64.yml b/.github/workflows/libclang-windows-amd64.yml index 6aba332..b423bd6 100644 --- a/.github/workflows/libclang-windows-amd64.yml +++ b/.github/workflows/libclang-windows-amd64.yml @@ -3,7 +3,7 @@ name: libclang-windows-amd64 on: [push, pull_request] env: - LLVM_VER: 17.0.6 + LLVM_VER: 18.1.1 concurrency: group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} diff --git a/docs/conf.py b/docs/conf.py index 3111ec9..5441988 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -63,9 +63,9 @@ # built documents. # # The short X.Y version. -version = '17.0.6' +version = '18.1.1' # The full version, including alpha/beta/rc tags. -release = '17.0.6' +release = '18.1.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index d1eaf29..baf405d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,5 +1,5 @@ :Date: 2021-04-17 -:Version: 17.0.6 +:Version: 18.1.1 :Authors: - The LLVM Team .. meta:: diff --git a/python/clang/cindex.py b/python/clang/cindex.py index db8919c..66eeac8 100644 --- a/python/clang/cindex.py +++ b/python/clang/cindex.py @@ -66,81 +66,50 @@ import clang.enumerations +import collections.abc import os -import sys - -if sys.version_info[0] == 3: - # Python 3 strings are unicode, translate them to/from utf8 for C-interop. - class c_interop_string(c_char_p): - def __init__(self, p=None): - if p is None: - p = "" - if isinstance(p, str): - p = p.encode("utf8") - super(c_char_p, self).__init__(p) - def __str__(self): - return self.value - - @property - def value(self): - if super(c_char_p, self).value is None: - return None - return super(c_char_p, self).value.decode("utf8") - - @classmethod - def from_param(cls, param): - if isinstance(param, str): - return cls(param) - if isinstance(param, bytes): - return cls(param) - if param is None: - # Support passing null to C functions expecting char arrays - return None - raise TypeError( - "Cannot convert '{}' to '{}'".format(type(param).__name__, cls.__name__) - ) - - @staticmethod - def to_python_string(x, *args): - return x.value - def b(x): - if isinstance(x, bytes): - return x - return x.encode("utf8") +# Python 3 strings are unicode, translate them to/from utf8 for C-interop. +class c_interop_string(c_char_p): + def __init__(self, p=None): + if p is None: + p = "" + if isinstance(p, str): + p = p.encode("utf8") + super(c_char_p, self).__init__(p) -elif sys.version_info[0] == 2: - # Python 2 strings are utf8 byte strings, no translation is needed for - # C-interop. - c_interop_string = c_char_p - - def _to_python_string(x, *args): - return x - - c_interop_string.to_python_string = staticmethod(_to_python_string) + def __str__(self): + return self.value - def b(x): - return x + @property + def value(self): + if super(c_char_p, self).value is None: + return None + return super(c_char_p, self).value.decode("utf8") + @classmethod + def from_param(cls, param): + if isinstance(param, str): + return cls(param) + if isinstance(param, bytes): + return cls(param) + if param is None: + # Support passing null to C functions expecting char arrays + return None + raise TypeError( + "Cannot convert '{}' to '{}'".format(type(param).__name__, cls.__name__) + ) -# Importing ABC-s directly from collections is deprecated since Python 3.7, -# will stop working in Python 3.8. -# See: https://docs.python.org/dev/whatsnew/3.7.html#id3 -if sys.version_info[:2] >= (3, 7): - from collections import abc as collections_abc -else: - import collections as collections_abc + @staticmethod + def to_python_string(x, *args): + return x.value -# We only support PathLike objects on Python version with os.fspath present -# to be consistent with the Python standard library. On older Python versions -# we only support strings and we have dummy fspath to just pass them through. -try: - fspath = os.fspath -except AttributeError: - def fspath(x): +def b(x): + if isinstance(x, bytes): return x + return x.encode("utf8") # ctypes doesn't implicitly convert c_void_p to the appropriate wrapper @@ -202,7 +171,7 @@ def __init__(self, enumeration, message): ### Structures and Utility Classes ### -class CachedProperty(object): +class CachedProperty: """Decorator that lazy-loads the value of a property. The first time the property is accessed, the original property function is @@ -392,7 +361,7 @@ def __repr__(self): return "" % (self.start, self.end) -class Diagnostic(object): +class Diagnostic: """ A Diagnostic is a single instance of a Clang diagnostic. It includes the diagnostic severity, the message, the location the diagnostic occurred, as @@ -433,7 +402,7 @@ def spelling(self): @property def ranges(self): - class RangeIterator(object): + class RangeIterator: def __init__(self, diag): self.diag = diag @@ -449,7 +418,7 @@ def __getitem__(self, key): @property def fixits(self): - class FixItIterator(object): + class FixItIterator: def __init__(self, diag): self.diag = diag @@ -468,7 +437,7 @@ def __getitem__(self, key): @property def children(self): - class ChildDiagnosticsIterator(object): + class ChildDiagnosticsIterator: def __init__(self, diag): self.diag_set = conf.lib.clang_getChildDiagnostics(diag) @@ -532,10 +501,10 @@ def from_param(self): return self.ptr -class FixIt(object): +class FixIt: """ A FixIt represents a transformation to be applied to the source to - "fix-it". The fix-it shouldbe applied by replacing the given source range + "fix-it". The fix-it should be applied by replacing the given source range with the given value. """ @@ -547,7 +516,7 @@ def __repr__(self): return "" % (self.range, self.value) -class TokenGroup(object): +class TokenGroup: """Helper class to facilitate token management. Tokens are allocated from libclang in chunks. They must be disposed of as a @@ -603,7 +572,7 @@ def get_tokens(tu, extent): yield token -class TokenKind(object): +class TokenKind: """Describes a specific type of a Token.""" _value_map = {} # int -> TokenKind @@ -642,7 +611,7 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration(object): +class BaseEnumeration: """ Common base class for named enumerations held in sync with Index.h values. @@ -1519,6 +1488,8 @@ def __repr__(self): CursorKind.STATIC_ASSERT = CursorKind(602) # A friend declaration CursorKind.FRIEND_DECL = CursorKind(603) +# A concept declaration +CursorKind.CONCEPT_DECL = CursorKind(604) # A code completion overload candidate. CursorKind.OVERLOAD_CANDIDATE = CursorKind(700) @@ -2176,7 +2147,7 @@ def from_cursor_result(res, fn, args): return res -class StorageClass(object): +class StorageClass: """ Describes the storage class of a declaration """ @@ -2470,7 +2441,7 @@ def argument_types(self): container is a Type instance. """ - class ArgumentsIterator(collections_abc.Sequence): + class ArgumentsIterator(collections.abc.Sequence): def __init__(self, parent): self.parent = parent self.length = None @@ -2725,7 +2696,7 @@ def __ne__(self, other): # a void*. -class ClangObject(object): +class ClangObject: """ A helper for Clang objects. This class helps act as an intermediary for the ctypes library and the Clang CIndex library. @@ -2773,8 +2744,8 @@ class _CXUnsavedFile(Structure): } -class CompletionChunk(object): - class Kind(object): +class CompletionChunk: + class Kind: def __init__(self, name): self.name = name @@ -2864,7 +2835,7 @@ def isKindResultType(self): class CompletionString(ClangObject): - class Availability(object): + class Availability: def __init__(self, name): self.name = name @@ -2966,7 +2937,7 @@ def results(self): @property def diagnostics(self): - class DiagnosticsItr(object): + class DiagnosticsItr: def __init__(self, ccr): self.ccr = ccr @@ -3120,13 +3091,13 @@ def from_source( if hasattr(contents, "read"): contents = contents.read() contents = b(contents) - unsaved_array[i].name = b(fspath(name)) + unsaved_array[i].name = b(os.fspath(name)) unsaved_array[i].contents = contents unsaved_array[i].length = len(contents) ptr = conf.lib.clang_parseTranslationUnit( index, - fspath(filename) if filename is not None else None, + os.fspath(filename) if filename is not None else None, args_array, len(args), unsaved_array, @@ -3157,7 +3128,7 @@ def from_ast_file(cls, filename, index=None): if index is None: index = Index.create() - ptr = conf.lib.clang_createTranslationUnit(index, fspath(filename)) + ptr = conf.lib.clang_createTranslationUnit(index, os.fspath(filename)) if not ptr: raise TranslationUnitLoadError(filename) @@ -3276,7 +3247,7 @@ def diagnostics(self): Return an iterable (and indexable) object containing the diagnostics. """ - class DiagIterator(object): + class DiagIterator: def __init__(self, tu): self.tu = tu @@ -3310,7 +3281,7 @@ def reparse(self, unsaved_files=None, options=0): if hasattr(contents, "read"): contents = contents.read() contents = b(contents) - unsaved_files_array[i].name = b(fspath(name)) + unsaved_files_array[i].name = b(os.fspath(name)) unsaved_files_array[i].contents = contents unsaved_files_array[i].length = len(contents) ptr = conf.lib.clang_reparseTranslationUnit( @@ -3334,7 +3305,11 @@ def save(self, filename): """ options = conf.lib.clang_defaultSaveOptions(self) result = int( - conf.lib.clang_saveTranslationUnit(self, fspath(filename), options) + conf.lib.clang_saveTranslationUnit( + self, + os.fspath(filename), + options, + ) ) if result != 0: raise TranslationUnitSaveError(result, "Error saving TranslationUnit.") @@ -3378,12 +3353,12 @@ def codeComplete( if hasattr(contents, "read"): contents = contents.read() contents = b(contents) - unsaved_files_array[i].name = b(fspath(name)) + unsaved_files_array[i].name = b(os.fspath(name)) unsaved_files_array[i].contents = contents unsaved_files_array[i].length = len(contents) ptr = conf.lib.clang_codeCompleteAt( self, - fspath(path), + os.fspath(path), line, column, unsaved_files_array, @@ -3417,7 +3392,9 @@ class File(ClangObject): @staticmethod def from_name(translation_unit, file_name): """Retrieve a file handle within the given translation unit.""" - return File(conf.lib.clang_getFile(translation_unit, fspath(file_name))) + return File( + conf.lib.clang_getFile(translation_unit, os.fspath(file_name)), + ) @property def name(self): @@ -3445,7 +3422,7 @@ def from_result(res, fn, args): return res -class FileInclusion(object): +class FileInclusion: """ The FileInclusion class represents the inclusion of one source file by another via a '#include' directive or as the input file for the translation @@ -3494,7 +3471,7 @@ def __init__(self, enumeration, message): Exception.__init__(self, "Error %d: %s" % (enumeration, message)) -class CompileCommand(object): +class CompileCommand: """Represents the compile command used to build a file""" def __init__(self, cmd, ccmds): @@ -3526,7 +3503,7 @@ def arguments(self): yield conf.lib.clang_CompileCommand_getArg(self.cmd, i) -class CompileCommands(object): +class CompileCommands: """ CompileCommands is an iterable object containing all CompileCommand that can be used for building a specific file. @@ -3577,7 +3554,7 @@ def fromDirectory(buildDir): errorCode = c_uint() try: cdb = conf.lib.clang_CompilationDatabase_fromDirectory( - fspath(buildDir), byref(errorCode) + os.fspath(buildDir), byref(errorCode) ) except CompilationDatabaseError as e: raise CompilationDatabaseError( @@ -3591,7 +3568,7 @@ def getCompileCommands(self, filename): build filename. Returns None if filename is not found in the database. """ return conf.lib.clang_CompilationDatabase_getCompileCommands( - self, fspath(filename) + self, os.fspath(filename) ) def getAllCompileCommands(self): @@ -3982,7 +3959,7 @@ def register(item): register(f) -class Config(object): +class Config: library_path = os.environ.get("LIBCLANG_LIBRARY_PATH", os.path.join(os.path.dirname(os.path.realpath(__file__)), "native")) library_file = None compatibility_check = True @@ -3997,7 +3974,7 @@ def set_library_path(path): "any other functionalities in libclang." ) - Config.library_path = fspath(path) + Config.library_path = os.fspath(path) @staticmethod def set_library_file(filename): @@ -4008,7 +3985,7 @@ def set_library_file(filename): "any other functionalities in libclang." ) - Config.library_file = fspath(filename) + Config.library_file = os.fspath(filename) @staticmethod def set_compatibility_check(check_status): diff --git a/scripts/data/clang_bindings.patch b/scripts/data/clang_bindings.patch index 6936b35..6164bb6 100644 --- a/scripts/data/clang_bindings.patch +++ b/scripts/data/clang_bindings.patch @@ -1,7 +1,7 @@ diff -aruN a/python/clang/cindex.py b/python/clang/cindex.py ---- a/python/clang/cindex.py 2024-03-17 21:00:52 -+++ b/python/clang/cindex.py 2024-03-17 21:02:00 -@@ -1121,7 +1121,24 @@ +--- a/python/clang/cindex.py 2024-03-17 21:19:17 ++++ b/python/clang/cindex.py 2024-03-17 21:18:28 +@@ -1090,7 +1090,24 @@ # Represents an @available(...) check. CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148) @@ -26,7 +26,7 @@ diff -aruN a/python/clang/cindex.py b/python/clang/cindex.py # A statement whose specific kind is not exposed via this interface. # -@@ -1343,6 +1360,105 @@ +@@ -1312,6 +1329,105 @@ # OpenMP teams distribute directive. CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271) @@ -132,7 +132,7 @@ diff -aruN a/python/clang/cindex.py b/python/clang/cindex.py ### # Other Kinds -@@ -1470,6 +1586,9 @@ +@@ -1441,6 +1557,9 @@ return cursor @@ -142,16 +142,16 @@ diff -aruN a/python/clang/cindex.py b/python/clang/cindex.py def __eq__(self, other): return conf.lib.clang_equalCursors(self, other) -@@ -3864,7 +3983,7 @@ +@@ -3841,7 +3960,7 @@ - class Config(object): + class Config: - library_path = None + library_path = os.environ.get("LIBCLANG_LIBRARY_PATH", os.path.join(os.path.dirname(os.path.realpath(__file__)), "native")) library_file = None compatibility_check = True loaded = False -@@ -3939,7 +4058,7 @@ +@@ -3916,7 +4035,7 @@ else: file = "libclang.so" diff --git a/scripts/update_python_clang_bindings.sh b/scripts/update_python_clang_bindings.sh index 8eed31f..ea50166 100755 --- a/scripts/update_python_clang_bindings.sh +++ b/scripts/update_python_clang_bindings.sh @@ -3,7 +3,7 @@ set -euo pipefail TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" -LLVM_VERSION="${LLVM_VERSION:-17.0.6}" +LLVM_VERSION="${LLVM_VERSION:-18.1.1}" LLVM_URL_PREFIX="https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-${LLVM_VERSION}/clang/bindings/python" LISTING=( diff --git a/setup.py b/setup.py index 6757b18..77b6fb0 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='libclang', - version='17.0.6', + version='18.1.1', description='Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python, to make the installation process easier.', long_description=long_description, long_description_content_type='text/markdown', diff --git a/setup_ext.py b/setup_ext.py index fd76b0f..8831a0f 100644 --- a/setup_ext.py +++ b/setup_ext.py @@ -54,7 +54,7 @@ def run(self): setup( name='libclang', - version='17.0.6', + version='18.1.1', description='Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python, to make the installation process easier.', long_description=long_description, long_description_content_type='text/markdown',