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 |
11 Attempts to update paths used in .gyp(i) files, but does not reorder | 11 Attempts to update and reorder paths used in .gyp(i) files. |
12 or restructure .gyp(i) files in any way. | |
13 | 12 |
14 Updates full-path references to files in // comments in source files. | 13 Updates full-path references to files in // comments in source files. |
15 | 14 |
16 Must run in a git checkout, as it relies on git grep for a fast way to | 15 Must run in a git checkout, as it relies on git grep for a fast way to |
17 find files that reference the moved file. | 16 find files that reference the moved file. |
18 """ | 17 """ |
19 | 18 |
20 | 19 |
21 import optparse | 20 import optparse |
22 import os | 21 import os |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 # of the file plus one at the bottom for the comment on the #endif. | 205 # of the file plus one at the bottom for the comment on the #endif. |
207 if new_contents.count(new_guard) != 3: | 206 if new_contents.count(new_guard) != 3: |
208 print ('WARNING: Could not successfully update include guard; perhaps ' | 207 print ('WARNING: Could not successfully update include guard; perhaps ' |
209 'old guard is not per style guide? You will have to update the ' | 208 'old guard is not per style guide? You will have to update the ' |
210 'include guard manually. (%s)' % new_path) | 209 'include guard manually. (%s)' % new_path) |
211 | 210 |
212 with open(new_path, 'w') as f: | 211 with open(new_path, 'w') as f: |
213 f.write(new_contents) | 212 f.write(new_contents) |
214 | 213 |
215 def main(): | 214 def main(): |
216 if not os.path.isdir('.git'): | 215 # git rev-parse returns 0 even when run in the .git directory. We don't want |
satorux1
2016/01/21 05:52:07
how about commenting that we use 'git rev-parse' t
dgrogan
2016/01/21 19:50:53
Done.
| |
217 print 'Fatal: You must run from the root of a git checkout.' | 216 # people running this in the .git directory. |
217 if not os.system('git rev-parse') == 0 or os.getcwd().endswith(".git"): | |
satorux1
2016/01/21 05:52:07
This probably matches "foo/bar.git".
how about o
dgrogan
2016/01/21 19:50:53
Good point. Fixed.
| |
218 print 'Fatal: You must run in a git checkout.' | |
218 return 1 | 219 return 1 |
219 | 220 |
220 in_blink = os.getcwd().endswith("third_party/WebKit") | 221 in_blink = os.getcwd().endswith("third_party/WebKit") |
satorux1
2016/01/21 05:52:07
'/' may not match on Windows? while you are at it,
dgrogan
2016/01/21 19:50:53
Done.
| |
221 | 222 |
222 parser = optparse.OptionParser(usage='%prog FROM_PATH... TO_PATH') | 223 parser = optparse.OptionParser(usage='%prog FROM_PATH... TO_PATH') |
223 parser.add_option('--already_moved', action='store_true', | 224 parser.add_option('--already_moved', action='store_true', |
224 dest='already_moved', | 225 dest='already_moved', |
225 help='Causes the script to skip moving the file.') | 226 help='Causes the script to skip moving the file.') |
226 parser.add_option('--no_error_for_non_source_file', action='store_false', | 227 parser.add_option('--no_error_for_non_source_file', action='store_false', |
227 default='True', | 228 default='True', |
228 dest='error_for_non_source_file', | 229 dest='error_for_non_source_file', |
229 help='Causes the script to simply print a warning on ' | 230 help='Causes the script to simply print a warning on ' |
230 'encountering a non-source file rather than raising an ' | 231 'encountering a non-source file rather than raising an ' |
(...skipping 19 matching lines...) Expand all Loading... | |
250 continue | 251 continue |
251 to_path = MakeDestinationPath(from_path, orig_to_path) | 252 to_path = MakeDestinationPath(from_path, orig_to_path) |
252 if not opts.already_moved: | 253 if not opts.already_moved: |
253 MoveFile(from_path, to_path) | 254 MoveFile(from_path, to_path) |
254 UpdatePostMove(from_path, to_path, in_blink) | 255 UpdatePostMove(from_path, to_path, in_blink) |
255 return 0 | 256 return 0 |
256 | 257 |
257 | 258 |
258 if __name__ == '__main__': | 259 if __name__ == '__main__': |
259 sys.exit(main()) | 260 sys.exit(main()) |
OLD | NEW |