| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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', | 198 '--shard', |
| 199 metavar='<n>-of-<count>') | 199 metavar='<n>-of-<count>') |
| 200 parser.add_argument( | 200 parser.add_argument( |
| 201 '-p', | 201 '-p', |
| 202 required=True, | 202 required=True, |
| 203 help='path to the directory that contains the compile database') | 203 help='path to the directory that contains the compile database') |
| 204 parser.add_argument( | 204 parser.add_argument( |
| 205 '--source-filenames', |
| 206 help='optional path to a file including filenames to process') |
| 207 parser.add_argument( |
| 205 'path_filter', | 208 'path_filter', |
| 206 nargs='*', | 209 nargs='*', |
| 207 help='optional paths to filter what files the tool is run on') | 210 help='optional paths to filter what files the tool is run on') |
| 208 parser.add_argument( | 211 parser.add_argument( |
| 209 '--tool-args', nargs='*', | 212 '--tool-args', nargs='*', |
| 210 help='optional arguments passed to the tool') | 213 help='optional arguments passed to the tool') |
| 211 args = parser.parse_args() | 214 args = parser.parse_args() |
| 212 | 215 |
| 213 os.environ['PATH'] = '%s%s%s' % ( | 216 os.environ['PATH'] = '%s%s%s' % ( |
| 214 os.path.abspath(os.path.join( | 217 os.path.abspath(os.path.join( |
| 215 os.path.dirname(__file__), | 218 os.path.dirname(__file__), |
| 216 '../../../third_party/llvm-build/Release+Asserts/bin')), | 219 '../../../third_party/llvm-build/Release+Asserts/bin')), |
| 217 os.pathsep, | 220 os.pathsep, |
| 218 os.environ['PATH']) | 221 os.environ['PATH']) |
| 219 | 222 |
| 220 if args.generate_compdb: | 223 if args.generate_compdb: |
| 221 with open(os.path.join(args.p, 'compile_commands.json'), 'w') as f: | 224 with open(os.path.join(args.p, 'compile_commands.json'), 'w') as f: |
| 222 f.write(compile_db.GenerateWithNinja(args.p)) | 225 f.write(compile_db.GenerateWithNinja(args.p)) |
| 223 | 226 |
| 224 if args.all: | 227 if args.all: |
| 225 source_filenames = set(_GetFilesFromCompileDB(args.p)) | 228 source_filenames = set(_GetFilesFromCompileDB(args.p)) |
| 229 elif args.source_filenames: |
| 230 source_filenames = open(args.source_filenames, 'r').read().split('\n') |
| 226 else: | 231 else: |
| 227 git_filenames = set(_GetFilesFromGit(args.path_filter)) | 232 git_filenames = set(_GetFilesFromGit(args.path_filter)) |
| 228 # Filter out files that aren't C/C++/Obj-C/Obj-C++. | 233 # Filter out files that aren't C/C++/Obj-C/Obj-C++. |
| 229 extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm')) | 234 extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm')) |
| 230 source_filenames = [f | 235 source_filenames = [f |
| 231 for f in git_filenames | 236 for f in git_filenames |
| 232 if os.path.splitext(f)[1] in extensions] | 237 if os.path.splitext(f)[1] in extensions] |
| 233 | 238 |
| 234 if args.shard: | 239 if args.shard: |
| 235 total_length = len(source_filenames) | 240 total_length = len(source_filenames) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 246 | 251 |
| 247 dispatcher = _CompilerDispatcher(args.tool, args.tool_args, | 252 dispatcher = _CompilerDispatcher(args.tool, args.tool_args, |
| 248 args.p, | 253 args.p, |
| 249 source_filenames) | 254 source_filenames) |
| 250 dispatcher.Run() | 255 dispatcher.Run() |
| 251 return -dispatcher.failed_count | 256 return -dispatcher.failed_count |
| 252 | 257 |
| 253 | 258 |
| 254 if __name__ == '__main__': | 259 if __name__ == '__main__': |
| 255 sys.exit(main()) | 260 sys.exit(main()) |
| OLD | NEW |