[clang-tools-extra] r248723 - [clang-tidy] add option to specify build path

Guillaume Papin via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 28 10:53:04 PDT 2015


Author: papin_g
Date: Mon Sep 28 12:53:04 2015
New Revision: 248723

URL: http://llvm.org/viewvc/llvm-project?rev=248723&view=rev
Log:
[clang-tidy] add option to specify build path

Summary:
compile_commands.json is usually generated in the build directory.
Projects like LLVM/Clang enforce out-of-source builds.
This option allow allow such projects to work out of the box, without
moving the compilation database manually.

The naming of the option is similar to the one use by other tools:

    clang-{check,modernize,query,rename,tidy} -p=<build_path> <...>

Reviewers: alexfh

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

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

Modified: clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py?rev=248723&r1=248722&r2=248723&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py Mon Sep 28 12:53:04 2015
@@ -128,10 +128,21 @@ def main():
   parser.add_argument('-fix', action='store_true', help='apply fix-its')
   parser.add_argument('-format', action='store_true', help='Reformat code '
                       'after applying fixes')
+  parser.add_argument('-p', dest='build_path',
+                      help='Path used to read a compile command database.')
   args = parser.parse_args()
 
+  db_path = 'compile_commands.json'
+
+  if args.build_path is not None:
+    build_path = args.build_path
+  else:
+    # Find our database
+    build_path = find_compilation_database(db_path)
+
   try:
     invocation = [args.clang_tidy_binary, '-list-checks']
+    invocation.append('-p=' + build_path)
     if args.checks:
       invocation.append('-checks=' + args.checks)
     invocation.append('-')
@@ -140,10 +151,6 @@ def main():
     print >>sys.stderr, "Unable to run clang-tidy."
     sys.exit(1)
 
-  # Find our database.
-  db_path = 'compile_commands.json'
-  build_path = find_compilation_database(db_path)
-
   # Load the database and extract all files.
   database = json.load(open(os.path.join(build_path, db_path)))
   files = [entry['file'] for entry in database]




More information about the cfe-commits mailing list