[Bf-blender-cvs] [1772ac968e6] temp-clang-format: clang-format-paths: add version check

Campbell Barton noreply at git.blender.org
Wed Jan 9 21:55:46 CET 2019


Commit: 1772ac968e63ef6c1d105586a1658f7bc6d3a647
Author: Campbell Barton
Date:   Thu Jan 10 07:54:03 2019 +1100
Branches: temp-clang-format
https://developer.blender.org/rB1772ac968e63ef6c1d105586a1658f7bc6d3a647

clang-format-paths: add version check

===================================================================

M	GNUmakefile
R069	clang-format-migration.py	clang-format-paths.py

===================================================================

diff --git a/GNUmakefile b/GNUmakefile
index b375e02bdfb..85bd01911de 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -463,7 +463,7 @@ update: .FORCE
 	git submodule foreach git pull --rebase origin master
 
 format: .FORCE
-	python3 clang-format-migration.py $(PATHS)
+	python3 clang-format-paths.py $(PATHS)
 
 
 # -----------------------------------------------------------------------------
diff --git a/clang-format-migration.py b/clang-format-paths.py
similarity index 69%
rename from clang-format-migration.py
rename to clang-format-paths.py
index 6d6cda95ebb..f5ece89f40c 100755
--- a/clang-format-migration.py
+++ b/clang-format-paths.py
@@ -4,6 +4,8 @@ import os
 import sys
 import subprocess
 
+VERSION_MIN = (6, 0, 0)
+
 # Optionally pass in files to operate on.
 paths = sys.argv[1:]
 if not paths:
@@ -45,6 +47,14 @@ def convert_tabs_to_spaces(files):
             fh.write(data)
 
 
+def clang_format_version():
+    version_output = subprocess.check_output(("clang-format", "-version")).decode('utf-8')
+    version = next(iter(v for v in version_output.split() if v[0].isdigit()), None)
+    if version is not None:
+        version = tuple(int(n) for n in version.split("."))
+    return version
+
+
 def clang_format(files):
     for f in files:
         cmd = (
@@ -54,6 +64,14 @@ def clang_format(files):
 
 
 def main():
+    version = clang_format_version()
+    if version is None:
+        print("Unable to detect 'clang-format -version'")
+        sys.exit(1)
+    if version < VERSION_MIN:
+        print("Version of clang-format is too old:", version, "<", VERSION_MIN)
+        sys.exit(1)
+
     files = [
         f for f in source_files_from_git()
         if f.endswith(extensions)



More information about the Bf-blender-cvs mailing list