[clang-tools-extra] [run-clang-tidy.py] Refactor, add progress indicator, add type hints (PR #89490)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 27 12:44:56 PDT 2024
================
@@ -488,70 +493,72 @@ def main():
# Build up a big regexy filter from all command line arguments.
file_name_re = re.compile("|".join(args.files))
+ files = {f for f in files if file_name_re.search(f)}
- return_code = 0
+ returncode = 0
try:
- # Spin up a bunch of tidy-launching threads.
- task_queue = queue.Queue(max_task)
- # List of files with a non-zero return code.
- failed_files = []
- lock = threading.Lock()
- for _ in range(max_task):
- t = threading.Thread(
- target=run_tidy,
- args=(
- args,
- clang_tidy_binary,
- export_fixes_dir,
- build_path,
- task_queue,
- lock,
- failed_files,
- ),
+ semaphore = asyncio.Semaphore(max_task)
+ tasks = [
+ run_with_semaphore(
+ semaphore,
+ run_tidy,
+ args,
+ f,
+ clang_tidy_binary,
+ export_fixes_dir,
+ build_path,
)
- t.daemon = True
- t.start()
-
- # Fill the queue with files.
- for name in files:
- if file_name_re.search(name):
- task_queue.put(name)
-
- # Wait for all threads to be done.
- task_queue.join()
- if len(failed_files):
- return_code = 1
-
+ for f in files
+ ]
+
+ for i, coro in enumerate(asyncio.as_completed(tasks)):
+ name, process_returncode, stdout, stderr = await coro
+ if process_returncode != 0:
+ returncode = 1
+ if process_returncode < 0:
+ stderr += f"{name}: terminated by signal {-process_returncode}\n"
+ print(f"[{i + 1}/{len(files)}] {name}")
+ if stdout:
+ print(stdout)
+ if stderr:
+ print(stderr, file=sys.stderr)
----------------
PiotrZSL wrote:
Make sure to add flush to both buffers after printing.
https://github.com/llvm/llvm-project/pull/89490
More information about the cfe-commits
mailing list