From 780ae3146a2d99a3377256bf8933668352361fd2 Mon Sep 17 00:00:00 2001 From: "machenbach@chromium.org" Date: Fri, 17 Jan 2014 11:29:43 +0000 Subject: [PATCH] Activate calling push-to-trunk in auto-roll script. - Call push-to-trunk through python not through the shell - Restore tree state on script errors - Mock out python call in unit tests - The actual call stays behind a flag BUG= R=ulan@chromium.org Review URL: https://codereview.chromium.org/141633003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- tools/push-to-trunk/auto_roll.py | 23 +++++++++++++++++++---- tools/push-to-trunk/common_includes.py | 3 +++ tools/push-to-trunk/push_to_trunk.py | 14 ++++++++++++++ tools/push-to-trunk/test_scripts.py | 3 +++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tools/push-to-trunk/auto_roll.py b/tools/push-to-trunk/auto_roll.py index 94fd7b4c97..ac2067c61e 100755 --- a/tools/push-to-trunk/auto_roll.py +++ b/tools/push-to-trunk/auto_roll.py @@ -34,6 +34,9 @@ import sys import urllib from common_includes import * +import push_to_trunk +from push_to_trunk import PushToTrunkOptions +from push_to_trunk import RunPushToTrunk SETTINGS_LOCATION = "SETTINGS_LOCATION" @@ -49,6 +52,9 @@ class AutoRollOptions(CommonOptions): super(AutoRollOptions, self).__init__(options) self.requires_editor = False self.status_password = options.status_password + self.r = options.r + self.c = options.c + self.push = getattr(options, 'push', False) class Preparation(Step): @@ -150,10 +156,16 @@ class PushToTrunk(Step): # TODO(machenbach): Call push to trunk script. # TODO(machenbach): Update the script before calling it. - # self._side_effect_handler.Command( - # "tools/push-to-trunk/push-to-trunk.py", - # "-f -c %s -r %s" % (self._options.c, self._options.r)) - self.PushTreeStatus(self._state["tree_message"]) + try: + if self._options.push: + self._side_effect_handler.Call( + RunPushToTrunk, + push_to_trunk.CONFIG, + PushToTrunkOptions.MakeForcedOptions(self._options.r, + self._options.c), + self._side_effect_handler) + finally: + self.PushTreeStatus(self._state["tree_message"]) else: print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk." % (latest, lkgr)) @@ -179,6 +191,9 @@ def BuildOptions(): result.add_option("-c", "--chromium", dest="c", help=("Specify the path to your Chromium src/ " "directory to automate the V8 roll.")) + result.add_option("-p", "--push", + help="Push to trunk if possible. Dry run if unspecified.", + default=False, action="store_true") result.add_option("-r", "--reviewer", dest="r", help=("Specify the account name to be used for reviews.")) result.add_option("-s", "--step", dest="s", diff --git a/tools/push-to-trunk/common_includes.py b/tools/push-to-trunk/common_includes.py index a6096486a6..410be8bbc5 100644 --- a/tools/push-to-trunk/common_includes.py +++ b/tools/push-to-trunk/common_includes.py @@ -189,6 +189,9 @@ def Command(cmd, args="", prefix="", pipe=True): # Wrapper for side effects. class SideEffectHandler(object): + def Call(self, fun, *args, **kwargs): + return fun(*args, **kwargs) + def Command(self, cmd, args="", prefix="", pipe=True): return Command(cmd, args, prefix, pipe) diff --git a/tools/push-to-trunk/push_to_trunk.py b/tools/push-to-trunk/push_to_trunk.py index d861009c76..06e277ee46 100755 --- a/tools/push-to-trunk/push_to_trunk.py +++ b/tools/push-to-trunk/push_to_trunk.py @@ -53,6 +53,20 @@ CONFIG = { class PushToTrunkOptions(CommonOptions): + @staticmethod + def MakeForcedOptions(reviewer, chrome_path): + """Convenience wrapper.""" + class Options(object): + pass + options = Options() + options.s = 0 + options.l = None + options.f = True + options.m = False + options.r = reviewer + options.c = chrome_path + return PushToTrunkOptions(options) + def __init__(self, options): super(PushToTrunkOptions, self).__init__(options, options.m) self.requires_editor = not options.f diff --git a/tools/push-to-trunk/test_scripts.py b/tools/push-to-trunk/test_scripts.py index 56b44a6e48..a8200ee265 100644 --- a/tools/push-to-trunk/test_scripts.py +++ b/tools/push-to-trunk/test_scripts.py @@ -300,6 +300,9 @@ class ScriptTest(unittest.TestCase): "vi": LogMock, } + def Call(self, fun, *args, **kwargs): + print "Calling %s with %s and %s" % (str(fun), str(args), str(kwargs)) + def Command(self, cmd, args="", prefix="", pipe=True): return ScriptTest.MOCKS[cmd](self, cmd, args)