| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 Returns: | 74 Returns: |
| 75 A dictionary mapping filenames to the associated edits. | 75 A dictionary mapping filenames to the associated edits. |
| 76 """ | 76 """ |
| 77 lines = stdout.splitlines() | 77 lines = stdout.splitlines() |
| 78 start_index = lines.index('==== BEGIN EDITS ====') | 78 start_index = lines.index('==== BEGIN EDITS ====') |
| 79 end_index = lines.index('==== END EDITS ====') | 79 end_index = lines.index('==== END EDITS ====') |
| 80 edits = collections.defaultdict(list) | 80 edits = collections.defaultdict(list) |
| 81 for line in lines[start_index + 1:end_index]: | 81 for line in lines[start_index + 1:end_index]: |
| 82 try: | 82 try: |
| 83 edit_type, path, offset, length, replacement = line.split(':', 4) | 83 edit_type, path, offset, length, replacement = line.split(':', 4) |
| 84 replacement = replacement.replace("\0", "\n"); |
| 84 # Normalize the file path emitted by the clang tool to be relative to the | 85 # Normalize the file path emitted by the clang tool to be relative to the |
| 85 # current working directory. | 86 # current working directory. |
| 86 path = os.path.relpath(os.path.join(build_directory, path)) | 87 path = os.path.relpath(os.path.join(build_directory, path)) |
| 87 edits[path].append(Edit(edit_type, int(offset), int(length), replacement)) | 88 edits[path].append(Edit(edit_type, int(offset), int(length), replacement)) |
| 88 except ValueError: | 89 except ValueError: |
| 89 print 'Unable to parse edit: %s' % line | 90 print 'Unable to parse edit: %s' % line |
| 90 return edits | 91 return edits |
| 91 | 92 |
| 92 | 93 |
| 93 def _ExecuteTool(toolname, build_directory, filename): | 94 def _ExecuteTool(toolname, build_directory, filename): |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 _ApplyEdits({k : v for k, v in dispatcher.edits.iteritems() | 295 _ApplyEdits({k : v for k, v in dispatcher.edits.iteritems() |
| 295 if k in filenames}, | 296 if k in filenames}, |
| 296 clang_format_diff_path) | 297 clang_format_diff_path) |
| 297 if dispatcher.failed_count != 0: | 298 if dispatcher.failed_count != 0: |
| 298 return 2 | 299 return 2 |
| 299 return 0 | 300 return 0 |
| 300 | 301 |
| 301 | 302 |
| 302 if __name__ == '__main__': | 303 if __name__ == '__main__': |
| 303 sys.exit(main(sys.argv[1:])) | 304 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |