Format script/clang-tidy

This commit is contained in:
Jesse Hills 2024-04-30 16:38:01 +12:00
parent 05fbb260ee
commit f96aff5107
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A

View file

@ -1,21 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from helpers import (
print_error_for_file,
get_output,
filter_grep,
build_all_include,
temp_header_file,
git_ls_files,
filter_changed,
load_idedata,
root_path,
basepath,
get_binary,
)
import argparse import argparse
import click
import colorama
import multiprocessing import multiprocessing
import os import os
import queue import queue
@ -26,6 +11,20 @@ import sys
import tempfile import tempfile
import threading import threading
from helpers import (
print_error_for_file,
filter_grep,
build_all_include,
temp_header_file,
git_ls_files,
filter_changed,
load_idedata,
root_path,
basepath,
get_binary,
)
import click
import colorama
def clang_options(idedata): def clang_options(idedata):
@ -114,9 +113,10 @@ def clang_options(idedata):
pids = set() pids = set()
def run_tidy(executable, args, options, tmpdir, queue, lock, failed_files):
def run_tidy(executable, args, options, tmpdir, task_queue, lock, failed_files):
while True: while True:
path = queue.get() path = task_queue.get()
invocation = [executable] invocation = [executable]
if tmpdir is not None: if tmpdir is not None:
@ -138,12 +138,14 @@ def run_tidy(executable, args, options, tmpdir, queue, lock, failed_files):
invocation.append("--") invocation.append("--")
invocation.extend(options) invocation.extend(options)
proc = subprocess.run(invocation, capture_output=True, encoding="utf-8") proc = subprocess.run(
invocation, capture_output=True, encoding="utf-8", check=False
)
if proc.returncode != 0: if proc.returncode != 0:
with lock: with lock:
print_error_for_file(path, proc.stdout) print_error_for_file(path, proc.stdout)
failed_files.append(path) failed_files.append(path)
queue.task_done() task_queue.task_done()
def progress_bar_show(value): def progress_bar_show(value):
@ -236,7 +238,15 @@ def main():
for _ in range(args.jobs): for _ in range(args.jobs):
t = threading.Thread( t = threading.Thread(
target=run_tidy, target=run_tidy,
args=(executable, args, options, tmpdir, task_queue, lock, failed_files), args=(
executable,
args,
options,
tmpdir,
task_queue,
lock,
failed_files,
),
) )
t.daemon = True t.daemon = True
t.start() t.start()
@ -244,14 +254,14 @@ def main():
# Fill the queue with files. # Fill the queue with files.
with click.progressbar( with click.progressbar(
files, width=30, file=sys.stderr, item_show_func=progress_bar_show files, width=30, file=sys.stderr, item_show_func=progress_bar_show
) as bar: ) as progressbar:
for name in bar: for name in progressbar:
task_queue.put(name) task_queue.put(name)
# Wait for all threads to be done. # Wait for all threads to be done.
task_queue.join() task_queue.join()
except FileNotFoundError as ex: except FileNotFoundError:
return 1 return 1
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
@ -261,7 +271,7 @@ def main():
# Kill subprocesses (and ourselves!) # Kill subprocesses (and ourselves!)
# No simple, clean alternative appears to be available. # No simple, clean alternative appears to be available.
os.kill(0, 9) os.kill(0, 9)
return 2 # Will not execute. return 2 # Will not execute.
if args.fix and failed_files: if args.fix and failed_files:
print("Applying fixes ...") print("Applying fixes ...")