[PATCH] D120331: [clang-tidy][run-clang-tidy.py] Add --config-file=<string> option

Shreyas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 22 08:32:08 PST 2022


SAtacker created this revision.
SAtacker added a reviewer: JonasToth.
Herald added subscribers: carlosgalvezp, xazax.hun.
SAtacker requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

- Link to the GitHub Issue: https://github.com/llvm/llvm-project/issues/53745

Details:

- Added config_path variable within the python script which makes the required call to the clang-tidy binary with --config-file option.
- If the config_path is None then config will be used.
- No error is raised if both are given but silently chooses config_path over config

Signed-off-by: Shreyas Atre <shreyasatre16 at gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120331

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
@@ -96,8 +96,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,
-                        line_filter, use_color):
+                        extra_arg, extra_arg_before, quiet, config_path, 
+                        config, line_filter, use_color):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if allow_enabling_alpha_checkers:
@@ -127,7 +127,9 @@
   start.append('-p=' + build_path)
   if quiet:
       start.append('-quiet')
-  if config:
+  if config_path:
+      start.append('--config-file=' + config_path)
+  elif config:
       start.append('-config=' + config)
   start.append(f)
   return start
@@ -188,8 +190,8 @@
                                      tmpdir, build_path, args.header_filter,
                                      args.allow_enabling_alpha_checkers,
                                      args.extra_arg, args.extra_arg_before,
-                                     args.quiet, args.config, args.line_filter,
-                                     args.use_color)
+                                     args.quiet, args.config_path, args.config,
+                                     args.line_filter, args.use_color)
 
     proc = subprocess.Popen(invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     output, err = proc.communicate()
@@ -231,6 +233,12 @@
                       'When the value is empty, clang-tidy will '
                       'attempt to find a file named .clang-tidy for '
                       'each source file in its parent directories.')
+  parser.add_argument('-config-file', default=None,
+                      help='Specify the path of .clang-tidy or custom config'
+                      'file: e.g. -config-file=/some/path/myTidyConfigFile'
+                      'This option internally works exactly the same way as'
+                      '-config option after reading specified config file.'
+                      'Use either -config-file or -config, not both.')
   parser.add_argument('-header-filter', default=None,
                       help='regular expression matching the names of the '
                       'headers to output diagnostics from. Diagnostics from '
@@ -283,8 +291,8 @@
                                      None, build_path, args.header_filter,
                                      args.allow_enabling_alpha_checkers,
                                      args.extra_arg, args.extra_arg_before,
-                                     args.quiet, args.config, args.line_filter,
-                                     args.use_color)
+                                     args.quiet, args.config_path, args.config, 
+                                     args.line_filter, args.use_color)
     invocation.append('-list-checks')
     invocation.append('-')
     if args.quiet:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120331.410547.patch
Type: text/x-patch
Size: 3210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220222/f1656484/attachment-0001.bin>


More information about the cfe-commits mailing list