Run clang-tidy on a single file.
(
file: Path,
compile_commands: Path,
fix: bool,
extra_args: List[str],
semaphore: asyncio.Semaphore
)
| 90 | |
| 91 | |
| 92 | async def lint_file( |
| 93 | file: Path, |
| 94 | compile_commands: Path, |
| 95 | fix: bool, |
| 96 | extra_args: List[str], |
| 97 | semaphore: asyncio.Semaphore |
| 98 | ) -> Tuple[Path, bool, str]: |
| 99 | """Run clang-tidy on a single file.""" |
| 100 | async with semaphore: |
| 101 | cmd = [ |
| 102 | "clang-tidy", |
| 103 | f"-p={compile_commands}", |
| 104 | *extra_args, |
| 105 | ] |
| 106 | |
| 107 | if fix: |
| 108 | cmd.extend(["--fix", "--fix-errors"]) |
| 109 | |
| 110 | cmd.append(str(file)) |
| 111 | |
| 112 | proc = await asyncio.create_subprocess_exec( |
| 113 | *cmd, |
| 114 | stdout=asyncio.subprocess.PIPE, |
| 115 | stderr=asyncio.subprocess.PIPE |
| 116 | ) |
| 117 | |
| 118 | stdout, stderr = await proc.communicate() |
| 119 | |
| 120 | output = stdout.decode() + stderr.decode() |
| 121 | success = proc.returncode == 0 |
| 122 | |
| 123 | return file, success, output |
| 124 | |
| 125 | |
| 126 | async def lint_all_files(files: List[Path], compile_commands: Path, fix: bool, jobs: int): |