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