[clang-tools-extra] b1f1688 - [clang-tidy] support --load in clang-tidy-diff.py/run-clang-tidy.py

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 04:51:33 PDT 2022


Author: Bernhard Manfred Gruber
Date: 2022-04-28T13:49:18+02:00
New Revision: b1f1688e90b22dedc829f5abc9a912f18c034fbc

URL: https://github.com/llvm/llvm-project/commit/b1f1688e90b22dedc829f5abc9a912f18c034fbc
DIFF: https://github.com/llvm/llvm-project/commit/b1f1688e90b22dedc829f5abc9a912f18c034fbc.diff

LOG: [clang-tidy] support --load in clang-tidy-diff.py/run-clang-tidy.py

Support for loading shared objects as plugins into clang-tidy was added
in http://reviews.llvm.org/D111100. Unfortunately, the utility scripts
`clang-tidy-diff.py` and `run-clang-tidy.py` did not receive
corresponding arguments to forward such plugins to clang-tidy.
This diff adds a `-load=plugin` option to both scripts.

Differential Revision: http://reviews.llvm.org/D12306

Reviewed By: aaron.ballman

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
    clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
index 6bd05531333ba..a26d2144b7f97 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
@@ -160,6 +160,10 @@ def main():
                       'command line.')
   parser.add_argument('-quiet', action='store_true', default=False,
                       help='Run clang-tidy in quiet mode')
+  parser.add_argument('-load', dest='plugins',
+                      action='append', default=[],
+                      help='Load the specified plugin in clang-tidy.')
+
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
@@ -233,6 +237,8 @@ def main():
     common_clang_tidy_args.append('-extra-arg=%s' % arg)
   for arg in args.extra_arg_before:
     common_clang_tidy_args.append('-extra-arg-before=%s' % arg)
+  for plugin in args.plugins:
+    common_clang_tidy_args.append('-load=%s' % plugin)
 
   for name in lines_by_file:
     line_filter_json = json.dumps(

diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 9497e0b9f52d3..fdfe5a07bc551 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -92,7 +92,7 @@ def make_absolute(f, directory):
 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_file_path,
-                        config, line_filter, use_color):
+                        config, line_filter, use_color, plugins):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
@@ -126,6 +126,8 @@ def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
       start.append('--config-file=' + config_file_path)
   elif config:
       start.append('-config=' + config)
+  for plugin in plugins:
+      start.append('-load=' + plugin)
   start.append(f)
   return start
 
@@ -196,7 +198,8 @@ def run_tidy(args, clang_tidy_binary, tmpdir, build_path, queue, lock,
                                      args.allow_enabling_alpha_checkers,
                                      args.extra_arg, args.extra_arg_before,
                                      args.quiet, args.config_file, args.config,
-                                     args.line_filter, args.use_color)
+                                     args.line_filter, args.use_color,
+                                     args.plugins)
 
     proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     output, err = proc.communicate()
@@ -280,6 +283,9 @@ def main():
                       'command line.')
   parser.add_argument('-quiet', action='store_true',
                       help='Run clang-tidy in quiet mode')
+  parser.add_argument('-load', dest='plugins',
+                      action='append', default=[],
+                      help='Load the specified plugin in clang-tidy.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'
@@ -306,7 +312,8 @@ def main():
                                      args.allow_enabling_alpha_checkers,
                                      args.extra_arg, args.extra_arg_before,
                                      args.quiet, args.config_file, args.config,
-                                     args.line_filter, args.use_color)
+                                     args.line_filter, args.use_color,
+                                     args.plugins)
     invocation.append('-list-checks')
     invocation.append('-')
     if args.quiet:


        


More information about the cfe-commits mailing list