aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2022-03-17 14:15:37 +0100
committerStefan Boberg <[email protected]>2022-03-17 14:15:37 +0100
commitd4cfea4764b983bf8e992b7219583c1f86ff0194 (patch)
tree7b5c0677acaf8a6a55f21aa77e97cb365cc5187f /scripts
parentSome more updates to .clang-format to remove redundant settings (diff)
downloadzen-d4cfea4764b983bf8e992b7219583c1f86ff0194.tar.xz
zen-d4cfea4764b983bf8e992b7219583c1f86ff0194.zip
Introduced basic validation of the clang-format version
This is a very primitive implementation, which could probably be improved. We should also raise an error if clang-format is not found
Diffstat (limited to 'scripts')
-rw-r--r--scripts/formatcode.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/scripts/formatcode.py b/scripts/formatcode.py
index dc13ae117..49a8753da 100644
--- a/scripts/formatcode.py
+++ b/scripts/formatcode.py
@@ -1,8 +1,9 @@
import argparse
-import os
import fileinput
+import os
import pathlib
import re
+import subprocess
match_expressions = []
valid_extensions = []
@@ -89,6 +90,20 @@ def parse_match_expressions(wildcards, matches):
print(f'Could not parse input --match expression \'{regex}\': {str(ex)}')
quit()
+def validate_clang_format():
+ vstring = subprocess.check_output("clang-format --version", shell=True).decode().rstrip()
+
+ match = re.search(r'(\d+)\.(\d+)(\.(\d+))?$', vstring)
+ if not match:
+ raise ValueError("invalid version number '%s'" % vstring)
+
+ (major, minor, patch) = match.group(1, 2, 4)
+
+ if int(major) < 13:
+ if int(minor) == 0:
+ if int(patch) < 1:
+ raise ValueError(f'invalid clang-format version -- we require at least v12.0.1')
+
def _main():
global root_dir, use_batching
@@ -106,6 +121,8 @@ def _main():
root_dir = pathlib.Path(__file__).parent.parent.resolve()
use_batching = options.use_batching
+ validate_clang_format()
+
while True:
if (os.path.isfile(".clang-format")):
scan_zen(".")