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 """Moves C++ files to a new location, updating any include paths that point | 6 """Moves C++ files to a new location, updating any include paths that point |
7 to them, and re-ordering headers as needed. If multiple source files are | 7 to them, and re-ordering headers as needed. If multiple source files are |
8 specified, the destination must be a directory. Updates include guards in | 8 specified, the destination must be a directory. Updates include guards in |
9 moved header files. Assumes Chromium coding style. | 9 moved header files. Assumes Chromium coding style. |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 import subprocess | 24 import subprocess |
25 import sys | 25 import sys |
26 | 26 |
27 import mffr | 27 import mffr |
28 | 28 |
29 if __name__ == '__main__': | 29 if __name__ == '__main__': |
30 # Need to add the directory containing sort-headers.py to the Python | 30 # Need to add the directory containing sort-headers.py to the Python |
31 # classpath. | 31 # classpath. |
32 sys.path.append(os.path.abspath(os.path.join(sys.path[0], '..'))) | 32 sys.path.append(os.path.abspath(os.path.join(sys.path[0], '..'))) |
33 sort_headers = __import__('sort-headers') | 33 sort_headers = __import__('sort-headers') |
| 34 import sort_sources |
34 | 35 |
35 | 36 |
36 HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh', '.cpp'] | 37 HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh', '.cpp'] |
37 | 38 |
38 | 39 |
39 def IsHandledFile(path): | 40 def IsHandledFile(path): |
40 return os.path.splitext(path)[1] in HANDLED_EXTENSIONS | 41 return os.path.splitext(path)[1] in HANDLED_EXTENSIONS |
41 | 42 |
42 | 43 |
43 def MakeDestinationPath(from_path, to_path): | 44 def MakeDestinationPath(from_path, to_path): |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 parts = re.split(r"[/\\]", path, 1) | 136 parts = re.split(r"[/\\]", path, 1) |
136 if len(parts) == 2: | 137 if len(parts) == 2: |
137 return (parts[0], parts[1]) | 138 return (parts[0], parts[1]) |
138 else: | 139 else: |
139 return (parts[0], '') | 140 return (parts[0], '') |
140 | 141 |
141 visiting_directory = '' | 142 visiting_directory = '' |
142 from_rest = from_path | 143 from_rest = from_path |
143 to_rest = to_path | 144 to_rest = to_path |
144 while True: | 145 while True: |
145 mffr.MultiFileFindReplace( | 146 files_with_changed_sources = mffr.MultiFileFindReplace( |
146 r'([\'"])%s([\'"])' % from_rest, | 147 r'([\'"])%s([\'"])' % from_rest, |
147 r'\1%s\2' % to_rest, | 148 r'\1%s\2' % to_rest, |
148 [os.path.join(visiting_directory, 'BUILD.gn'), | 149 [os.path.join(visiting_directory, 'BUILD.gn'), |
149 os.path.join(visiting_directory, '*.gyp*')]) | 150 os.path.join(visiting_directory, '*.gyp*')]) |
| 151 for changed_file in files_with_changed_sources: |
| 152 sort_sources.ProcessFile(changed_file, should_confirm=False) |
150 from_first, from_rest = SplitByFirstComponent(from_rest) | 153 from_first, from_rest = SplitByFirstComponent(from_rest) |
151 to_first, to_rest = SplitByFirstComponent(to_rest) | 154 to_first, to_rest = SplitByFirstComponent(to_rest) |
152 visiting_directory = os.path.join(visiting_directory, from_first) | 155 visiting_directory = os.path.join(visiting_directory, from_first) |
153 if not from_rest or not to_rest: | 156 if not from_rest or not to_rest: |
154 break | 157 break |
155 | 158 |
156 | 159 |
157 def MakeIncludeGuardName(path_from_root): | 160 def MakeIncludeGuardName(path_from_root): |
158 """Returns an include guard name given a path from root.""" | 161 """Returns an include guard name given a path from root.""" |
159 guard = path_from_root.replace('/', '_') | 162 guard = path_from_root.replace('/', '_') |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 continue | 226 continue |
224 to_path = MakeDestinationPath(from_path, orig_to_path) | 227 to_path = MakeDestinationPath(from_path, orig_to_path) |
225 if not opts.already_moved: | 228 if not opts.already_moved: |
226 MoveFile(from_path, to_path) | 229 MoveFile(from_path, to_path) |
227 UpdatePostMove(from_path, to_path) | 230 UpdatePostMove(from_path, to_path) |
228 return 0 | 231 return 0 |
229 | 232 |
230 | 233 |
231 if __name__ == '__main__': | 234 if __name__ == '__main__': |
232 sys.exit(main()) | 235 sys.exit(main()) |
OLD | NEW |