[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
llvm-svn: 248723
diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 73c5140..e4dd3da 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -128,10 +128,21 @@
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 @@
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]