-
Notifications
You must be signed in to change notification settings - Fork 4
/
runClangTidy.py
executable file
·45 lines (40 loc) · 1.43 KB
/
runClangTidy.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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
from argparse import ArgumentParser
from pathlib import Path
from subprocess import run
from concurrent.futures import ThreadPoolExecutor
from sys import exit
parser = ArgumentParser(
description = 'Light-weight wrapper around clang-tidy to enable `ninja clang-tidy` to function properly',
allow_abbrev = False
)
parser.add_argument('-s', required = True, type = str, metavar = 'sourcePath',
dest = 'sourcePath', help = 'Path to the source directory to run clang-tidy in')
parser.add_argument('-p', required = True, type = str, metavar = 'buildPath',
dest = 'buildPath', help = 'Path to the build directory containing a compile_commands.json')
args = parser.parse_args()
def globFiles():
srcDir = Path(args.sourcePath)
paths = set(('impl',)) # 'test'))
suffixes = set(('cxx', 'hxx'))
for path in paths:
for suffix in suffixes:
yield srcDir.glob('{}/**/*.{}'.format(path, suffix))
def globSrc():
for item in srcDir.glob('substrate/**/*'):
if item.name != 'meson.build':
yield item
yield globSrc()
def gatherFiles():
for fileGlob in globFiles():
for file in fileGlob:
yield file
extraArgs = []
futures = []
returncode = 0
with ThreadPoolExecutor() as pool:
for file in gatherFiles():
futures.append(pool.submit(run, ['clang-tidy'] + extraArgs + ['-p', args.buildPath, file]))
returncode = max((future.result().returncode for future in futures))
exit(returncode)