OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 the V8 project 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. |
| 5 |
| 6 """ |
| 7 Script for auto-increasing the version on bleeding_edge. |
| 8 |
| 9 The script can be run regularly by a cron job. It will increase the build |
| 10 level of the version on bleeding_edge if: |
| 11 - the lkgr version is smaller than the version of the latest revision, |
| 12 - the lkgr version is not a version change itself, |
| 13 - the tree is not closed for maintenance. |
| 14 |
| 15 The new version will be the maximum of the bleeding_edge and trunk versions +1. |
| 16 E.g. latest bleeding_edge version: 3.22.11.0 and latest trunk 3.23.0.0 gives |
| 17 the new version 3.23.1.0. |
| 18 |
| 19 This script requires a depot tools git checkout. I.e. 'fetch v8'. |
| 20 """ |
| 21 |
| 22 import argparse |
| 23 import os |
| 24 import sys |
| 25 |
| 26 from common_includes import * |
| 27 |
| 28 CONFIG = { |
| 29 PERSISTFILE_BASENAME: "/tmp/v8-bump-up-version-tempfile", |
| 30 VERSION_FILE: "src/version.cc", |
| 31 } |
| 32 |
| 33 VERSION_BRANCH = "auto-bump-up-version" |
| 34 |
| 35 |
| 36 class Preparation(Step): |
| 37 MESSAGE = "Preparation." |
| 38 |
| 39 def RunStep(self): |
| 40 # Check for a clean workdir. |
| 41 if not self.GitIsWorkdirClean(): # pragma: no cover |
| 42 # This is in case a developer runs this script on a dirty tree. |
| 43 self.GitStash() |
| 44 |
| 45 # TODO(machenbach): This should be called master after the git switch. |
| 46 self.GitCheckout("bleeding_edge") |
| 47 |
| 48 self.GitPull() |
| 49 |
| 50 # Ensure a clean version branch. |
| 51 self.DeleteBranch(VERSION_BRANCH) |
| 52 |
| 53 |
| 54 class GetCurrentBleedingEdgeVersion(Step): |
| 55 MESSAGE = "Get latest bleeding edge version." |
| 56 |
| 57 def RunStep(self): |
| 58 # TODO(machenbach): This should be called trunk after the git switch. |
| 59 self.GitCheckout("bleeding_edge") |
| 60 |
| 61 # Store latest version and revision. |
| 62 self.ReadAndPersistVersion() |
| 63 self["latest_version"] = self.ArrayToVersion("") |
| 64 self["latest"] = self.GitLog(n=1, format="%H") |
| 65 print "Bleeding edge version: %s" % self["latest_version"] |
| 66 |
| 67 |
| 68 # This step is pure paranoia. It forbids the script to continue if the last |
| 69 # commit changed version.cc. Just in case the other bailout has a bug, this |
| 70 # prevents the script from continuously commiting version changes. |
| 71 class LastChangeBailout(Step): |
| 72 MESSAGE = "Stop script if the last change modified the version." |
| 73 |
| 74 def RunStep(self): |
| 75 if self._config[VERSION_FILE] in self.GitChangedFiles(self["latest"]): |
| 76 print "Stop due to recent version change." |
| 77 return True |
| 78 |
| 79 |
| 80 # TODO(machenbach): Implement this for git. |
| 81 class FetchLKGR(Step): |
| 82 MESSAGE = "Fetching V8 LKGR." |
| 83 |
| 84 def RunStep(self): |
| 85 lkgr_url = "https://v8-status.appspot.com/lkgr" |
| 86 self["lkgr_svn"] = self.ReadURL(lkgr_url, wait_plan=[5]) |
| 87 |
| 88 |
| 89 # TODO(machenbach): Implement this for git. With a git lkgr we could simply |
| 90 # checkout that revision. With svn, we have to search backwards until that |
| 91 # revision is found. |
| 92 class GetLKGRVersion(Step): |
| 93 MESSAGE = "Get bleeding edge lkgr version." |
| 94 |
| 95 def RunStep(self): |
| 96 self.GitCheckout("bleeding_edge") |
| 97 # If the commit was made from svn, there is a mapping entry in the commit |
| 98 # message. |
| 99 self["lkgr"] = self.GitLog( |
| 100 grep="^git-svn-id: [^@]*@%s [A-Za-z0-9-]*$" % self["lkgr_svn"], |
| 101 format="%H") |
| 102 |
| 103 # FIXME(machenbach): http://crbug.com/391712 can lead to svn lkgrs on the |
| 104 # trunk branch (rarely). |
| 105 if not self["lkgr"]: # pragma: no cover |
| 106 self.Die("No git hash found for svn lkgr.") |
| 107 |
| 108 self.GitCreateBranch(VERSION_BRANCH, self["lkgr"]) |
| 109 self.ReadAndPersistVersion("lkgr_") |
| 110 self["lkgr_version"] = self.ArrayToVersion("lkgr_") |
| 111 print "LKGR version: %s" % self["lkgr_version"] |
| 112 |
| 113 # Ensure a clean version branch. |
| 114 self.GitCheckout("bleeding_edge") |
| 115 self.DeleteBranch(VERSION_BRANCH) |
| 116 |
| 117 |
| 118 class LKGRVersionUpToDateBailout(Step): |
| 119 MESSAGE = "Stop script if the lkgr has a renewed version." |
| 120 |
| 121 def RunStep(self): |
| 122 # If a version-change commit becomes the lkgr, don't bump up the version |
| 123 # again. |
| 124 if self._config[VERSION_FILE] in self.GitChangedFiles(self["lkgr"]): |
| 125 print "Stop because the lkgr is a version change itself." |
| 126 return True |
| 127 |
| 128 # Don't bump up the version if it got updated already after the lkgr. |
| 129 if SortingKey(self["lkgr_version"]) < SortingKey(self["latest_version"]): |
| 130 print("Stop because the latest version already changed since the lkgr " |
| 131 "version.") |
| 132 return True |
| 133 |
| 134 |
| 135 class GetTrunkVersion(Step): |
| 136 MESSAGE = "Get latest trunk version." |
| 137 |
| 138 def RunStep(self): |
| 139 # TODO(machenbach): This should be called trunk after the git switch. |
| 140 self.GitCheckout("master") |
| 141 self.GitPull() |
| 142 self.ReadAndPersistVersion("trunk_") |
| 143 self["trunk_version"] = self.ArrayToVersion("trunk_") |
| 144 print "Trunk version: %s" % self["trunk_version"] |
| 145 |
| 146 |
| 147 class CalculateVersion(Step): |
| 148 MESSAGE = "Calculate the new version." |
| 149 |
| 150 def RunStep(self): |
| 151 if self["lkgr_build"] == "9999": # pragma: no cover |
| 152 # If version control on bleeding edge was switched off, just use the last |
| 153 # trunk version. |
| 154 self["lkgr_version"] = self["trunk_version"] |
| 155 |
| 156 # The new version needs to be greater than the max on bleeding edge and |
| 157 # trunk. |
| 158 max_version = max(self["trunk_version"], |
| 159 self["lkgr_version"], |
| 160 key=SortingKey) |
| 161 |
| 162 # Strip off possible leading zeros. |
| 163 self["new_major"], self["new_minor"], self["new_build"], _ = ( |
| 164 map(str, map(int, max_version.split(".")))) |
| 165 |
| 166 self["new_build"] = str(int(self["new_build"]) + 1) |
| 167 self["new_patch"] = "0" |
| 168 |
| 169 self["new_version"] = ("%s.%s.%s.0" % |
| 170 (self["new_major"], self["new_minor"], self["new_build"])) |
| 171 print "New version is %s" % self["new_version"] |
| 172 |
| 173 if self._options.dry_run: # pragma: no cover |
| 174 print "Dry run, skipping version change." |
| 175 return True |
| 176 |
| 177 |
| 178 class CheckTreeStatus(Step): |
| 179 MESSAGE = "Checking v8 tree status message." |
| 180 |
| 181 def RunStep(self): |
| 182 status_url = "https://v8-status.appspot.com/current?format=json" |
| 183 status_json = self.ReadURL(status_url, wait_plan=[5, 20, 300, 300]) |
| 184 message = json.loads(status_json)["message"] |
| 185 if re.search(r"maintenance|no commits", message, flags=re.I): |
| 186 print "Skip version change by tree status: \"%s\"" % message |
| 187 return True |
| 188 |
| 189 |
| 190 class ChangeVersion(Step): |
| 191 MESSAGE = "Bump up the version." |
| 192 |
| 193 def RunStep(self): |
| 194 self.GitCreateBranch(VERSION_BRANCH, "bleeding_edge") |
| 195 |
| 196 self.SetVersion(self.Config(VERSION_FILE), "new_") |
| 197 |
| 198 try: |
| 199 self.GitCommit("[Auto-roll] Bump up version to %s\n\nTBR=%s" % |
| 200 (self["new_version"], self._options.author)) |
| 201 self.GitUpload(author=self._options.author, |
| 202 force=self._options.force_upload) |
| 203 self.GitDCommit() |
| 204 print "Successfully changed the version." |
| 205 finally: |
| 206 # Clean up. |
| 207 self.GitCheckout("bleeding_edge") |
| 208 self.DeleteBranch(VERSION_BRANCH) |
| 209 |
| 210 |
| 211 class BumpUpVersion(ScriptsBase): |
| 212 def _PrepareOptions(self, parser): |
| 213 parser.add_argument("--dry_run", help="Don't commit the new version.", |
| 214 default=False, action="store_true") |
| 215 |
| 216 def _ProcessOptions(self, options): # pragma: no cover |
| 217 if not options.dry_run and not options.author: |
| 218 print "Specify your chromium.org email with -a" |
| 219 return False |
| 220 options.wait_for_lgtm = False |
| 221 options.force_readline_defaults = True |
| 222 options.force_upload = True |
| 223 return True |
| 224 |
| 225 def _Steps(self): |
| 226 return [ |
| 227 Preparation, |
| 228 GetCurrentBleedingEdgeVersion, |
| 229 LastChangeBailout, |
| 230 FetchLKGR, |
| 231 GetLKGRVersion, |
| 232 LKGRVersionUpToDateBailout, |
| 233 GetTrunkVersion, |
| 234 CalculateVersion, |
| 235 CheckTreeStatus, |
| 236 ChangeVersion, |
| 237 ] |
| 238 |
| 239 if __name__ == "__main__": # pragma: no cover |
| 240 sys.exit(BumpUpVersion(CONFIG).Run()) |
OLD | NEW |