Austin Schuh | 208337d | 2022-01-01 14:29:11 -0800 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (c) 2021 Raspberry Pi (Trading) Ltd. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | # |
| 8 | # Little script to check that every \ingroup has a matching \defgroup |
| 9 | # |
| 10 | # Usage: |
| 11 | # |
| 12 | # Run from the root of the tree to check |
| 13 | |
| 14 | |
| 15 | import subprocess |
| 16 | import re |
| 17 | import sys |
| 18 | import os |
| 19 | |
| 20 | groups = {} |
| 21 | any_errors = False |
| 22 | |
| 23 | res = subprocess.run(['git', 'grep', '\\defgroup'], check=True, stdout=subprocess.PIPE) |
| 24 | for line in res.stdout.decode('utf8').split('\n'): |
| 25 | m = re.match(r'^(\S+):.*\\defgroup\s+(\w+)', line) |
| 26 | if m: |
| 27 | filename = m.group(1) |
| 28 | group = m.group(2) |
| 29 | if os.path.basename(filename) in ('check_doxygen_groups.py', 'index.h'): |
| 30 | continue |
| 31 | if group in groups: |
| 32 | any_errors = True |
| 33 | print("{} uses \\defgroup {} but so does {}".format(groups[group], group, filename)) |
| 34 | else: |
| 35 | groups[group] = filename |
| 36 | |
| 37 | res = subprocess.run(['git', 'grep', '\\ingroup'], check=True, stdout=subprocess.PIPE) |
| 38 | for line in res.stdout.decode('utf8').split('\n'): |
| 39 | m = re.match(r'^(\S+):.*\\ingroup\s+(\w+)', line) |
| 40 | if m: |
| 41 | filename = m.group(1) |
| 42 | group = m.group(2) |
| 43 | if os.path.basename(filename) in ('check_doxygen_groups.py', 'index.h'): |
| 44 | continue |
| 45 | if group not in groups: |
| 46 | any_errors = True |
| 47 | print("{} uses \\ingroup {} which was never defined".format(filename, group)) |
| 48 | |
| 49 | sys.exit(any_errors) |