Skip to content

Commit 68b5910

Browse files
committedSep 28, 2015
[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
1 parent 36c42b5 commit 68b5910

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,21 @@ def main():
128128
parser.add_argument('-fix', action='store_true', help='apply fix-its')
129129
parser.add_argument('-format', action='store_true', help='Reformat code '
130130
'after applying fixes')
131+
parser.add_argument('-p', dest='build_path',
132+
help='Path used to read a compile command database.')
131133
args = parser.parse_args()
132134

135+
db_path = 'compile_commands.json'
136+
137+
if args.build_path is not None:
138+
build_path = args.build_path
139+
else:
140+
# Find our database
141+
build_path = find_compilation_database(db_path)
142+
133143
try:
134144
invocation = [args.clang_tidy_binary, '-list-checks']
145+
invocation.append('-p=' + build_path)
135146
if args.checks:
136147
invocation.append('-checks=' + args.checks)
137148
invocation.append('-')
@@ -140,10 +151,6 @@ def main():
140151
print >>sys.stderr, "Unable to run clang-tidy."
141152
sys.exit(1)
142153

143-
# Find our database.
144-
db_path = 'compile_commands.json'
145-
build_path = find_compilation_database(db_path)
146-
147154
# Load the database and extract all files.
148155
database = json.load(open(os.path.join(build_path, db_path)))
149156
files = [entry['file'] for entry in database]

0 commit comments

Comments
 (0)