From 05e28c23ee06b0567effec7a87c254691b6f2aee Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Sun, 9 Oct 2022 16:39:29 +0000 Subject: [PATCH] utils: Find default clang-format in check-style-clang-format.py --- utils/check-style-clang-format.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils/check-style-clang-format.py b/utils/check-style-clang-format.py index f80260650..bdd57798f 100755 --- a/utils/check-style-clang-format.py +++ b/utils/check-style-clang-format.py @@ -234,12 +234,30 @@ def find_clang_format_path() -> str: @return Path to clang-format. """ + # Find exact version for version in CLANG_FORMAT_VERSIONS: clang_format_path = shutil.which(f'clang-format-{version}') if clang_format_path: return clang_format_path + # Find default version and check if it is supported + clang_format_path = shutil.which('clang-format') + + if clang_format_path: + process = subprocess.run([clang_format_path, '--version'], + capture_output=True, + text=True, + check=True, + ) + + version = process.stdout.strip().split(' ')[-1] + major_version = int(version.split('.')[0]) + + if major_version in CLANG_FORMAT_VERSIONS: + return clang_format_path + + # No supported version of clang-format found raise RuntimeError( f'Could not find any supported version of clang-format installed on this system. ' f'List of supported versions: {CLANG_FORMAT_VERSIONS}.'