kuhar updated this revision to Diff 96045. kuhar added a comment. After thinking about Piotr's comment, I think that a better way to perform the check would be te invoking clang-apply-replacements with `--version` and seeing if it fails even before running clang-tidy. This way it is possible to save a lot of time when run-clang-tidy.py is run on a big project and apply_fixes fails at the end.
Let me know what you think about this approach. https://reviews.llvm.org/D32294 Files: clang-tidy/tool/run-clang-tidy.py
Index: clang-tidy/tool/run-clang-tidy.py =================================================================== --- clang-tidy/tool/run-clang-tidy.py +++ clang-tidy/tool/run-clang-tidy.py @@ -34,6 +34,7 @@ http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html """ +from __future__ import print_function import argparse import json import multiprocessing @@ -45,14 +46,15 @@ import sys import tempfile import threading +import traceback def find_compilation_database(path): """Adjusts the directory until a compilation database is found.""" result = './' while not os.path.isfile(os.path.join(result, path)): if os.path.realpath(result) == '/': - print 'Error: could not find compilation database.' + print('Error: could not find compilation database.') sys.exit(1) result += '../' return os.path.realpath(result) @@ -86,15 +88,24 @@ start.append(f) return start +def check_clang_apply_replacements_binary(args): + """Checks if invoking supplied clang-apply-replacements binary works.""" + try: + subprocess.check_call([args.clang_apply_replacements_binary, '--version']) + except: + print('Unable to run clang-apply-replacements. Is clang-apply-replacements ' + 'binary correctly specified?', file=sys.stderr) + traceback.print_exc() + sys.exit(1) + def apply_fixes(args, tmpdir): """Calls clang-apply-fixes on a given directory. Deletes the dir when done.""" invocation = [args.clang_apply_replacements_binary] if args.format: invocation.append('-format') invocation.append(tmpdir) subprocess.call(invocation) - shutil.rmtree(tmpdir) def run_tidy(args, tmpdir, build_path, queue): @@ -164,9 +175,9 @@ if args.checks: invocation.append('-checks=' + args.checks) invocation.append('-') - print subprocess.check_output(invocation) + print(subprocess.check_output(invocation)) except: - print >>sys.stderr, "Unable to run clang-tidy." + print("Unable to run clang-tidy.", file=sys.stderr) sys.exit(1) # Load the database and extract all files. @@ -179,6 +190,7 @@ tmpdir = None if args.fix: + check_clang_apply_replacements_binary(args) tmpdir = tempfile.mkdtemp() # Build up a big regexy filter from all command line arguments. @@ -204,14 +216,25 @@ except KeyboardInterrupt: # This is a sad hack. Unfortunately subprocess goes # bonkers with ctrl-c and we start forking merrily. - print '\nCtrl-C detected, goodbye.' + print('\nCtrl-C detected, goodbye.') if args.fix: shutil.rmtree(tmpdir) os.kill(0, 9) if args.fix: - print 'Applying fixes ...' - apply_fixes(args, tmpdir) + print('Applying fixes ...') + successfully_applied = True + + try: + apply_fixes(args, tmpdir) + except: + successfully_applied = False + print('Error applying fixes.\n', file=sys.stderr) + traceback.print_exc() + + shutil.rmtree(tmpdir) + if not successfully_applied: + sys.exit(1) if __name__ == '__main__': main()
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits