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