[PATCH] D23476: Allow manual specification of the binary directory in check_clang_tidy.py

Zachary Turner via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 16:47:47 PDT 2016


zturner created this revision.
zturner added reviewers: alexfh, djasper.
zturner added a subscriber: cfe-commits.

When you run the script from lit it starts in the right directory so it can find `FileCheck` and `clang-tidy`, but when you manually run `check-clang-tidy.py` from a command line it doesn't work unless you put yourself in the bin directory beforehand.  This isn't always convenient, so allow specifying the bin directory as an option to `check_clang_tidy.py`

https://reviews.llvm.org/D23476

Files:
  test/clang-tidy/check_clang_tidy.py

Index: test/clang-tidy/check_clang_tidy.py
===================================================================
--- test/clang-tidy/check_clang_tidy.py
+++ test/clang-tidy/check_clang_tidy.py
@@ -25,6 +25,7 @@
 """
 
 import argparse
+import os
 import re
 import subprocess
 import sys
@@ -41,13 +42,15 @@
   parser.add_argument('input_file_name')
   parser.add_argument('check_name')
   parser.add_argument('temp_file_name')
+  parser.add_argument('--bin-dir', '-b', default='.', help='Directory containing clang-tidy and FileCheck executables')
 
   args, extra_args = parser.parse_known_args()
 
   resource_dir = args.resource_dir
   input_file_name = args.input_file_name
   check_name = args.check_name
   temp_file_name = args.temp_file_name
+  bin_dir = args.bin_dir
 
   extension = '.cpp'
   if (input_file_name.endswith('.c')):
@@ -83,7 +86,8 @@
   original_file_name = temp_file_name + ".orig"
   write_file(original_file_name, cleaned_test)
 
-  args = ['clang-tidy', temp_file_name, '-fix', '--checks=-*,' + check_name] + \
+  executable = os.path.join(bin_dir, 'clang-tidy')
+  args = [executable, temp_file_name, '-fix', '--checks=-*,' + check_name] + \
         clang_tidy_extra_args
   print('Running ' + repr(args) + '...')
   try:
@@ -108,10 +112,11 @@
         diff_output.decode() +
         '\n------------------------------------------------------------------')
 
+  file_check_exe = os.path.join(bin_dir, 'FileCheck')
   if has_check_fixes:
     try:
       subprocess.check_output(
-          ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
+          [file_check_exe, '-input-file=' + temp_file_name, input_file_name,
            '-check-prefix=CHECK-FIXES', '-strict-whitespace'],
           stderr=subprocess.STDOUT)
     except subprocess.CalledProcessError as e:
@@ -123,7 +128,7 @@
     write_file(messages_file, clang_tidy_output)
     try:
       subprocess.check_output(
-          ['FileCheck', '-input-file=' + messages_file, input_file_name,
+          [file_check_exe, '-input-file=' + messages_file, input_file_name,
            '-check-prefix=CHECK-MESSAGES',
            '-implicit-check-not={{warning|error}}:'],
           stderr=subprocess.STDOUT)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23476.67939.patch
Type: text/x-patch
Size: 2209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160812/8395971e/attachment.bin>


More information about the cfe-commits mailing list