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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 continue | 207 continue |
208 last_edit = edit | 208 last_edit = edit |
209 contents[edit.offset:edit.offset + edit.length] = edit.replacement | 209 contents[edit.offset:edit.offset + edit.length] = edit.replacement |
210 if not edit.replacement: | 210 if not edit.replacement: |
211 _ExtendDeletionIfElementIsInList(contents, edit.offset) | 211 _ExtendDeletionIfElementIsInList(contents, edit.offset) |
212 edit_count += 1 | 212 edit_count += 1 |
213 f.seek(0) | 213 f.seek(0) |
214 f.truncate() | 214 f.truncate() |
215 f.write(contents) | 215 f.write(contents) |
216 if clang_format_diff_path: | 216 if clang_format_diff_path: |
217 if subprocess.call('git diff -U0 %s | python %s -style=Chromium' % ( | 217 if subprocess.call('git diff -U0 %s | python %s -i -p1 -style=file ' % ( |
218 k, clang_format_diff_path), shell=True) != 0: | 218 k, clang_format_diff_path), shell=True) != 0: |
219 print 'clang-format failed for %s' % k | 219 print 'clang-format failed for %s' % k |
220 print 'Applied %d edits to %d files' % (edit_count, len(edits)) | 220 print 'Applied %d edits to %d files' % (edit_count, len(edits)) |
221 | 221 |
222 | 222 |
223 _WHITESPACE_BYTES = frozenset((ord('\t'), ord('\n'), ord('\r'), ord(' '))) | 223 _WHITESPACE_BYTES = frozenset((ord('\t'), ord('\n'), ord('\r'), ord(' '))) |
224 | 224 |
225 | 225 |
226 def _ExtendDeletionIfElementIsInList(contents, offset): | 226 def _ExtendDeletionIfElementIsInList(contents, offset): |
227 """Extends the range of a deletion if the deleted element was part of a list. | 227 """Extends the range of a deletion if the deleted element was part of a list. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 _ApplyEdits({k : v for k, v in dispatcher.edits.iteritems() | 294 _ApplyEdits({k : v for k, v in dispatcher.edits.iteritems() |
295 if k in filenames}, | 295 if k in filenames}, |
296 clang_format_diff_path) | 296 clang_format_diff_path) |
297 if dispatcher.failed_count != 0: | 297 if dispatcher.failed_count != 0: |
298 return 2 | 298 return 2 |
299 return 0 | 299 return 0 |
300 | 300 |
301 | 301 |
302 if __name__ == '__main__': | 302 if __name__ == '__main__': |
303 sys.exit(main(sys.argv[1:])) | 303 sys.exit(main(sys.argv[1:])) |
OLD | NEW |