2 # Copyright (c) 2011 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 if new_content
== content
:
37 die_with_error('Failed to update the DEPS file')
38 open(path
, 'w').write(new_content
)
42 tool_dir
= os
.path
.dirname(os
.path
.abspath(__file__
))
43 parser
= optparse
.OptionParser(usage
='<new webkit rev>')
44 parser
.add_option('-v', '--verbose', action
='count', default
=0)
45 options
, args
= parser
.parse_args()
48 [logging
.WARNING
, logging
.INFO
, logging
.DEBUG
][
49 min(2, options
.verbose
)])
51 parser
.error('Need only one arg: new webkit revision to roll to.')
53 root_dir
= os
.path
.dirname(tool_dir
)
56 new_rev
= int(args
[0])
57 msg
= 'Roll webkit revision to %s' % new_rev
61 os
.environ
['EDITOR'] = 'true'
63 old_branch
= scm
.GIT
.GetBranch(root_dir
)
64 if old_branch
== 'webkit_roll':
66 'Please delete the branch webkit_roll and move to a different branch')
67 subprocess2
.check_output(
68 ['git', 'checkout', '-b', 'webkit_roll', 'origin/trunk'])
70 process_deps(os
.path
.join(root_dir
, 'DEPS'), new_rev
)
71 commit_msg
= msg
+ '\n\nTBR=\n'
72 subprocess2
.check_output(['git', 'commit', '-m', commit_msg
, 'DEPS'])
73 subprocess2
.check_call(['git', 'diff', 'origin/trunk'])
74 subprocess2
.check_call(['git', 'cl', 'upload', '--use-commit-queue'])
76 subprocess2
.check_output(['git', 'checkout', old_branch
])
77 subprocess2
.check_output(['git', 'branch', '-D', 'webkit_roll'])
81 if __name__
== '__main__':