-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclang_tidy.py
40 lines (30 loc) · 1015 Bytes
/
clang_tidy.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
import subprocess
from argparse import ArgumentParser
from typing import Tuple
from .util import ensure_installed, DEFAULT_CLANG_VERSION
parser = ArgumentParser()
parser.add_argument("--version", default=DEFAULT_CLANG_VERSION)
def run_clang_tidy(args=None) -> Tuple[int, str]:
hook_args, other_args = parser.parse_known_args(args)
path = ensure_installed("clang-tidy", hook_args.version)
command = [str(path)]
command.extend(other_args)
retval = 0
output = ""
try:
sp = subprocess.run(command, stdout=subprocess.PIPE, encoding='utf-8')
retval = sp.returncode
output = sp.stdout
if "warning:" in output or "error:" in output:
retval = 1
return retval, output
except FileNotFoundError as stderr:
retval = 1
return retval, str(stderr)
def main() -> int:
retval, output = run_clang_tidy()
if retval != 0:
print(output)
return retval
if __name__ == "__main__":
raise SystemExit(main())