tidy.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # Copyright 2019 Hans Dembinski
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
  5. import subprocess as subp
  6. from pathlib import Path
  7. from multiprocessing.pool import ThreadPool
  8. clang_tidy_cmd = None
  9. for version in range(15, 5, -1):
  10. clang_tidy_cmd = f"clang-tidy-{version}"
  11. if subp.run(("which", clang_tidy_cmd), stdout=subp.DEVNULL).returncode == 0:
  12. break
  13. project_dir = Path(__file__).resolve().parents[1]
  14. assert project_dir.exists()
  15. boost_dir = project_dir.parents[1]
  16. filenames = (project_dir / "include").rglob("*.hpp")
  17. def run_tidy(filename):
  18. n = len(project_dir.parts) + 2
  19. cmd = f"{clang_tidy_cmd} {filename} -- -I{boost_dir}"
  20. return (
  21. cmd,
  22. subp.run(cmd.split(), stdout=subp.PIPE, stderr=subp.STDOUT).stdout.decode(
  23. "utf-8"
  24. ),
  25. )
  26. pool = ThreadPool()
  27. for cmd, report in pool.map(run_tidy, filenames):
  28. if report:
  29. print(cmd)
  30. print(report)