diff --git a/utilities/clang-tidy/analyze.py b/utilities/clang-tidy/analyze.py index a11fc4257add7171519935ed5c60751d46421ab2..8856beda479e843f2269e9f272487bdc11d61edb 100644 --- a/utilities/clang-tidy/analyze.py +++ b/utilities/clang-tidy/analyze.py @@ -53,18 +53,19 @@ WARNING_PATTERN = re.compile(r"\[[a-z-]+,-warnings-as-errors\]\n") TRAILING = len(",-warnings-as-errors]\n") -def print_summary(output_file: pathlib.Path) -> tuple[bool | str]: +def count_diagnostics(output_file: pathlib.Path) -> Counter: clang_tidy_log = output_file.read_text() matches = WARNING_PATTERN.findall(clang_tidy_log) matches = [m[1:-TRAILING] for m in matches] - counter = Counter(matches) + counts = Counter(matches) - if not counter: - return True, "Success! No more warnings." + return counts - counts = sorted(list(counter.items()), key=lambda it: it[1], reverse=True) + +def print_summary(counts: Counter): + counts = sorted(list(counts.items()), key=lambda it: it[1], reverse=True) summary = "\n".join(f"{warning}: {count}" for warning, count in counts) - return False, summary + return summary def main(): @@ -117,6 +118,7 @@ def main(): shutil.copy(str(database_fp), str(database_backup)) success: bool = True + total_counts = Counter() try: with database_fp.open() as dbfile: @@ -169,12 +171,19 @@ def main(): print(f" -- clang-tidy output written to {str(output)}") - success, summary = print_summary(output) - print(" -- Summary:") - print(indent(summary, " - ")) + counts = count_diagnostics(output) + total_counts.update(counts) + + if counts.total() == 0: + print(" -- Success!") + else: + summary = print_summary(counts) + + print(" -- Summary:") + print(indent(summary, " - ")) print("\n\n", end="") - return success + return counts.total() == 0 for module_spec in params.get("modules", []): include_paths: list[pathlib.Path] = [] @@ -196,7 +205,7 @@ def main(): header_filter, output_dir / "modules" / f"{module_name}.out", f"module {module_name}", - ) + ) success = succ and success for app_spec in params.get("apps", []): @@ -219,7 +228,7 @@ def main(): include_paths, None, output_dir / "apps" / f"{app_name}.out", - f"application {app_name}" + f"application {app_name}", ) success = succ and success @@ -228,6 +237,11 @@ def main(): # Restore the backup shutil.move(str(database_backup), str(database_fp)) + print(f"Done. Total number of diagnostics: {total_counts.total()}") + print() + print("Summary:") + print(indent(print_summary(total_counts), " - ")) + exit(0 if success else 1)