OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Given a filename as an argument, sort the #include/#imports in that file. | 6 """Given a filename as an argument, sort the #include/#imports in that file. |
7 | 7 |
8 Shows a diff and prompts for confirmation before doing the deed. | 8 Shows a diff and prompts for confirmation before doing the deed. |
9 Works great with tools/git/for-all-touched-files.py. | 9 Works great with tools/git/for-all-touched-files.py. |
10 """ | 10 """ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 # The win32 api has all sorts of implicit include order dependencies :-/ | 49 # The win32 api has all sorts of implicit include order dependencies :-/ |
50 # Give a few headers special sort keys that make sure they appear before all | 50 # Give a few headers special sort keys that make sure they appear before all |
51 # other headers. | 51 # other headers. |
52 if line.startswith('<windows.h>'): # Must be before e.g. shellapi.h | 52 if line.startswith('<windows.h>'): # Must be before e.g. shellapi.h |
53 return '0' | 53 return '0' |
54 if line.startswith('<atlbase.h>'): # Must be before atlapp.h. | 54 if line.startswith('<atlbase.h>'): # Must be before atlapp.h. |
55 return '1' + line | 55 return '1' + line |
56 if line.startswith('<unknwn.h>'): # Must be before e.g. intshcut.h | 56 if line.startswith('<unknwn.h>'): # Must be before e.g. intshcut.h |
57 return '1' + line | 57 return '1' + line |
| 58 if line.startswith('<ole2.h>'): # Must be before e.g. intshcut.h |
| 59 return '1' + line |
58 | 60 |
59 # C++ system headers should come after C system headers. | 61 # C++ system headers should come after C system headers. |
60 if line.startswith('<'): | 62 if line.startswith('<'): |
61 if line.find('.h>') != -1: | 63 if line.find('.h>') != -1: |
62 return '2' + line.lower() | 64 return '2' + line.lower() |
63 else: | 65 else: |
64 return '3' + line.lower() | 66 return '3' + line.lower() |
65 | 67 |
66 return '4' + line | 68 return '4' + line |
67 | 69 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if len(filenames) < 1: | 178 if len(filenames) < 1: |
177 parser.print_help() | 179 parser.print_help() |
178 return 1 | 180 return 1 |
179 | 181 |
180 for filename in filenames: | 182 for filename in filenames: |
181 DiffAndConfirm(filename, opts.should_confirm, opts.perform_safety_checks) | 183 DiffAndConfirm(filename, opts.should_confirm, opts.perform_safety_checks) |
182 | 184 |
183 | 185 |
184 if __name__ == '__main__': | 186 if __name__ == '__main__': |
185 sys.exit(main()) | 187 sys.exit(main()) |
OLD | NEW |