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 | 5 |
6 """Wrapper script to help run clang tools across Chromium code. | 6 """Wrapper script to help run clang tools across Chromium code. |
7 | 7 |
8 How to use this tool: | 8 How to use this tool: |
9 If you want to run the tool across all Chromium code: | 9 If you want to run the tool across all Chromium code: |
10 run_tool.py <tool> <path/to/compiledb> | 10 run_tool.py <tool> <path/to/compiledb> |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 os.path.dirname(os.path.realpath(__file__)), | 307 os.path.dirname(os.path.realpath(__file__)), |
308 '../../../third_party/llvm/tools/clang/tools/clang-format', | 308 '../../../third_party/llvm/tools/clang/tools/clang-format', |
309 'clang-format-diff.py') | 309 'clang-format-diff.py') |
310 # TODO(dcheng): Allow this to be controlled with a flag as well. | 310 # TODO(dcheng): Allow this to be controlled with a flag as well. |
311 # TODO(dcheng): Shell escaping of args to git diff to clang-format is broken | 311 # TODO(dcheng): Shell escaping of args to git diff to clang-format is broken |
312 # on Windows. | 312 # on Windows. |
313 if not os.path.isfile(clang_format_diff_path) or sys.platform == 'win32': | 313 if not os.path.isfile(clang_format_diff_path) or sys.platform == 'win32': |
314 clang_format_diff_path = None | 314 clang_format_diff_path = None |
315 | 315 |
316 if len(argv) == 3 and argv[2] == '--all': | 316 if len(argv) == 3 and argv[2] == '--all': |
317 filenames = frozenset(_GetFilesFromCompileDB(argv[1])) | 317 filenames = set(_GetFilesFromCompileDB(argv[1])) |
318 else: | 318 else: |
319 filenames = frozenset(_GetFilesFromGit(argv[2:])) | 319 filenames = set(_GetFilesFromGit(argv[2:])) |
320 # Filter out files that aren't C/C++/Obj-C/Obj-C++. | 320 # Filter out files that aren't C/C++/Obj-C/Obj-C++. |
321 extensions = frozenset(('.c', '.cc', '.m', '.mm')) | 321 extensions = frozenset(('.c', '.cc', '.m', '.mm')) |
322 dispatcher = _CompilerDispatcher(argv[0], argv[1], | 322 filenames = [f for f in filenames |
323 [f for f in filenames | 323 if os.path.splitext(f)[1] in extensions] |
324 if os.path.splitext(f)[1] in extensions]) | 324 dispatcher = _CompilerDispatcher(argv[0], argv[1], filenames) |
325 dispatcher.Run() | 325 dispatcher.Run() |
326 # Filter out edits to files that aren't in the git repository, since it's not | 326 # Filter out edits to files that aren't in the git repository, since it's not |
327 # useful to modify files that aren't under source control--typically, these | 327 # useful to modify files that aren't under source control--typically, these |
328 # are generated files or files in a git submodule that's not part of Chromium. | 328 # are generated files or files in a git submodule that's not part of Chromium. |
329 _ApplyEdits({k : v for k, v in dispatcher.edits.iteritems() | 329 _ApplyEdits({k : v for k, v in dispatcher.edits.iteritems() |
330 if os.path.realpath(k) in filenames}, | 330 if os.path.realpath(k) in filenames}, |
331 clang_format_diff_path) | 331 clang_format_diff_path) |
332 if dispatcher.failed_count != 0: | 332 if dispatcher.failed_count != 0: |
333 return 2 | 333 return 2 |
334 return 0 | 334 return 0 |
335 | 335 |
336 | 336 |
337 if __name__ == '__main__': | 337 if __name__ == '__main__': |
338 sys.exit(main(sys.argv[1:])) | 338 sys.exit(main(sys.argv[1:])) |
OLD | NEW |