[PATCH] D90535: [clang-tidy] Allow -warnings-as-errors to be specified from run_clang_tidy.py

Christian Schärf via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 31 09:12:11 PDT 2020


schaerfo created this revision.
schaerfo added a reviewer: alexfh.
schaerfo added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
schaerfo requested review of this revision.

This patch adds a `-warnings-as-errors` option to run_clang_tidy.py, which is forwarded to clang-tidy itself. This is done similar to the `-header-filter` option (as well as some others).

The rationale behind this is that previously, promoting warnings to errors when using run_clang_tidy was only possible through the .clang-tidy file and the `-config` option (which, however, overrides what is specified in .clang-tidy) and thus could not be changed without modifying this file. This comes in handy e. g. for CI, when you want the run to fail if certain warnings are emitted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90535

Files:
  clang-tools-extra/clang-tidy/tool/run-clang-tidy.py


Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -81,7 +81,8 @@
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
                         header_filter, allow_enabling_alpha_checkers,
-                        extra_arg, extra_arg_before, quiet, config):
+                        extra_arg, extra_arg_before, quiet, config,
+                        warnings_as_errors):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
@@ -106,6 +107,8 @@
       start.append('-quiet')
   if config:
       start.append('-config=' + config)
+  if warnings_as_errors:
+      start.append('-warnings-as-errors=' + warnings_as_errors)
   start.append(f)
   return start
 
@@ -165,7 +168,7 @@
                                      tmpdir, build_path, args.header_filter,
                                      args.allow_enabling_alpha_checkers,
                                      args.extra_arg, args.extra_arg_before,
-                                     args.quiet, args.config)
+                                     args.quiet, args.config, args.warnings_as_errors)
 
     proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     output, err = proc.communicate()
@@ -234,6 +237,9 @@
                       'command line.')
   parser.add_argument('-quiet', action='store_true',
                       help='Run clang-tidy in quiet mode')
+  parser.add_argument('-warnings-as-errors', default=None,
+                      help='Upgrades warnings to errors. Does not enable '
+                      'any warnings py itself.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90535.302097.patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201031/fb01a33b/attachment.bin>


More information about the cfe-commits mailing list