aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Fioraldi <andreafioraldi@gmail.com>2019-08-27 19:35:44 +0200
committerAndrea Fioraldi <andreafioraldi@gmail.com>2019-08-27 19:35:44 +0200
commitaca63d4986540ca6c51cc90321f54509aee2ce45 (patch)
treecb282a85ba00a28f1a7d55a575b63026597df9d4
parentbae398a9a4d14ccddde48591ba94d5c03970d741 (diff)
downloadAFLplusplus-aca63d4986540ca6c51cc90321f54509aee2ce45.tar.gz
custom format now search for the best clang-format version
-rw-r--r--.clang-format2
-rwxr-xr-x.custom-format.py28
2 files changed, 27 insertions, 3 deletions
diff --git a/.clang-format b/.clang-format
index e506392d..f691d684 100644
--- a/.clang-format
+++ b/.clang-format
@@ -124,7 +124,7 @@ RawStringFormats:
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
-SortIncludes: true
+SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
diff --git a/.custom-format.py b/.custom-format.py
index b4a2c48a..a73d92ab 100755
--- a/.custom-format.py
+++ b/.custom-format.py
@@ -2,10 +2,34 @@
import subprocess
import sys
+import os
with open(".clang-format") as f:
fmt = f.read()
+CLANG_FORMAT_BIN = os.getenv("CLANG_FORMAT_BIN")
+if CLANG_FORMAT_BIN is None:
+ p = subprocess.Popen(["clang-format", "--version"], stdout=subprocess.PIPE)
+ o, _ = p.communicate()
+ o = str(o, "utf-8")
+ o = o[len("clang-format version "):].strip()
+ o = o[:o.find(".")]
+ o = int(o)
+ if o < 7:
+ if subprocess.call(['which', 'clang-format-7'], stdout=subprocess.PIPE) == 0:
+ CLANG_FORMAT_BIN = 'clang-format-7'
+ elif subprocess.call(['which', 'clang-format-8'], stdout=subprocess.PIPE) == 0:
+ CLANG_FORMAT_BIN = 'clang-format-8'
+ elif subprocess.call(['which', 'clang-format-9'], stdout=subprocess.PIPE) == 0:
+ CLANG_FORMAT_BIN = 'clang-format-9'
+ elif subprocess.call(['which', 'clang-format-10'], stdout=subprocess.PIPE) == 0:
+ CLANG_FORMAT_BIN = 'clang-format-10'
+ else:
+ print ("clang-format 7 or above is needed. Aborted.")
+ exit(1)
+ else:
+ CLANG_FORMAT_BIN = 'clang-format'
+
COLUMN_LIMIT = 80
for line in fmt.split("\n"):
line = line.split(":")
@@ -13,7 +37,7 @@ for line in fmt.split("\n"):
COLUMN_LIMIT = int(line[1].strip())
def custom_format(filename):
- p = subprocess.Popen(['clang-format-7', filename], stdout=subprocess.PIPE)
+ p = subprocess.Popen([CLANG_FORMAT_BIN, filename], stdout=subprocess.PIPE)
src, _ = p.communicate()
src = str(src, "utf-8")
@@ -28,7 +52,7 @@ def custom_format(filename):
i -= 1
elif line.startswith("#el") and macro_indent > 0:
i -= 1
- elif line.startswith("#if") and not (line.startswith("#ifndef") and line.endswith("_H")):
+ elif line.startswith("#if") and not (line.startswith("#ifndef") and (line.endswith("_H") or line.endswith("H_"))):
macro_indent += 1
r = "#" + (i * " ") + line[1:]
if i != 0 and line.endswith("\\"):