Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 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( |
ncteisen | 7a2be20 | 2017-12-11 16:49:19 -0800 | [diff] [blame] | 23 | os.path.join( |
| 24 | os.path.dirname(sys.argv[0]), '..', 'run_tests', 'python_utils')) |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 25 | import jobset |
| 26 | |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 27 | extra_args = [ |
ncteisen | 7a2be20 | 2017-12-11 16:49:19 -0800 | [diff] [blame] | 28 | '-x', |
| 29 | 'c++', |
| 30 | '-std=c++11', |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 31 | ] |
| 32 | with open('.clang_complete') as f: |
ncteisen | 7a2be20 | 2017-12-11 16:49:19 -0800 | [diff] [blame] | 33 | for line in f: |
| 34 | line = line.strip() |
| 35 | if line.startswith('-I'): |
| 36 | extra_args.append(line) |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 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') |
ncteisen | 7a2be20 | 2017-12-11 16:49:19 -0800 | [diff] [blame] | 43 | argp.add_argument( |
| 44 | '-j', |
| 45 | '--jobs', |
| 46 | type=int, |
| 47 | default=multiprocessing.cpu_count(), |
| 48 | help='Number of CPUs to use') |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 49 | argp.set_defaults(fix=False) |
| 50 | args = argp.parse_args() |
| 51 | |
| 52 | cmdline = [ |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 53 | clang_tidy, |
ncteisen | 1adad72 | 2018-01-12 15:26:30 -0800 | [diff] [blame] | 54 | ] + ['--extra-arg-before=%s' % arg for arg in extra_args] |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 55 | |
| 56 | if args.fix: |
ncteisen | 7a2be20 | 2017-12-11 16:49:19 -0800 | [diff] [blame] | 57 | cmdline.append('--fix') |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 58 | |
| 59 | jobs = [] |
| 60 | for filename in args.files: |
ncteisen | 7a2be20 | 2017-12-11 16:49:19 -0800 | [diff] [blame] | 61 | jobs.append(jobset.JobSpec( |
| 62 | cmdline + [filename], |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 63 | shortname=filename, |
| 64 | )) #verbose_success=True)) |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 65 | |
Noah Eisen | 02336a2 | 2018-01-03 22:14:28 -0800 | [diff] [blame] | 66 | num_fails, res_set = jobset.run(jobs, maxjobs=args.jobs) |
| 67 | sys.exit(num_fails) |