[PATCH] D158929: [clang-tidy] Add exit code support to clang-tidy-diff.py
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 28 13:02:26 PDT 2023
PiotrZSL updated this revision to Diff 554028.
PiotrZSL marked 2 inline comments as done.
PiotrZSL added a comment.
Fix some Pylint issues.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158929/new/
https://reviews.llvm.org/D158929
Files:
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
clang-tools-extra/docs/ReleaseNotes.rst
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,10 @@
- Improved `--dump-config` to print check options in alphabetical order.
+- Improved :program:`clang-tidy-diff.py` script. It now returns exit code `1`
+ if any :program:`clang-tidy` subprocess exits with a non-zero code or if
+ exporting fixes fails.
+
New checks
^^^^^^^^^^
Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
===================================================================
--- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -49,7 +49,7 @@
import queue as queue
-def run_tidy(task_queue, lock, timeout):
+def run_tidy(task_queue, lock, timeout, failed_files):
watchdog = None
while True:
command = task_queue.get()
@@ -63,6 +63,14 @@
watchdog.start()
stdout, stderr = proc.communicate()
+ if proc.returncode != 0:
+ if proc.returncode < 0:
+ msg = "Terminated by signal %d : %s\n" % (
+ -proc.returncode,
+ " ".join(command),
+ )
+ stderr += msg.encode("utf-8")
+ failed_files.append(command)
with lock:
sys.stdout.write(stdout.decode("utf-8") + "\n")
@@ -84,9 +92,9 @@
task_queue.task_done()
-def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+def start_workers(max_tasks, tidy_caller, arguments):
for _ in range(max_tasks):
- t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+ t = threading.Thread(target=tidy_caller, args=arguments)
t.daemon = True
t.start()
@@ -259,8 +267,13 @@
# A lock for console output.
lock = threading.Lock()
+ # List of files with a non-zero return code.
+ failed_files = []
+
# Run a pool of clang-tidy workers.
- start_workers(max_task_count, run_tidy, task_queue, lock, args.timeout)
+ start_workers(
+ max_task_count, run_tidy, (task_queue, lock, args.timeout, failed_files)
+ )
# Form the common args list.
common_clang_tidy_args = []
@@ -301,8 +314,15 @@
task_queue.put(command)
+ # Application return code
+ return_code = 0
+
# Wait for all threads to be done.
task_queue.join()
+ # Application return code
+ return_code = 0
+ if failed_files:
+ return_code = 1
if yaml and args.export_fixes:
print("Writing fixes to " + args.export_fixes + " ...")
@@ -311,9 +331,11 @@
except:
sys.stderr.write("Error exporting fixes.\n")
traceback.print_exc()
+ return_code = 1
if tmpdir:
shutil.rmtree(tmpdir)
+ sys.exit(return_code)
if __name__ == "__main__":
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158929.554028.patch
Type: text/x-patch
Size: 3033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230828/c8ad2b35/attachment.bin>
More information about the cfe-commits
mailing list