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 | |
35 | 34 |
36 | 35 |
37 HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh', '.cpp'] | 36 HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh', '.cpp'] |
38 | 37 |
39 | 38 |
40 def IsHandledFile(path): | 39 def IsHandledFile(path): |
41 return os.path.splitext(path)[1] in HANDLED_EXTENSIONS | 40 return os.path.splitext(path)[1] in HANDLED_EXTENSIONS |
42 | 41 |
43 | 42 |
44 def MakeDestinationPath(from_path, to_path): | 43 def MakeDestinationPath(from_path, to_path): |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 parts = re.split(r"[/\\]", path, 1) | 135 parts = re.split(r"[/\\]", path, 1) |
137 if len(parts) == 2: | 136 if len(parts) == 2: |
138 return (parts[0], parts[1]) | 137 return (parts[0], parts[1]) |
139 else: | 138 else: |
140 return (parts[0], '') | 139 return (parts[0], '') |
141 | 140 |
142 visiting_directory = '' | 141 visiting_directory = '' |
143 from_rest = from_path | 142 from_rest = from_path |
144 to_rest = to_path | 143 to_rest = to_path |
145 while True: | 144 while True: |
146 files_with_changed_sources = mffr.MultiFileFindReplace( | 145 mffr.MultiFileFindReplace( |
147 r'([\'"])%s([\'"])' % from_rest, | 146 r'([\'"])%s([\'"])' % from_rest, |
148 r'\1%s\2' % to_rest, | 147 r'\1%s\2' % to_rest, |
149 [os.path.join(visiting_directory, 'BUILD.gn'), | 148 [os.path.join(visiting_directory, 'BUILD.gn'), |
150 os.path.join(visiting_directory, '*.gyp*')]) | 149 os.path.join(visiting_directory, '*.gyp*')]) |
151 for changed_file in files_with_changed_sources: | |
152 sort_sources.ProcessFile(changed_file, should_confirm=False) | |
153 from_first, from_rest = SplitByFirstComponent(from_rest) | 150 from_first, from_rest = SplitByFirstComponent(from_rest) |
154 to_first, to_rest = SplitByFirstComponent(to_rest) | 151 to_first, to_rest = SplitByFirstComponent(to_rest) |
155 visiting_directory = os.path.join(visiting_directory, from_first) | 152 visiting_directory = os.path.join(visiting_directory, from_first) |
156 if not from_rest or not to_rest: | 153 if not from_rest or not to_rest: |
157 break | 154 break |
158 | 155 |
159 | 156 |
160 def MakeIncludeGuardName(path_from_root): | 157 def MakeIncludeGuardName(path_from_root): |
161 """Returns an include guard name given a path from root.""" | 158 """Returns an include guard name given a path from root.""" |
162 guard = path_from_root.replace('/', '_') | 159 guard = path_from_root.replace('/', '_') |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 continue | 223 continue |
227 to_path = MakeDestinationPath(from_path, orig_to_path) | 224 to_path = MakeDestinationPath(from_path, orig_to_path) |
228 if not opts.already_moved: | 225 if not opts.already_moved: |
229 MoveFile(from_path, to_path) | 226 MoveFile(from_path, to_path) |
230 UpdatePostMove(from_path, to_path) | 227 UpdatePostMove(from_path, to_path) |
231 return 0 | 228 return 0 |
232 | 229 |
233 | 230 |
234 if __name__ == '__main__': | 231 if __name__ == '__main__': |
235 sys.exit(main()) | 232 sys.exit(main()) |
OLD | NEW |