|
| 1 | +# AUI Framework - Declarative UI toolkit for modern C++20 |
| 2 | +# Copyright (C) 2020-2024 Alex2772 and Contributors |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MPL-2.0 |
| 5 | +# |
| 6 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + |
| 10 | +""" |
| 11 | +
|
| 12 | +This script is run on CI/CD. It runs cmake build and then parses the build log to count occurrences of each diagnostic |
| 13 | +and prints them in descending order. It is handy to identify which diagnostic rules are causing issues and adjust the |
| 14 | +build configuration accordingly. It is also useful to track the progress of fixing these issues over time. |
| 15 | +
|
| 16 | +""" |
| 17 | + |
| 18 | + |
| 19 | +import re |
| 20 | +import subprocess |
| 21 | +import sys |
| 22 | +from pathlib import Path |
| 23 | + |
| 24 | +REGEX_DIAGNOSTIC = re.compile(r'.+ \[([a-zA-Z0-9-]+)(,.+)?\]$') |
| 25 | +assert REGEX_DIAGNOSTIC.match("/home/AUI/Common/ASmallVector.h:326:5: warning: function 'contains' should be marked [[nodiscard]] [modernize-use-nodiscard,-warnings-as-errors]").group(1) == 'modernize-use-nodiscard' |
| 26 | + |
| 27 | + |
| 28 | +if __name__ == '__main__': |
| 29 | + if not Path('CMakeCache.txt').is_file(): |
| 30 | + raise RuntimeError('This script should be run inside preconfigured CMake build directory.') |
| 31 | + |
| 32 | + # In .clang-tidy, we've disabled WarningsAsErrors. So, we need to ensure we are building all the files to capture |
| 33 | + # all problems. |
| 34 | + if subprocess.run("cmake --build . -t clean", shell=True).returncode != 0: |
| 35 | + exit(-1) |
| 36 | + |
| 37 | + cmake_process = subprocess.Popen("cmake --build .", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 38 | + cmake_process.stdout.readline() |
| 39 | + |
| 40 | + def lines(pipe): |
| 41 | + while True: |
| 42 | + l = pipe.readline() |
| 43 | + if not l: |
| 44 | + return |
| 45 | + l = l.decode('utf-8').rstrip('\n') |
| 46 | + print(l) |
| 47 | + yield l |
| 48 | + |
| 49 | + count = {} |
| 50 | + for line in lines(cmake_process.stdout): |
| 51 | + line = line.strip() |
| 52 | + if m := REGEX_DIAGNOSTIC.match(line): |
| 53 | + diagnostic_name = m.group(1) |
| 54 | + if diagnostic_name.startswith("-W"): |
| 55 | + # TODO unskip warnings |
| 56 | + continue |
| 57 | + |
| 58 | + count[diagnostic_name] = count.get(diagnostic_name, 0) + 1 |
| 59 | + |
| 60 | + count_as_list = count.items() |
| 61 | + print('Sorted by count:') |
| 62 | + for i in sorted(count_as_list, key=lambda x: x[1], reverse=True): |
| 63 | + print(f"{i[0]}: {i[1]}") |
| 64 | + |
| 65 | + print('') |
| 66 | + print('Sorted by name:') |
| 67 | + for i in sorted(count_as_list, key=lambda x: x[0]): |
| 68 | + print(f"{i[0]}: {i[1]}") |
| 69 | + |
| 70 | + print('') |
| 71 | + total = sum(count.values()) |
| 72 | + print(f'Total: {total}') |
| 73 | + if total > 0: |
| 74 | + exit(-1) |
| 75 | + |
| 76 | + |
0 commit comments