[PATCH] D39141: [clang-tidy] New argument --language to add_new_check.py

Ben Hamilton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 13:54:47 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL323919: [clang-tidy] New argument --language to add_new_check.py (authored by benhamilton, committed by ).
Herald added subscribers: llvm-commits, klimek.

Repository:
  rL LLVM

https://reviews.llvm.org/D39141

Files:
  clang-tools-extra/trunk/clang-tidy/add_new_check.py


Index: clang-tools-extra/trunk/clang-tidy/add_new_check.py
===================================================================
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py
@@ -9,6 +9,7 @@
 #
 #===------------------------------------------------------------------------===#
 
+import argparse
 import os
 import re
 import sys
@@ -221,10 +222,10 @@
 
 
 # Adds a test for the check.
-def write_test(module_path, module, check_name):
+def write_test(module_path, module, check_name, test_extension):
   check_name_dashes = module + '-' + check_name
   filename = os.path.normpath(os.path.join(module_path, '../../test/clang-tidy',
-                                           check_name_dashes + '.cpp'))
+                                           check_name_dashes + '.' + test_extension))
   print('Creating %s...' % filename)
   with open(filename, 'wb') as f:
     f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
@@ -300,22 +301,37 @@
 
 
 def main():
-  if len(sys.argv) == 2 and sys.argv[1] == '--update-docs':
-    update_checks_list(os.path.dirname(sys.argv[0]))
-    return
-
-  if len(sys.argv) != 3:
-    print """\
-Usage: add_new_check.py <module> <check>, e.g.
-  add_new_check.py misc awesome-functions
-
-Alternatively, run 'add_new_check.py --update-docs' to just update the list of
-documentation files."""
+  language_to_extension = {
+      'c': 'c',
+      'c++': 'cpp',
+      'objc': 'm',
+      'objc++': 'mm',
+  }
+  parser = argparse.ArgumentParser()
+  parser.add_argument(
+      '--update-docs',
+      action='store_true',
+      help='just update the list of documentation files, then exit')
+  parser.add_argument(
+      '--language',
+      help='language to use for new check (defaults to c++)',
+      choices=language_to_extension.keys(),
+      default='c++',
+      metavar='LANG')
+  parser.add_argument(
+      'module',
+      help='module directory under which to place the new tidy check (e.g., misc)')
+  parser.add_argument(
+      'check',
+      help='name of new tidy check to add (e.g. foo-do-the-stuff)')
+  args = parser.parse_args()
 
+  if args.update_docs:
+    update_checks_list(os.path.dirname(sys.argv[0]))
     return
 
-  module = sys.argv[1]
-  check_name = sys.argv[2]
+  module = args.module
+  check_name = args.check
 
   if check_name.startswith(module):
     print 'Check name "%s" must not start with the module "%s". Exiting.' % (
@@ -332,7 +348,8 @@
   write_implementation(module_path, module, check_name_camel)
   adapt_module(module_path, module, check_name, check_name_camel)
   add_release_notes(module_path, module, check_name)
-  write_test(module_path, module, check_name)
+  test_extension = language_to_extension.get(args.language)
+  write_test(module_path, module, check_name, test_extension)
   write_docs(module_path, module, check_name)
   update_checks_list(clang_tidy_path)
   print('Done. Now it\'s your turn!')


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39141.132270.patch
Type: text/x-patch
Size: 2987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180131/f2bc7391/attachment.bin>


More information about the llvm-commits mailing list