ehsan created this revision.
ehsan added reviewers: bkramer, alexfh, klimek.
ehsan added a subscriber: cfe-commits.
Herald added a subscriber: JDevlieghere.

These flags allow specifying extra arguments to the tool's command
line which don't appear in the compilation database.


https://reviews.llvm.org/D28334

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


Index: clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tidy/tool/run-clang-tidy.py
+++ clang-tidy/tool/run-clang-tidy.py
@@ -59,7 +59,7 @@
 
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
-                        header_filter):
+                        header_filter, extra_arg, extra_arg_before):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -76,6 +76,10 @@
     (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
     os.close(handle)
     start.append(name)
+  for arg in extra_arg:
+      start.append('-extra-arg=%s' % arg[0])
+  for arg in extra_arg_before:
+      start.append('-extra-arg-before=%s' % arg[0])
   start.append('-p=' + build_path)
   start.append(f)
   return start
@@ -96,7 +100,8 @@
   while True:
     name = queue.get()
     invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
-                                     tmpdir, build_path, args.header_filter)
+                                     tmpdir, build_path, args.header_filter,
+                                     args.extra_arg, args.extra_arg_before)
     sys.stdout.write(' '.join(invocation) + '\n')
     subprocess.call(invocation)
     queue.task_done()
@@ -130,6 +135,14 @@
                       'after applying fixes')
   parser.add_argument('-p', dest='build_path',
                       help='Path used to read a compile command database.')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+                      nargs=1, action='append', default=[],
+                      help='Additional argument to append to the compiler '
+                      'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+                      nargs=1, action='append', default=[],
+                      help='Additional argument to prepend to the compiler '
+                      'command line.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'


Index: clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tidy/tool/run-clang-tidy.py
+++ clang-tidy/tool/run-clang-tidy.py
@@ -59,7 +59,7 @@
 
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
-                        header_filter):
+                        header_filter, extra_arg, extra_arg_before):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -76,6 +76,10 @@
     (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
     os.close(handle)
     start.append(name)
+  for arg in extra_arg:
+      start.append('-extra-arg=%s' % arg[0])
+  for arg in extra_arg_before:
+      start.append('-extra-arg-before=%s' % arg[0])
   start.append('-p=' + build_path)
   start.append(f)
   return start
@@ -96,7 +100,8 @@
   while True:
     name = queue.get()
     invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
-                                     tmpdir, build_path, args.header_filter)
+                                     tmpdir, build_path, args.header_filter,
+                                     args.extra_arg, args.extra_arg_before)
     sys.stdout.write(' '.join(invocation) + '\n')
     subprocess.call(invocation)
     queue.task_done()
@@ -130,6 +135,14 @@
                       'after applying fixes')
   parser.add_argument('-p', dest='build_path',
                       help='Path used to read a compile command database.')
+  parser.add_argument('-extra-arg', dest='extra_arg',
+                      nargs=1, action='append', default=[],
+                      help='Additional argument to append to the compiler '
+                      'command line.')
+  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
+                      nargs=1, action='append', default=[],
+                      help='Additional argument to prepend to the compiler '
+                      'command line.')
   args = parser.parse_args()
 
   db_path = 'compile_commands.json'
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to