• 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(os.path.dirname(sys.argv[0]), '..', 'run_tests',
24                 '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('-j',
44                  '--jobs',
45                  type=int,
46                  default=multiprocessing.cpu_count(),
47                  help='Number of CPUs to use')
48argp.set_defaults(fix=False)
49args = argp.parse_args()
50
51cmdline = [
52    clang_tidy,
53] + ['--extra-arg-before=%s' % arg for arg in extra_args]
54
55if args.fix:
56    cmdline.append('--fix')
57
58jobs = []
59for filename in args.files:
60    jobs.append(jobset.JobSpec(
61        cmdline + [filename],
62        shortname=filename,
63    ))  #verbose_success=True))
64
65num_fails, res_set = jobset.run(jobs, maxjobs=args.jobs)
66sys.exit(num_fails)
67