Chromium Code Reviews| Index: tools/safely-roll-webkit.py |
| diff --git a/tools/safely-roll-webkit.py b/tools/safely-roll-webkit.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..d7e21d4bbd6906b2cd36243b5fe694a2679fecee |
| --- /dev/null |
| +++ b/tools/safely-roll-webkit.py |
| @@ -0,0 +1,81 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Safely* rolls webkit. |
| + |
| +* As safely as currently possible. |
| +""" |
|
Dirk Pranke
2011/05/30 21:23:24
This comment isn't that helpful. I would replace i
M-A Ruel
2011/05/31 01:21:07
done
|
| + |
| +import logging |
| +import optparse |
| +import os |
| +import re |
| +import sys |
| + |
| +import find_depot_tools |
| +import scm |
| +import subprocess2 |
| + |
| + |
| +def die_with_error(msg): |
| + print >> sys.stderr, msg |
| + sys.exit(1) |
| + |
| + |
| +def process_deps(path, new_rev): |
| + """Update webkit_revision to |new_issue|. |
| + |
| + A bit hacky, could it be made better? |
| + """ |
| + content = open(path).read() |
| + old_line = r' "webkit_revision": "(\d+)",' |
| + new_line = ' "webkit_revision": "%d",' % new_rev |
|
Dirk Pranke
2011/05/30 21:23:24
Hm. I'd probably do this using readlines() for lin
M-A Ruel
2011/05/31 01:21:07
I prefer to keep the dumb logic here and change it
|
| + new_content = re.sub(old_line, new_line, content) |
| + if new_content == content: |
| + die_with_error('Failed to update the DEPS file') |
| + open(path, 'w').write(new_content) |
| + |
| + |
| +def main(): |
| + tool_dir = os.path.dirname(os.path.abspath(__file__)) |
| + parser = optparse.OptionParser(usage='<new webkit rev>') |
| + parser.add_option('-v', '--verbose', action='count', default=0) |
| + options, args = parser.parse_args() |
| + logging.basicConfig( |
| + level= |
| + [logging.WARNING, logging.INFO, logging.DEBUG][ |
| + min(2, options.verbose)]) |
| + if len(args) != 1: |
| + parser.error('Need only one arg: new webkit revision to roll to.') |
| + |
| + root_dir = os.path.dirname(tool_dir) |
| + os.chdir(root_dir) |
| + |
| + new_rev = int(args[0]) |
| + msg = 'Roll webkit revision to %s' % new_rev |
| + print msg |
| + |
| + # Silence the editor. |
| + os.environ['EDITOR'] = '/bin/true' |
| + |
| + old_branch = scm.GIT.GetBranch(root_dir) |
| + subprocess2.check_output( |
| + ['git', 'checkout', '-b', 'webkit_roll', 'origin/trunk']) |
| + try: |
| + process_deps(os.path.join(root_dir, 'DEPS'), new_rev) |
| + subprocess2.check_output(['git', 'commit', '-m', msg, 'DEPS']) |
| + changed = subprocess2.check_output( |
| + ['git', 'diff', 'origin/trunk', '--name-only']).splitlines() |
| + if changed != ['DEPS']: |
| + die_with_error('Make sure to be on a clean branch first') |
| + subprocess2.check_call(['git', 'cl', 'upload', '--use-commit-queue']) |
| + finally: |
| + subprocess2.check_output(['git', 'checkout', old_branch]) |
| + subprocess2.check_output(['git', 'branch', '-D', 'webkit_roll']) |
|
Dirk Pranke
2011/05/30 21:23:24
I personally don't like to delete branches until a
M-A Ruel
2011/05/31 01:21:07
By using check_call(git checkout -b) before the tr
|
| + return 0 |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |