-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclang_tidy.py
More file actions
39 lines (29 loc) · 1003 Bytes
/
clang_tidy.py
File metadata and controls
39 lines (29 loc) · 1003 Bytes
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
import subprocess
from argparse import ArgumentParser
from typing import Tuple
from .util import ensure_installed, DEFAULT_CLANG_TIDY_VERSION
parser = ArgumentParser()
parser.add_argument("--version", default=DEFAULT_CLANG_TIDY_VERSION)
def run_clang_tidy(args=None) -> Tuple[int, str]:
hook_args, other_args = parser.parse_known_args(args)
ensure_installed("clang-tidy", hook_args.version)
command = ["clang-tidy"] + 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())