blob: 7ad1c160ba8c60f775c974823d0686b692a88982 [file] [log] [blame]
Craig Tiller4ac2b8e2017-11-10 14:14:17 -08001#!/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
16import sys
17import os
18import subprocess
19import argparse
20import multiprocessing
21
22sys.path.append(
ncteisen7a2be202017-12-11 16:49:19 -080023 os.path.join(
24 os.path.dirname(sys.argv[0]), '..', 'run_tests', 'python_utils'))
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080025import jobset
26
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080027extra_args = [
ncteisen7a2be202017-12-11 16:49:19 -080028 '-x',
29 'c++',
30 '-std=c++11',
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080031]
32with open('.clang_complete') as f:
ncteisen7a2be202017-12-11 16:49:19 -080033 for line in f:
34 line = line.strip()
35 if line.startswith('-I'):
36 extra_args.append(line)
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080037
38clang_tidy = os.environ.get('CLANG_TIDY', 'clang-tidy')
39
40argp = argparse.ArgumentParser(description='Run clang-tidy against core')
41argp.add_argument('files', nargs='+', help='Files to tidy')
42argp.add_argument('--fix', dest='fix', action='store_true')
ncteisen7a2be202017-12-11 16:49:19 -080043argp.add_argument(
44 '-j',
45 '--jobs',
46 type=int,
47 default=multiprocessing.cpu_count(),
48 help='Number of CPUs to use')
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080049argp.set_defaults(fix=False)
50args = argp.parse_args()
51
52cmdline = [
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080053 clang_tidy,
ncteisen1adad722018-01-12 15:26:30 -080054] + ['--extra-arg-before=%s' % arg for arg in extra_args]
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080055
56if args.fix:
ncteisen7a2be202017-12-11 16:49:19 -080057 cmdline.append('--fix')
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080058
59jobs = []
60for filename in args.files:
ncteisen7a2be202017-12-11 16:49:19 -080061 jobs.append(jobset.JobSpec(
62 cmdline + [filename],
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080063 shortname=filename,
64 )) #verbose_success=True))
Craig Tiller4ac2b8e2017-11-10 14:14:17 -080065
Noah Eisen02336a22018-01-03 22:14:28 -080066num_fails, res_set = jobset.run(jobs, maxjobs=args.jobs)
67sys.exit(num_fails)