[clang-tools-extra] r327854 - run-clang-tidy: forward clang-tidy exit status

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 19 07:43:59 PDT 2018


Author: vmiklos
Date: Mon Mar 19 07:43:59 2018
New Revision: 327854

URL: http://llvm.org/viewvc/llvm-project?rev=327854&view=rev
Log:
run-clang-tidy: forward clang-tidy exit status

Exit with a non-zero value in case any of the underlying clang-tidy
invocations exit with a non-zero value.

This is useful in case WarningsAsErrors is enabled for some of the
checks: if any of those checks find something, the exit status now
reflects that.

Also add the ability to use run-clang-tidy.py via lit, and assert that
the exit code is not 0 when modernize-use-auto is triggered
intentionally.

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D44366

Added:
    clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
    clang-tools-extra/trunk/test/lit.cfg

Modified: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py?rev=327854&r1=327853&r2=327854&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py Mon Mar 19 07:43:59 2018
@@ -153,7 +153,7 @@ def apply_fixes(args, tmpdir):
   subprocess.call(invocation)
 
 
-def run_tidy(args, tmpdir, build_path, queue):
+def run_tidy(args, tmpdir, build_path, queue, failed_files):
   """Takes filenames out of queue and runs clang-tidy on them."""
   while True:
     name = queue.get()
@@ -162,7 +162,9 @@ def run_tidy(args, tmpdir, build_path, q
                                      args.extra_arg, args.extra_arg_before,
                                      args.quiet, args.config)
     sys.stdout.write(' '.join(invocation) + '\n')
-    subprocess.call(invocation)
+    return_code = subprocess.call(invocation)
+    if return_code != 0:
+      failed_files.append(name)
     queue.task_done()
 
 
@@ -255,12 +257,15 @@ def main():
   # Build up a big regexy filter from all command line arguments.
   file_name_re = re.compile('|'.join(args.files))
 
+  return_code = 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 = []
     for _ in range(max_task):
       t = threading.Thread(target=run_tidy,
-                           args=(args, tmpdir, build_path, task_queue))
+                           args=(args, tmpdir, build_path, task_queue, failed_files))
       t.daemon = True
       t.start()
 
@@ -271,6 +276,8 @@ def main():
 
     # Wait for all threads to be done.
     task_queue.join()
+    if len(failed_files):
+      return_code = 1
 
   except KeyboardInterrupt:
     # This is a sad hack. Unfortunately subprocess goes
@@ -280,7 +287,6 @@ def main():
       shutil.rmtree(tmpdir)
     os.kill(0, 9)
 
-  return_code = 0
   if args.export_fixes:
     print('Writing fixes to ' + args.export_fixes + ' ...')
     try:

Added: clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp?rev=327854&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/run-clang-tidy.cpp Mon Mar 19 07:43:59 2018
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %/t/test.cpp\",\"file\":\"%/t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
+// RUN: echo "Checks: '-*,modernize-use-auto'" > %t/.clang-tidy
+// RUN: echo "WarningsAsErrors: '*'" >> %t/.clang-tidy
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: cd "%t"
+// RUN: not %run_clang_tidy "%t/test.cpp"
+
+int main()
+{
+  int* x = new int();
+  delete x;
+}

Modified: clang-tools-extra/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/lit.cfg?rev=327854&r1=327853&r2=327854&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/lit.cfg (original)
+++ clang-tools-extra/trunk/test/lit.cfg Mon Mar 19 07:43:59 2018
@@ -129,6 +129,11 @@ if config.clang_staticanalyzer:
     config.substitutions.append(
         ('%clang_tidy_diff',
          '%s %s' % (config.python_executable, clang_tidy_diff)) )
+    run_clang_tidy = os.path.join(
+        config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py")
+    config.substitutions.append(
+        ('%run_clang_tidy',
+         '%s %s' % (config.python_executable, run_clang_tidy)) )
 else:
     # exclude the clang-tidy test directory
     config.excludes.append('clang-tidy')




More information about the cfe-commits mailing list