OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Wrapper script to help run clang tools across Chromium code. | 5 """Wrapper script to help run clang tools across Chromium code. |
6 | 6 |
7 How to use run_tool.py: | 7 How to use run_tool.py: |
8 If you want to run a clang tool across all Chromium code: | 8 If you want to run a clang tool across all Chromium code: |
9 run_tool.py <tool> <path/to/compiledb> | 9 run_tool.py <tool> <path/to/compiledb> |
10 | 10 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 188 |
189 def main(): | 189 def main(): |
190 parser = argparse.ArgumentParser() | 190 parser = argparse.ArgumentParser() |
191 parser.add_argument('tool', help='clang tool to run') | 191 parser.add_argument('tool', help='clang tool to run') |
192 parser.add_argument('--all', action='store_true') | 192 parser.add_argument('--all', action='store_true') |
193 parser.add_argument( | 193 parser.add_argument( |
194 '--generate-compdb', | 194 '--generate-compdb', |
195 action='store_true', | 195 action='store_true', |
196 help='regenerate the compile database before running the tool') | 196 help='regenerate the compile database before running the tool') |
197 parser.add_argument( | 197 parser.add_argument( |
| 198 '--shard', |
| 199 metavar='<n>-of-<count>') |
| 200 parser.add_argument( |
198 'compile_database', | 201 'compile_database', |
199 help='path to the directory that contains the compile database') | 202 help='path to the directory that contains the compile database') |
200 parser.add_argument( | 203 parser.add_argument( |
201 'path_filter', | 204 'path_filter', |
202 nargs='*', | 205 nargs='*', |
203 help='optional paths to filter what files the tool is run on') | 206 help='optional paths to filter what files the tool is run on') |
204 parser.add_argument( | 207 parser.add_argument( |
205 '--tool-args', nargs='*', | 208 '--tool-args', nargs='*', |
206 help='optional arguments passed to the tool') | 209 help='optional arguments passed to the tool') |
207 args = parser.parse_args() | 210 args = parser.parse_args() |
(...skipping 11 matching lines...) Expand all Loading... |
219 if args.all: | 222 if args.all: |
220 source_filenames = set(_GetFilesFromCompileDB(args.compile_database)) | 223 source_filenames = set(_GetFilesFromCompileDB(args.compile_database)) |
221 else: | 224 else: |
222 git_filenames = set(_GetFilesFromGit(args.path_filter)) | 225 git_filenames = set(_GetFilesFromGit(args.path_filter)) |
223 # Filter out files that aren't C/C++/Obj-C/Obj-C++. | 226 # Filter out files that aren't C/C++/Obj-C/Obj-C++. |
224 extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm')) | 227 extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm')) |
225 source_filenames = [f | 228 source_filenames = [f |
226 for f in git_filenames | 229 for f in git_filenames |
227 if os.path.splitext(f)[1] in extensions] | 230 if os.path.splitext(f)[1] in extensions] |
228 | 231 |
| 232 if args.shard: |
| 233 total_length = len(source_filenames) |
| 234 match = re.match(r'(\d+)-of-(\d+)$', args.shard) |
| 235 # Input is 1-based, but modular arithmetic is 0-based. |
| 236 shard_number = int(match.group(1)) - 1 |
| 237 shard_count = int(match.group(2)) |
| 238 source_filenames = [ |
| 239 f[1] for f in enumerate(sorted(source_filenames)) |
| 240 if f[0] % shard_count == shard_number |
| 241 ] |
| 242 print 'Shard %d-of-%d will process %d entries out of %d' % ( |
| 243 shard_number, shard_count, len(source_filenames), total_length) |
| 244 |
229 dispatcher = _CompilerDispatcher(args.tool, args.tool_args, | 245 dispatcher = _CompilerDispatcher(args.tool, args.tool_args, |
230 args.compile_database, | 246 args.compile_database, |
231 source_filenames) | 247 source_filenames) |
232 dispatcher.Run() | 248 dispatcher.Run() |
233 return -dispatcher.failed_count | 249 return -dispatcher.failed_count |
234 | 250 |
235 | 251 |
236 if __name__ == '__main__': | 252 if __name__ == '__main__': |
237 sys.exit(main()) | 253 sys.exit(main()) |
OLD | NEW |