check_doxygen_groups.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. import subprocess
  14. import re
  15. import sys
  16. import os
  17. groups = {}
  18. any_errors = False
  19. res = subprocess.run(['git', 'grep', '\\defgroup'], check=True, stdout=subprocess.PIPE)
  20. for line in res.stdout.decode('utf8').split('\n'):
  21. m = re.match(r'^(\S+):.*\\defgroup\s+(\w+)', line)
  22. if m:
  23. filename = m.group(1)
  24. group = m.group(2)
  25. if os.path.basename(filename) in ('check_doxygen_groups.py', 'index.h'):
  26. continue
  27. if group in groups:
  28. any_errors = True
  29. print("{} uses \\defgroup {} but so does {}".format(groups[group], group, filename))
  30. else:
  31. groups[group] = filename
  32. res = subprocess.run(['git', 'grep', '\\ingroup'], check=True, stdout=subprocess.PIPE)
  33. for line in res.stdout.decode('utf8').split('\n'):
  34. m = re.match(r'^(\S+):.*\\ingroup\s+(\w+)', line)
  35. if m:
  36. filename = m.group(1)
  37. group = m.group(2)
  38. if os.path.basename(filename) in ('check_doxygen_groups.py', 'index.h'):
  39. continue
  40. if group not in groups:
  41. any_errors = True
  42. print("{} uses \\ingroup {} which was never defined".format(filename, group))
  43. sys.exit(any_errors)