1 #!/usr/bin/env python2.7 2 # Copyright 2017 gRPC authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 import sys 17 import os 18 import subprocess 19 import argparse 20 import multiprocessing 21 22 sys.path.append( 23 os.path.join( 24 os.path.dirname(sys.argv[0]), '..', 'run_tests', 'python_utils')) 25 import jobset 26 27 extra_args = [ 28 '-x', 29 'c++', 30 '-std=c++11', 31 ] 32 with open('.clang_complete') as f: 33 for line in f: 34 line = line.strip() 35 if line.startswith('-I'): 36 extra_args.append(line) 37 38 clang_tidy = os.environ.get('CLANG_TIDY', 'clang-tidy') 39 40 argp = argparse.ArgumentParser(description='Run clang-tidy against core') 41 argp.add_argument('files', nargs='+', help='Files to tidy') 42 argp.add_argument('--fix', dest='fix', action='store_true') 43 argp.add_argument( 44 '-j', 45 '--jobs', 46 type=int, 47 default=multiprocessing.cpu_count(), 48 help='Number of CPUs to use') 49 argp.set_defaults(fix=False) 50 args = argp.parse_args() 51 52 cmdline = [ 53 clang_tidy, 54 ] + ['--extra-arg-before=%s' % arg for arg in extra_args] 55 56 if args.fix: 57 cmdline.append('--fix') 58 59 jobs = [] 60 for filename in args.files: 61 jobs.append(jobset.JobSpec( 62 cmdline + [filename], 63 shortname=filename, 64 )) #verbose_success=True)) 65 66 num_fails, res_set = jobset.run(jobs, maxjobs=args.jobs) 67 sys.exit(num_fails) 68