Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: tools/git/move_source_file.py

Issue 1614633002: Make move_source_file.py work in blink again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change from 'not... == 0' to '!= 0' Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/git/OWNERS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 # We use "git rev-parse" to check if the script is run from a git checkout. It
217 print 'Fatal: You must run from the root of a git checkout.' 216 # returns 0 even when run in the .git directory. We don't want people running
217 # this in the .git directory.
218 if (os.system('git rev-parse') != 0 or
219 os.path.basename(os.getcwd()) == '.git'):
220 print 'Fatal: You must run in a git checkout.'
218 return 1 221 return 1
219 222
220 in_blink = os.getcwd().endswith("third_party/WebKit") 223 cwd = os.getcwd()
224 parent = os.path.dirname(cwd)
225 in_blink = (os.path.basename(parent) == 'third_party' and
226 os.path.basename(cwd) == 'WebKit')
221 227
222 parser = optparse.OptionParser(usage='%prog FROM_PATH... TO_PATH') 228 parser = optparse.OptionParser(usage='%prog FROM_PATH... TO_PATH')
223 parser.add_option('--already_moved', action='store_true', 229 parser.add_option('--already_moved', action='store_true',
224 dest='already_moved', 230 dest='already_moved',
225 help='Causes the script to skip moving the file.') 231 help='Causes the script to skip moving the file.')
226 parser.add_option('--no_error_for_non_source_file', action='store_false', 232 parser.add_option('--no_error_for_non_source_file', action='store_false',
227 default='True', 233 default='True',
228 dest='error_for_non_source_file', 234 dest='error_for_non_source_file',
229 help='Causes the script to simply print a warning on ' 235 help='Causes the script to simply print a warning on '
230 'encountering a non-source file rather than raising an ' 236 'encountering a non-source file rather than raising an '
(...skipping 19 matching lines...) Expand all
250 continue 256 continue
251 to_path = MakeDestinationPath(from_path, orig_to_path) 257 to_path = MakeDestinationPath(from_path, orig_to_path)
252 if not opts.already_moved: 258 if not opts.already_moved:
253 MoveFile(from_path, to_path) 259 MoveFile(from_path, to_path)
254 UpdatePostMove(from_path, to_path, in_blink) 260 UpdatePostMove(from_path, to_path, in_blink)
255 return 0 261 return 0
256 262
257 263
258 if __name__ == '__main__': 264 if __name__ == '__main__':
259 sys.exit(main()) 265 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/git/OWNERS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698