-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathlint-clang-format.py
executable file
·50 lines (40 loc) · 1.11 KB
/
lint-clang-format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
from glob import glob
from pathlib import Path
from subprocess import run
from os import path
import subprocess
import sys
from time import time
import re
root_path = path.abspath(Path(__file__).parent.parent.parent)
globs = [
f"{root_path}/include/**/*.h",
f"{root_path}/test/**/*.h",
f"{root_path}/test/**/*.cpp",
]
exclusions = [
"nanobench\\.h",
"FuzzedDataProvider\\.h",
'/third-party/']
files = []
for g in globs:
r = glob(g, recursive=True)
files.extend(r)
# filter out exclusions
for exclusion in exclusions:
l = filter(lambda file: re.search(exclusion, file) == None, files)
files = list(l)
if len(files) == 0:
print("could not find any files!")
sys.exit(1)
command = ['clang-format', '--dry-run', '-Werror'] + files
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=None,
stdin=subprocess.PIPE,
universal_newlines=True)
stdout, stderr = p.communicate()
print(f"clang-format checked {len(files)} files")
if p.returncode != 0:
sys.exit(p.returncode)