Skip to content

Commit 48d62b4

Browse files
authored
Merge pull request PowerDNS#17371 from rgacogne/error-when-clang-tidy-fails
ci: Error when clang tidy fails
2 parents acce7db + d395cc2 commit 48d62b4

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

.github/scripts/clang-tidy-diff.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
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

281297
if __name__ == "__main__":

.github/scripts/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
import sys
56

67
import git
78
import yaml
@@ -43,6 +44,6 @@ def index_compdb(file_contents):
4344
"""Index the compilation database."""
4445
result = set()
4546
for item in file_contents:
46-
filename = os.path.join(item["directory"], item["file"])
47+
filename = os.path.normpath(os.path.join(item["directory"], item["file"]))
4748
result.add(filename)
4849
return result

0 commit comments

Comments
 (0)