22
33import json
44import os
5+ import shlex
56import shutil
67import subprocess
8+ from concurrent .futures import ThreadPoolExecutor , as_completed
79from pathlib import Path
810
911root = Path ("/repo" )
1012build_dir = Path (os .environ .get ("BUILD_DIR" , "build" ))
13+ jobs = int (os .environ .get ("JOBS" , "1" ))
1114
1215cpp_format_exts = {
1316 ".c" , ".cc" , ".cpp" , ".cxx" , ".c++" ,
@@ -39,7 +42,7 @@ def run(cmd, check=True):
3942compile_db = root / build_dir / "compile_commands.json"
4043
4144if not compile_db .exists ():
42- cmake_args = os .environ .get ("CMAKE_ARGS" , "" ). split ( )
45+ cmake_args = shlex . split ( os .environ .get ("CMAKE_ARGS" , "" ))
4346 run ([
4447 "cmake" ,
4548 "-S" , "." ,
@@ -82,10 +85,10 @@ def run(cmd, check=True):
8285print (f"==> clang-tidy translation units: { len (tidy_files )} " , flush = True )
8386
8487tidy_failures = []
85- extra = os .environ .get ("CLANG_TIDY_EXTRA_ARGS" , "" ). split ( )
88+ extra = shlex . split ( os .environ .get ("CLANG_TIDY_EXTRA_ARGS" , "" ))
8689strict = os .environ .get ("STRICT_CLANG_TIDY" , "0" ) == "1"
8790
88- for rel in tidy_files :
91+ def run_tidy ( rel ) :
8992 cmd = [
9093 "clang-tidy" ,
9194 str (rel ),
@@ -95,9 +98,15 @@ def run(cmd, check=True):
9598 ]
9699 print ("+ " + " " .join (cmd ), flush = True )
97100 ret = subprocess .run (cmd ).returncode
98- if ret != 0 :
99- tidy_failures .append ((str (rel ), ret ))
100- print (f"WARNING: clang-tidy failed for { rel } with exit code { ret } " , flush = True )
101+ return str (rel ), ret
102+
103+ with ThreadPoolExecutor (max_workers = max (1 , jobs )) as pool :
104+ futures = [pool .submit (run_tidy , rel ) for rel in tidy_files ]
105+ for fut in as_completed (futures ):
106+ filename , ret = fut .result ()
107+ if ret != 0 :
108+ tidy_failures .append ((str (rel ), ret ))
109+ print (f"WARNING: clang-tidy failed for { rel } with exit code { ret } " , flush = True )
101110
102111if tidy_failures :
103112 print ("==> clang-tidy failures:" , flush = True )
0 commit comments