Chromium Code Reviews| 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 """Generate a CL to roll webkit to the specified revision number and post | 6 """Generate a CL to roll webkit to the specified revision number and post |
| 7 it to Rietveld so that the CL will land automatically if it passes the | 7 it to Rietveld so that the CL will land automatically if it passes the |
| 8 commit-queue's checks. | 8 commit-queue's checks. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import logging | 11 import logging |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import sys | 15 import sys |
| 16 | 16 |
| 17 import find_depot_tools | 17 import find_depot_tools |
| 18 import scm | 18 import scm |
| 19 import subprocess2 | 19 import subprocess2 |
| 20 | 20 |
| 21 | 21 |
| 22 def die_with_error(msg): | 22 def die_with_error(msg): |
| 23 print >> sys.stderr, msg | 23 print >> sys.stderr, msg |
| 24 sys.exit(1) | 24 sys.exit(1) |
| 25 | 25 |
| 26 | 26 |
| 27 def process_deps(path, new_rev): | 27 def process_deps(path, new_rev, is_dry_run): |
| 28 """Update webkit_revision to |new_issue|. | 28 """Update webkit_revision to |new_issue|. |
| 29 | 29 |
| 30 A bit hacky, could it be made better? | 30 A bit hacky, could it be made better? |
| 31 """ | 31 """ |
| 32 content = open(path).read() | 32 content = open(path).read() |
| 33 old_line = r'(\s+)"webkit_revision": "(\d+)",' | 33 old_line = r'(\s+)"webkit_revision": "(\d+)",' |
| 34 new_line = r'\1"webkit_revision": "%d",' % new_rev | 34 new_line = r'\1"webkit_revision": "%d",' % new_rev |
| 35 new_content = re.sub(old_line, new_line, content, 1) | 35 new_content = re.sub(old_line, new_line, content, 1) |
| 36 old_rev = re.search(old_line, content).group(2) | 36 old_rev = re.search(old_line, content).group(2) |
| 37 if not old_rev or new_content == content: | 37 if not old_rev or new_content == content: |
| 38 die_with_error('Failed to update the DEPS file') | 38 die_with_error('Failed to update the DEPS file') |
| 39 | 39 |
| 40 open(path, 'w').write(new_content) | 40 if not is_dry_run: |
| 41 open(path, 'w').write(new_content) | |
| 41 return old_rev | 42 return old_rev |
| 42 | 43 |
| 43 | 44 |
| 44 def main(): | 45 def main(): |
| 45 tool_dir = os.path.dirname(os.path.abspath(__file__)) | 46 tool_dir = os.path.dirname(os.path.abspath(__file__)) |
| 46 parser = optparse.OptionParser(usage='%prog [options] <new webkit rev>') | 47 parser = optparse.OptionParser(usage='%prog [options] <new webkit rev>') |
| 47 parser.add_option('-v', '--verbose', action='count', default=0) | 48 parser.add_option('-v', '--verbose', action='count', default=0) |
| 49 parser.add_option('--dry-run', action='store_true', default=False) | |
|
M-A Ruel
2013/04/24 01:40:23
Personally, I prefer to skip default=False and use
| |
| 48 parser.add_option('--commit', action='store_true', default=True, | 50 parser.add_option('--commit', action='store_true', default=True, |
| 49 help='(default) Put change in commit queue on upload.') | 51 help='(default) Put change in commit queue on upload.') |
| 50 parser.add_option('--no-commit', action='store_false', dest='commit', | 52 parser.add_option('--no-commit', action='store_false', dest='commit', |
| 51 help='Don\'t put change in commit queue on upload.') | 53 help='Don\'t put change in commit queue on upload.') |
| 52 parser.add_option('-r', '--reviewers', default='', | 54 parser.add_option('-r', '--reviewers', default='', |
| 53 help='Add given users as either reviewers or TBR as' | 55 help='Add given users as either reviewers or TBR as' |
| 54 ' appropriate.') | 56 ' appropriate.') |
| 55 parser.add_option('--upstream', default='origin/master', | 57 parser.add_option('--upstream', default='origin/master', |
| 56 help='(default "%default") Use given start point for change' | 58 help='(default "%default") Use given start point for change' |
| 57 ' to upload. For instance, if you use the old git workflow,' | 59 ' to upload. For instance, if you use the old git workflow,' |
| 58 ' you might set it to "origin/trunk".') | 60 ' you might set it to "origin/trunk".') |
| 59 parser.add_option('--cc', help='CC email addresses for issue.') | 61 parser.add_option('--cc', help='CC email addresses for issue.') |
| 60 | 62 |
| 61 options, args = parser.parse_args() | 63 options, args = parser.parse_args() |
| 62 logging.basicConfig( | 64 logging.basicConfig( |
| 63 level= | 65 level= |
| 64 [logging.WARNING, logging.INFO, logging.DEBUG][ | 66 [logging.WARNING, logging.INFO, logging.DEBUG][ |
| 65 min(2, options.verbose)]) | 67 min(2, options.verbose)]) |
| 66 if len(args) != 1: | 68 if len(args) != 1: |
| 67 parser.print_help() | 69 parser.print_help() |
| 68 exit(0) | 70 exit(0) |
| 69 | 71 |
| 70 root_dir = os.path.dirname(tool_dir) | 72 root_dir = os.path.dirname(tool_dir) |
| 71 os.chdir(root_dir) | 73 os.chdir(root_dir) |
| 72 | 74 |
| 73 new_rev = int(args[0]) | 75 new_rev = int(args[0]) |
| 74 print 'Roll webkit revision to %s' % new_rev | |
| 75 | 76 |
| 76 # Silence the editor. | 77 # Silence the editor. |
| 77 os.environ['EDITOR'] = 'true' | 78 os.environ['EDITOR'] = 'true' |
| 78 | 79 |
| 79 old_branch = scm.GIT.GetBranch(root_dir) | 80 old_branch = scm.GIT.GetBranch(root_dir) |
| 80 if old_branch == 'webkit_roll': | 81 if old_branch == 'blink_roll': |
| 81 parser.error( | 82 parser.error( |
| 82 'Please delete the branch webkit_roll and move to a different branch') | 83 'Please delete the branch blink_roll and move to a different branch') |
| 83 subprocess2.check_output( | 84 |
| 84 ['git', 'checkout', '-b', 'webkit_roll', options.upstream]) | 85 if not options.dry_run: |
| 86 subprocess2.check_output( | |
| 87 ['git', 'checkout', '-b', 'blink_roll', options.upstream]) | |
| 88 | |
| 85 try: | 89 try: |
| 86 old_rev = int(process_deps(os.path.join(root_dir, 'DEPS'), new_rev)) | 90 old_rev = int(process_deps(os.path.join(root_dir, 'DEPS'), new_rev, |
| 91 options.dry_run)) | |
| 92 print 'Blink roll %s:%s' % (old_rev, new_rev) | |
| 93 | |
| 87 review_field = 'TBR' if options.commit else 'R' | 94 review_field = 'TBR' if options.commit else 'R' |
| 88 commit_msg = ('Webkit roll %s:%s\n' | 95 commit_msg = ('Blink roll %s:%s\n' |
| 89 '\n' | 96 '\n' |
| 90 'http://trac.webkit.org/log/?' | 97 'http://build.chromium.org/f/chromium/perf/dashboard/ui/' |
| 91 'rev=%s&stop_rev=%s&verbose=on\n' | 98 'changelog_blink.html?url=/trunk&range=%s:%s&mode=html' |
| 92 '\n' | 99 '\n' |
| 93 '%s=%s\n' % (old_rev, new_rev, | 100 '%s=%s\n' % (old_rev, new_rev, |
| 94 new_rev, old_rev+1, | 101 old_rev+1, new_rev, |
| 95 review_field, | 102 review_field, |
| 96 options.reviewers)) | 103 options.reviewers)) |
| 104 | |
| 105 if options.dry_run: | |
| 106 print 'Commit message: ' + commit_msg | |
| 107 return 0 | |
| 108 | |
| 97 subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS']) | 109 subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS']) |
| 98 subprocess2.check_call(['git', 'diff', options.upstream]) | 110 subprocess2.check_call(['git', 'diff', options.upstream]) |
| 99 upload_cmd = ['git', 'cl', 'upload'] | 111 upload_cmd = ['git', 'cl', 'upload'] |
| 100 if options.commit: | 112 if options.commit: |
| 101 upload_cmd.append('--use-commit-queue') | 113 upload_cmd.append('--use-commit-queue') |
| 102 if options.reviewers: | 114 if options.reviewers: |
| 103 upload_cmd.append('--send-mail') | 115 upload_cmd.append('--send-mail') |
| 104 if options.cc: | 116 if options.cc: |
| 105 upload_cmd.extend(['--cc', options.cc]) | 117 upload_cmd.extend(['--cc', options.cc]) |
| 106 subprocess2.check_call(upload_cmd) | 118 subprocess2.check_call(upload_cmd) |
| 107 finally: | 119 finally: |
| 108 subprocess2.check_output(['git', 'checkout', old_branch]) | 120 if not options.dry_run: |
| 109 subprocess2.check_output(['git', 'branch', '-D', 'webkit_roll']) | 121 subprocess2.check_output(['git', 'checkout', old_branch]) |
| 122 subprocess2.check_output(['git', 'branch', '-D', 'blink_roll']) | |
| 110 return 0 | 123 return 0 |
| 111 | 124 |
| 112 | 125 |
| 113 if __name__ == '__main__': | 126 if __name__ == '__main__': |
| 114 sys.exit(main()) | 127 sys.exit(main()) |
| OLD | NEW |