blob: 581aecd5c6bb1ddfd3c2514f7c8130d06d502412 [file] [log] [blame]
[email protected]bd2056392011-07-25 21:12:341#!/usr/bin/env python
[email protected]b77cb6242012-01-12 01:34:032# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]bd2056392011-07-25 21:12:343# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
[email protected]b69cc1d2013-05-09 18:01:326"""Generate a CL to roll Blink to the specified revision number and post
[email protected]bd2056392011-07-25 21:12:347it to Rietveld so that the CL will land automatically if it passes the
8commit-queue's checks.
9"""
10
11import logging
12import optparse
13import os
14import re
15import sys
16
17import find_depot_tools
18import scm
19import subprocess2
20
21
22def die_with_error(msg):
23 print >> sys.stderr, msg
24 sys.exit(1)
25
26
[email protected]4b8aa4c2013-04-24 01:54:2927def process_deps(path, new_rev, is_dry_run):
[email protected]bd2056392011-07-25 21:12:3428 """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]8c604f402012-06-13 00:11:4936 old_rev = re.search(old_line, content).group(2)
37 if not old_rev or new_content == content:
[email protected]bd2056392011-07-25 21:12:3438 die_with_error('Failed to update the DEPS file')
[email protected]8c604f402012-06-13 00:11:4939
[email protected]4b8aa4c2013-04-24 01:54:2940 if not is_dry_run:
41 open(path, 'w').write(new_content)
[email protected]8c604f402012-06-13 00:11:4942 return old_rev
[email protected]bd2056392011-07-25 21:12:3443
44
45def main():
46 tool_dir = os.path.dirname(os.path.abspath(__file__))
[email protected]b69cc1d2013-05-09 18:01:3247 parser = optparse.OptionParser(usage='%prog [options] <new blink rev>')
[email protected]bd2056392011-07-25 21:12:3448 parser.add_option('-v', '--verbose', action='count', default=0)
[email protected]4b8aa4c2013-04-24 01:54:2949 parser.add_option('--dry-run', action='store_true')
[email protected]a1f86ac92012-08-30 20:18:5950 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]148e4f532012-08-31 20:16:0754 parser.add_option('-r', '--reviewers', default='',
55 help='Add given users as either reviewers or TBR as'
56 ' appropriate.')
[email protected]a1f86ac92012-08-30 20:18:5957 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]148e4f532012-08-31 20:16:0761 parser.add_option('--cc', help='CC email addresses for issue.')
[email protected]a1f86ac92012-08-30 20:18:5962
[email protected]bd2056392011-07-25 21:12:3463 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]2f603502013-02-07 16:49:1769 parser.print_help()
70 exit(0)
[email protected]bd2056392011-07-25 21:12:3471
72 root_dir = os.path.dirname(tool_dir)
73 os.chdir(root_dir)
74
75 new_rev = int(args[0])
[email protected]bd2056392011-07-25 21:12:3476
77 # Silence the editor.
[email protected]4677a942011-08-10 22:35:1678 os.environ['EDITOR'] = 'true'
[email protected]bd2056392011-07-25 21:12:3479
80 old_branch = scm.GIT.GetBranch(root_dir)
[email protected]4b8aa4c2013-04-24 01:54:2981 if old_branch == 'blink_roll':
[email protected]bd2056392011-07-25 21:12:3482 parser.error(
[email protected]4b8aa4c2013-04-24 01:54:2983 '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]bd2056392011-07-25 21:12:3489 try:
[email protected]4b8aa4c2013-04-24 01:54:2990 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]148e4f532012-08-31 20:16:0794 review_field = 'TBR' if options.commit else 'R'
[email protected]4b8aa4c2013-04-24 01:54:2995 commit_msg = ('Blink roll %s:%s\n'
[email protected]4a6709d42012-10-30 20:31:5496 '\n'
[email protected]4b8aa4c2013-04-24 01:54:2997 'http://build.chromium.org/f/chromium/perf/dashboard/ui/'
98 'changelog_blink.html?url=/trunk&range=%s:%s&mode=html'
[email protected]4a6709d42012-10-30 20:31:5499 '\n'
100 '%s=%s\n' % (old_rev, new_rev,
[email protected]4b8aa4c2013-04-24 01:54:29101 old_rev+1, new_rev,
[email protected]4a6709d42012-10-30 20:31:54102 review_field,
103 options.reviewers))
[email protected]4b8aa4c2013-04-24 01:54:29104
105 if options.dry_run:
106 print 'Commit message: ' + commit_msg
107 return 0
108
[email protected]bd2056392011-07-25 21:12:34109 subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS'])
[email protected]a1f86ac92012-08-30 20:18:59110 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]148e4f532012-08-31 20:16:07114 if options.reviewers:
115 upload_cmd.append('--send-mail')
116 if options.cc:
117 upload_cmd.extend(['--cc', options.cc])
[email protected]a1f86ac92012-08-30 20:18:59118 subprocess2.check_call(upload_cmd)
[email protected]bd2056392011-07-25 21:12:34119 finally:
[email protected]4b8aa4c2013-04-24 01:54:29120 if not options.dry_run:
121 subprocess2.check_output(['git', 'checkout', old_branch])
122 subprocess2.check_output(['git', 'branch', '-D', 'blink_roll'])
[email protected]bd2056392011-07-25 21:12:34123 return 0
124
125
126if __name__ == '__main__':
127 sys.exit(main())