Skip to content

Commit 6be2172

Browse files
committed
run_clang_format.py: Require clang-format 10.0.0
The previous version required clang-format >= 10.0.0, but this could cause problems if a version > 10.0.0 formatted differently.
1 parent b9e7f12 commit 6be2172

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

run_clang_format.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import subprocess
1212
import sys
1313
import os
14-
import re
1514

1615
#Folders to scan
1716
folders = [
@@ -36,11 +35,14 @@
3635
#Files with this extensions will be formatted/
3736
extensions = [".h", ".hpp", ".c", ".cpp"]
3837

39-
# Check that the clang-format is installed and >= the minimum version
40-
clang_format_minimum_version = [10, 0, 0]
38+
# Check that the clang-format is installed and matches the required version. The clang-format binary
39+
# chosen is specified by the environment variable $CLANG_FORMAT_PATH or "clang-format" using the
40+
# regular $PATH resolution mechanism if $CLANG_FORMAT_PATH is undefined.
41+
clang_format_path = os.environ.get("CLANG_FORMAT_PATH")
42+
clang_format_bin = clang_format_path if clang_format_path is not None else "clang-format"
4143
try:
4244
cf = subprocess.Popen(
43-
["clang-format", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45+
[clang_format_bin, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4446
except FileNotFoundError:
4547
print("clang-format is not in $PATH")
4648
exit(1)
@@ -50,26 +52,9 @@
5052
clang_format_stderr.decode('utf-8')))
5153
exit(1)
5254
clang_format_stdout = clang_format_stdout.decode("utf-8")
53-
m = re.match('^clang-format version (\d+\.\d+\.\d+)', clang_format_stdout)
54-
if m is None:
55-
print("clang-format --version output not understood: \"%s\"" % (clang_format_stdout))
55+
if not clang_format_stdout.startswith("clang-format version 10.0.0"):
56+
print("clang-format is not the required version: 10.0.0")
5657
exit(1)
57-
clang_format_version = [int(e) for e in m.group(1).split(".")]
58-
59-
if (clang_format_version[0] < clang_format_minimum_version[0]) or \
60-
((clang_format_version[0] == clang_format_minimum_version[0]) and \
61-
((clang_format_version[1] < clang_format_minimum_version[1]) or \
62-
((clang_format_version[1] == clang_format_minimum_version[1]) and \
63-
(clang_format_version[2] < clang_format_minimum_version[2])))):
64-
print(
65-
"Installed clang-format version (%d.%d.%d) is less than the required minimum version (%d.%d.%d)" % (
66-
clang_format_version[0],
67-
clang_format_version[1],
68-
clang_format_version[2],
69-
clang_format_minimum_version[0],
70-
clang_format_minimum_version[1],
71-
clang_format_minimum_version[2]))
72-
exit(1)
7358

7459
#processing formatting
7560
for folder in folders:

0 commit comments

Comments
 (0)