Skip to content

Commit 10fe9bc

Browse files
committedMar 19, 2018
run-clang-tidy: forward clang-tidy exit status
Exit with a non-zero value in case any of the underlying clang-tidy invocations exit with a non-zero value. This is useful in case WarningsAsErrors is enabled for some of the checks: if any of those checks find something, the exit status now reflects that. Also add the ability to use run-clang-tidy.py via lit, and assert that the exit code is not 0 when modernize-use-auto is triggered intentionally. Reviewers: alexfh, aaron.ballman Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D44366 llvm-svn: 327854
1 parent 05daae7 commit 10fe9bc

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
 

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def apply_fixes(args, tmpdir):
153153
subprocess.call(invocation)
154154

155155

156-
def run_tidy(args, tmpdir, build_path, queue):
156+
def run_tidy(args, tmpdir, build_path, queue, failed_files):
157157
"""Takes filenames out of queue and runs clang-tidy on them."""
158158
while True:
159159
name = queue.get()
@@ -162,7 +162,9 @@ def run_tidy(args, tmpdir, build_path, queue):
162162
args.extra_arg, args.extra_arg_before,
163163
args.quiet, args.config)
164164
sys.stdout.write(' '.join(invocation) + '\n')
165-
subprocess.call(invocation)
165+
return_code = subprocess.call(invocation)
166+
if return_code != 0:
167+
failed_files.append(name)
166168
queue.task_done()
167169

168170

@@ -255,12 +257,15 @@ def main():
255257
# Build up a big regexy filter from all command line arguments.
256258
file_name_re = re.compile('|'.join(args.files))
257259

260+
return_code = 0
258261
try:
259262
# Spin up a bunch of tidy-launching threads.
260263
task_queue = queue.Queue(max_task)
264+
# List of files with a non-zero return code.
265+
failed_files = []
261266
for _ in range(max_task):
262267
t = threading.Thread(target=run_tidy,
263-
args=(args, tmpdir, build_path, task_queue))
268+
args=(args, tmpdir, build_path, task_queue, failed_files))
264269
t.daemon = True
265270
t.start()
266271

@@ -271,6 +276,8 @@ def main():
271276

272277
# Wait for all threads to be done.
273278
task_queue.join()
279+
if len(failed_files):
280+
return_code = 1
274281

275282
except KeyboardInterrupt:
276283
# This is a sad hack. Unfortunately subprocess goes
@@ -280,7 +287,6 @@ def main():
280287
shutil.rmtree(tmpdir)
281288
os.kill(0, 9)
282289

283-
return_code = 0
284290
if args.export_fixes:
285291
print('Writing fixes to ' + args.export_fixes + ' ...')
286292
try:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %/t/test.cpp\",\"file\":\"%/t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
4+
// RUN: echo "Checks: '-*,modernize-use-auto'" > %t/.clang-tidy
5+
// RUN: echo "WarningsAsErrors: '*'" >> %t/.clang-tidy
6+
// RUN: cp "%s" "%t/test.cpp"
7+
// RUN: cd "%t"
8+
// RUN: not %run_clang_tidy "%t/test.cpp"
9+
10+
int main()
11+
{
12+
int* x = new int();
13+
delete x;
14+
}

‎clang-tools-extra/test/lit.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ if config.clang_staticanalyzer:
129129
config.substitutions.append(
130130
('%clang_tidy_diff',
131131
'%s %s' % (config.python_executable, clang_tidy_diff)) )
132+
run_clang_tidy = os.path.join(
133+
config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py")
134+
config.substitutions.append(
135+
('%run_clang_tidy',
136+
'%s %s' % (config.python_executable, run_clang_tidy)) )
132137
else:
133138
# exclude the clang-tidy test directory
134139
config.excludes.append('clang-tidy')

0 commit comments

Comments
 (0)
Please sign in to comment.