5151 import queue as queue
5252
5353
54- def run_tidy (task_queue , lock , timeout ):
54+ def run_tidy (task_queue , lock , timeout , failed_files ):
5555 watchdog = None
5656 while True :
5757 command = task_queue .get ()
@@ -63,6 +63,14 @@ def run_tidy(task_queue, lock, timeout):
6363 watchdog .start ()
6464
6565 stdout , stderr = proc .communicate ()
66+ if proc .returncode != 0 :
67+ if proc .returncode < 0 :
68+ msg = "Terminated by signal %d : %s\n " % (
69+ - proc .returncode ,
70+ " " .join (command ),
71+ )
72+ stderr += msg .encode ("utf-8" )
73+ failed_files .append (command )
6674
6775 with lock :
6876 sys .stdout .write (stdout .decode ("utf-8" ) + "\n " )
@@ -82,9 +90,9 @@ def run_tidy(task_queue, lock, timeout):
8290 task_queue .task_done ()
8391
8492
85- def start_workers (max_tasks , tidy_caller , task_queue , lock , timeout ):
93+ def start_workers (max_tasks , tidy_caller , arguments ):
8694 for _ in range (max_tasks ):
87- t = threading .Thread (target = tidy_caller , args = ( task_queue , lock , timeout ) )
95+ t = threading .Thread (target = tidy_caller , args = arguments )
8896 t .daemon = True
8997 t .start ()
9098
@@ -219,8 +227,10 @@ def main():
219227 # A lock for console output.
220228 lock = threading .Lock ()
221229
230+ # List of files with a non-zero return code.
231+ failed_files = []
222232 # Run a pool of clang-tidy workers.
223- start_workers (max_task_count , run_tidy , task_queue , lock , args .timeout )
233+ start_workers (max_task_count , run_tidy , ( task_queue , lock , args .timeout , failed_files ) )
224234
225235 # Form the common args list.
226236 common_clang_tidy_args = []
@@ -263,8 +273,12 @@ def main():
263273
264274 task_queue .put (command )
265275
276+ # Application return code
277+ return_code = 0
266278 # Wait for all threads to be done.
267279 task_queue .join ()
280+ if failed_files :
281+ return_code = 1
268282
269283 if yaml and args .export_fixes :
270284 print ("Writing fixes to " + args .export_fixes + " ..." )
@@ -273,9 +287,11 @@ def main():
273287 except Exception :
274288 sys .stderr .write ("Error exporting fixes.\n " )
275289 traceback .print_exc ()
290+ return_code = 1
276291
277292 if tmpdir :
278293 shutil .rmtree (tmpdir )
294+ sys .exit (return_code )
279295
280296
281297if __name__ == "__main__" :
0 commit comments