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 7import subprocess as subp 8from pathlib import Path 9from multiprocessing.pool import ThreadPool 10 11clang_tidy_cmd = None 12for 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 17project_dir = Path(__file__).resolve().parents[1] 18assert project_dir.exists() 19boost_dir = project_dir.parents[1] 20 21filenames = (project_dir / "include").rglob("*.hpp") 22 23 24def 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 35pool = ThreadPool() 36for cmd, report in pool.map(run_tidy, filenames): 37 if report: 38 print(cmd) 39 print(report) 40