1#!/usr/bin/env python 2# Copyright 2013 the V8 project authors. All rights reserved. 3# Redistribution and use in source and binary forms, with or without 4# modification, are permitted provided that the following conditions are 5# met: 6# 7# * Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# * Redistributions in binary form must reproduce the above 10# copyright notice, this list of conditions and the following 11# disclaimer in the documentation and/or other materials provided 12# with the distribution. 13# * Neither the name of Google Inc. nor the names of its 14# contributors may be used to endorse or promote products derived 15# from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29import optparse 30import re 31import sys 32 33from common_includes import * 34 35CONFIG = { 36 PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile", 37 DOT_GIT_LOCATION: ".git", 38} 39 40 41class Preparation(Step): 42 MESSAGE = "Preparation." 43 44 def RunStep(self): 45 self.InitialEnvironmentChecks() 46 self.CommonPrepare() 47 48 49class FetchLatestRevision(Step): 50 MESSAGE = "Fetching latest V8 revision." 51 52 def RunStep(self): 53 log = self.Git("svn log -1 --oneline").strip() 54 match = re.match(r"^r(\d+) ", log) 55 if not match: 56 self.Die("Could not extract current svn revision from log.") 57 self.Persist("latest", match.group(1)) 58 59 60class FetchLKGR(Step): 61 MESSAGE = "Fetching V8 LKGR." 62 63 def RunStep(self): 64 lkgr_url = "https://v8-status.appspot.com/lkgr" 65 # Retry several times since app engine might have issues. 66 self.Persist("lkgr", self.ReadURL(lkgr_url, wait_plan=[5, 20, 300, 300])) 67 68 69class PushToTrunk(Step): 70 MESSAGE = "Pushing to trunk if possible." 71 72 def RunStep(self): 73 self.RestoreIfUnset("latest") 74 self.RestoreIfUnset("lkgr") 75 latest = int(self._state["latest"]) 76 lkgr = int(self._state["lkgr"]) 77 if latest == lkgr: 78 print "ToT (r%d) is clean. Pushing to trunk." % latest 79 # TODO(machenbach): Call push to trunk script. 80 else: 81 print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk." 82 % (latest, lkgr)) 83 84 85def RunAutoRoll(config, 86 options, 87 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): 88 step_classes = [ 89 Preparation, 90 FetchLatestRevision, 91 FetchLKGR, 92 PushToTrunk, 93 ] 94 RunScript(step_classes, config, options, side_effect_handler) 95 96 97def BuildOptions(): 98 result = optparse.OptionParser() 99 result.add_option("-f", "--force", dest="f", 100 help="Don't prompt the user.", 101 default=True, action="store_true") 102 result.add_option("-s", "--step", dest="s", 103 help="Specify the step where to start work. Default: 0.", 104 default=0, type="int") 105 return result 106 107 108def Main(): 109 parser = BuildOptions() 110 (options, args) = parser.parse_args() 111 RunAutoRoll(CONFIG, options) 112 113if __name__ == "__main__": 114 sys.exit(Main()) 115