| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 def IncludeCompareKey(line): | 40 def IncludeCompareKey(line): |
| 41 """Sorting comparator key used for comparing two #include lines. | 41 """Sorting comparator key used for comparing two #include lines. |
| 42 Returns the filename without the #include/#import/import prefix. | 42 Returns the filename without the #include/#import/import prefix. |
| 43 """ | 43 """ |
| 44 for prefix in ('#include ', '#import ', 'import '): | 44 for prefix in ('#include ', '#import ', 'import '): |
| 45 if line.startswith(prefix): | 45 if line.startswith(prefix): |
| 46 line = line[len(prefix):] | 46 line = line[len(prefix):] |
| 47 break | 47 break |
| 48 | 48 |
| 49 # In sky, config.h must always be first to defined HAVE, USE, etc. |
| 50 if line.startswith('"sky/engine/config.h"'): |
| 51 return '0' |
| 52 |
| 49 # The win32 api has all sorts of implicit include order dependencies :-/ | 53 # 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 | 54 # Give a few headers special sort keys that make sure they appear before all |
| 51 # other headers. | 55 # other headers. |
| 52 if line.startswith('<windows.h>'): # Must be before e.g. shellapi.h | 56 if line.startswith('<windows.h>'): # Must be before e.g. shellapi.h |
| 53 return '0' | 57 return '0' |
| 54 if line.startswith('<atlbase.h>'): # Must be before atlapp.h. | 58 if line.startswith('<atlbase.h>'): # Must be before atlapp.h. |
| 55 return '1' + line | 59 return '1' + line |
| 56 if line.startswith('<ole2.h>'): # Must be before e.g. intshcut.h | 60 if line.startswith('<ole2.h>'): # Must be before e.g. intshcut.h |
| 57 return '1' + line | 61 return '1' + line |
| 58 if line.startswith('<unknwn.h>'): # Must be before e.g. intshcut.h | 62 if line.startswith('<unknwn.h>'): # Must be before e.g. intshcut.h |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if len(filenames) < 1: | 183 if len(filenames) < 1: |
| 180 parser.print_help() | 184 parser.print_help() |
| 181 return 1 | 185 return 1 |
| 182 | 186 |
| 183 for filename in filenames: | 187 for filename in filenames: |
| 184 DiffAndConfirm(filename, opts.should_confirm, opts.perform_safety_checks) | 188 DiffAndConfirm(filename, opts.should_confirm, opts.perform_safety_checks) |
| 185 | 189 |
| 186 | 190 |
| 187 if __name__ == '__main__': | 191 if __name__ == '__main__': |
| 188 sys.exit(main()) | 192 sys.exit(main()) |
| OLD | NEW |