• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16import sys
17import os
18import subprocess
19import argparse
20import multiprocessing
21
22sys.path.append(
23    os.path.join(
24        os.path.dirname(sys.argv[0]), '..', 'run_tests', 'python_utils'))
25import jobset
26
27extra_args = [
28    '-x',
29    'c++',
30    '-std=c++11',
31]
32with 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
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')
43argp.add_argument(
44    '-j',
45    '--jobs',
46    type=int,
47    default=multiprocessing.cpu_count(),
48    help='Number of CPUs to use')
49argp.set_defaults(fix=False)
50args = argp.parse_args()
51
52cmdline = [
53    clang_tidy,
54] + ['--extra-arg-before=%s' % arg for arg in extra_args]
55
56if args.fix:
57    cmdline.append('--fix')
58
59jobs = []
60for filename in args.files:
61    jobs.append(jobset.JobSpec(
62        cmdline + [filename],
63        shortname=filename,
64    ))  #verbose_success=True))
65
66num_fails, res_set = jobset.run(jobs, maxjobs=args.jobs)
67sys.exit(num_fails)
68