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
4 # found in the LICENSE file.
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
17 import find_depot_tools
22 def die_with_error(msg
):
23 print >> sys
.stderr
, msg
27 def process_deps(path
, new_rev
):
28 """Update webkit_revision to |new_issue|.
30 A bit hacky, could it be made better?
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)
36 old_rev
= re
.search(old_line
, content
).group(2)
37 if not old_rev
or new_content
== content
:
38 die_with_error('Failed to update the DEPS file')
40 open(path
, 'w').write(new_content
)
45 tool_dir
= os
.path
.dirname(os
.path
.abspath(__file__
))
46 parser
= optparse
.OptionParser(usage
='<new webkit rev>')
47 parser
.add_option('-v', '--verbose', action
='count', default
=0)
48 parser
.add_option('--commit', action
='store_true', default
=True,
49 help='(default) Put change in commit queue on upload.')
50 parser
.add_option('--no-commit', action
='store_false', dest
='commit',
51 help='Don\'t put change in commit queue on upload.')
52 parser
.add_option('-r', '--reviewers', default
='',
53 help='Add given users as either reviewers or TBR as'
55 parser
.add_option('--upstream', default
='origin/master',
56 help='(default "%default") Use given start point for change'
57 ' to upload. For instance, if you use the old git workflow,'
58 ' you might set it to "origin/trunk".')
59 parser
.add_option('--cc', help='CC email addresses for issue.')
61 options
, args
= parser
.parse_args()
64 [logging
.WARNING
, logging
.INFO
, logging
.DEBUG
][
65 min(2, options
.verbose
)])
67 parser
.error('Need only one arg: new webkit revision to roll to.')
69 root_dir
= os
.path
.dirname(tool_dir
)
72 new_rev
= int(args
[0])
73 print 'Roll webkit revision to %s' % new_rev
76 os
.environ
['EDITOR'] = 'true'
78 old_branch
= scm
.GIT
.GetBranch(root_dir
)
79 if old_branch
== 'webkit_roll':
81 'Please delete the branch webkit_roll and move to a different branch')
82 subprocess2
.check_output(
83 ['git', 'checkout', '-b', 'webkit_roll', options
.upstream
])
85 old_rev
= process_deps(os
.path
.join(root_dir
, 'DEPS'), new_rev
)
86 review_field
= 'TBR' if options
.commit
else 'R'
87 commit_msg
= 'Webkit roll %s:%s\n\n%s=%s\n' % (old_rev
, new_rev
,
90 subprocess2
.check_output(['git', 'commit', '-m', commit_msg
, 'DEPS'])
91 subprocess2
.check_call(['git', 'diff', options
.upstream
])
92 upload_cmd
= ['git', 'cl', 'upload']
94 upload_cmd
.append('--use-commit-queue')
96 upload_cmd
.append('--send-mail')
98 upload_cmd
.extend(['--cc', options
.cc
])
99 subprocess2
.check_call(upload_cmd
)
101 subprocess2
.check_output(['git', 'checkout', old_branch
])
102 subprocess2
.check_output(['git', 'branch', '-D', 'webkit_roll'])
106 if __name__
== '__main__':