Chromium Code Reviews| Index: tools/git/move_source_file.py |
| diff --git a/tools/git/move_source_file.py b/tools/git/move_source_file.py |
| index 18ef1ce82721ce348948d57dccd85f63d5d9ff6c..8b5db87ac1067de65183983a84e714c86bcbce2c 100755 |
| --- a/tools/git/move_source_file.py |
| +++ b/tools/git/move_source_file.py |
| @@ -72,7 +72,7 @@ def MoveFile(from_path, to_path): |
| raise Exception('Fatal: Failed to run git mv command.') |
| -def UpdatePostMove(from_path, to_path): |
| +def UpdatePostMove(from_path, to_path, in_blink): |
| """Given a file that has moved from |from_path| to |to_path|, |
| updates the moved file's include guard to match the new path and |
| updates all references to the file in other source files. Also tries |
| @@ -85,16 +85,28 @@ def UpdatePostMove(from_path, to_path): |
| if os.path.splitext(from_path)[1] in ['.h', '.hh']: |
| UpdateIncludeGuard(from_path, to_path) |
| + from_include_path = from_path |
| + to_include_path = to_path |
| + if in_blink: |
| + def UpdateIncludePathForBlink(path): |
|
Matt Giuca
2015/07/07 05:20:52
This should be moved to the top level. (Only make
benwells
2015/07/13 05:46:31
Done.
|
| + for prefix in ['public/', 'Source/']: |
|
Matt Giuca
2015/07/07 05:20:52
Use tuple not list ("(,)" not "[,]").
(Semantical
benwells
2015/07/13 05:46:31
Done.
|
| + if path.startswith(prefix): |
| + return path[len(prefix):] |
|
Matt Giuca
2015/07/07 05:20:52
nit: Blank line after return.
benwells
2015/07/13 05:46:31
Done.
|
| + return path |
| + from_include_path = UpdateIncludePathForBlink(from_include_path) |
| + to_include_path = UpdateIncludePathForBlink(to_include_path) |
| + |
| # Update include/import references. |
| files_with_changed_includes = mffr.MultiFileFindReplace( |
| - r'(#(include|import)\s*["<])%s([>"])' % re.escape(from_path), |
| - r'\1%s\3' % to_path, |
| + r'(#(include|import)\s*["<])%s([>"])' % re.escape(from_include_path), |
| + r'\1%s\3' % to_include_path, |
| ['*.cc', '*.h', '*.m', '*.mm', '*.cpp']) |
| # Reorder headers in files that changed. |
| for changed_file in files_with_changed_includes: |
| def AlwaysConfirm(a, b): return True |
| - sort_headers.FixFileWithConfirmFunction(changed_file, AlwaysConfirm, True) |
| + sort_headers.FixFileWithConfirmFunction(changed_file, AlwaysConfirm, True, |
| + in_blink) |
| # Update comments; only supports // comments, which are primarily |
| # used in our code. |
| @@ -195,6 +207,8 @@ def main(): |
| print 'Fatal: You must run from the root of a git checkout.' |
| return 1 |
| + in_blink = os.getcwd().endswith("third_party/WebKit") |
|
Matt Giuca
2015/07/07 05:20:52
I'm concerned this will break when the repos merge
benwells
2015/07/13 05:46:31
Yep, it will break. I think it is unavoidable now,
|
| + |
| parser = optparse.OptionParser(usage='%prog FROM_PATH... TO_PATH') |
| parser.add_option('--already_moved', action='store_true', |
| dest='already_moved', |
| @@ -227,7 +241,7 @@ def main(): |
| to_path = MakeDestinationPath(from_path, orig_to_path) |
| if not opts.already_moved: |
| MoveFile(from_path, to_path) |
| - UpdatePostMove(from_path, to_path) |
| + UpdatePostMove(from_path, to_path, in_blink) |
| return 0 |