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.
6 # This script retrieves the history of all V8 branches and trunk revisions and
7 # their corresponding Chromium revisions.
9 # Requires a chromium checkout with branch heads:
10 # gclient sync --with_branch_heads
21 from common_includes import *
23 DEPS_FILE = "DEPS_FILE"
27 BRANCHNAME: "retrieve-v8-releases",
28 PERSISTFILE_BASENAME: "/tmp/v8-releases-tempfile",
29 DOT_GIT_LOCATION: ".git",
30 VERSION_FILE: "src/version.cc",
34 # Expression for retrieving the bleeding edge revision from a commit message.
35 PUSH_MESSAGE_RE = re.compile(r".* \(based on bleeding_edge revision r(\d+)\)$")
37 # Expression for retrieving the merged patches from a merge commit message
38 # (old and new format).
39 MERGE_MESSAGE_RE = re.compile(r"^.*[M|m]erged (.+)(\)| into).*$", re.M)
41 # Expression for retrieving reverted patches from a commit message (old and
43 ROLLBACK_MESSAGE_RE = re.compile(r"^.*[R|r]ollback of (.+)(\)| in).*$", re.M)
45 # Expression for retrieving the code review link.
46 REVIEW_LINK_RE = re.compile(r"^Review URL: (.+)$", re.M)
48 # Expression with three versions (historical) for extracting the v8 revision
49 # from the chromium DEPS file.
50 DEPS_RE = re.compile(r'^\s*(?:"v8_revision": "'
51 '|\(Var\("googlecode_url"\) % "v8"\) \+ "\/trunk@'
52 '|"http\:\/\/v8\.googlecode\.com\/svn\/trunk@)'
56 def SortingKey(version):
57 """Key for sorting version number strings: '3.11' > '3.2.1.1'"""
58 version_keys = map(int, version.split("."))
59 # Fill up to full version numbers to normalize comparison.
60 while len(version_keys) < 4:
61 version_keys.append(0)
63 return ".".join(map("{0:03d}".format, version_keys))
66 def SortBranches(branches):
67 """Sort branches with version number names."""
68 return sorted(branches, key=SortingKey, reverse=True)
71 def FilterDuplicatesAndReverse(cr_releases):
72 """Returns the chromium releases in reverse order filtered by v8 revision
75 cr_releases is a list of [cr_rev, v8_rev] reverse-sorted by cr_rev.
79 for release in reversed(cr_releases):
80 if last == release[1]:
83 result.append(release)
87 def BuildRevisionRanges(cr_releases):
88 """Returns a mapping of v8 revision -> chromium ranges.
89 The ranges are comma-separated, each range has the form R1:R2. The newest
90 entry is the only one of the form R1, as there is no end range.
92 cr_releases is a list of [cr_rev, v8_rev] reverse-sorted by cr_rev.
93 cr_rev either refers to a chromium svn revision or a chromium branch number.
96 cr_releases = FilterDuplicatesAndReverse(cr_releases)
98 # Visit pairs of cr releases from oldest to newest.
99 for cr_from, cr_to in itertools.izip(
100 cr_releases, itertools.islice(cr_releases, 1, None)):
102 # Assume the chromium revisions are all different.
103 assert cr_from[0] != cr_to[0]
105 # TODO(machenbach): Subtraction is not git friendly.
106 ran = "%s:%d" % (cr_from[0], int(cr_to[0]) - 1)
108 # Collect the ranges in lists per revision.
109 range_lists.setdefault(cr_from[1], []).append(ran)
111 # Add the newest revision.
113 range_lists.setdefault(cr_releases[-1][1], []).append(cr_releases[-1][0])
115 # Stringify and comma-separate the range lists.
116 return dict((rev, ", ".join(ran)) for rev, ran in range_lists.iteritems())
119 def MatchSafe(match):
121 return match.group(1)
126 class Preparation(Step):
127 MESSAGE = "Preparation."
134 class RetrieveV8Releases(Step):
135 MESSAGE = "Retrieve all V8 releases."
137 def ExceedsMax(self, releases):
138 return (self._options.max_releases > 0
139 and len(releases) > self._options.max_releases)
141 def GetBleedingEdgeFromPush(self, title):
142 return MatchSafe(PUSH_MESSAGE_RE.match(title))
144 def GetMergedPatches(self, body):
145 patches = MatchSafe(MERGE_MESSAGE_RE.search(body))
147 patches = MatchSafe(ROLLBACK_MESSAGE_RE.search(body))
149 # Indicate reverted patches with a "-".
150 patches = "-%s" % patches
153 def GetRelease(self, git_hash, branch):
154 self.ReadAndPersistVersion()
155 base_version = [self["major"], self["minor"], self["build"]]
156 version = ".".join(base_version)
157 body = self.GitLog(n=1, format="%B", git_hash=git_hash)
160 if self["patch"] != "0":
161 version += ".%s" % self["patch"]
162 patches = self.GetMergedPatches(body)
164 title = self.GitLog(n=1, format="%s", git_hash=git_hash)
165 revision = self.GitSVNFindSVNRev(git_hash)
167 # The SVN revision on the branch.
168 "revision": revision,
169 # The SVN revision on bleeding edge (only for newer trunk pushes).
170 "bleeding_edge": self.GetBleedingEdgeFromPush(title),
173 # The version for displaying in the form 3.26.3 or 3.26.3.12.
175 # The date of the commit.
176 "date": self.GitLog(n=1, format="%ci", git_hash=git_hash),
177 # Merged patches if available in the form 'r1234, r2345'.
178 "patches_merged": patches,
179 # Default for easier output formatting.
180 "chromium_revision": "",
181 # Default for easier output formatting.
182 "chromium_branch": "",
183 # Link to the CL on code review. Trunk pushes are not uploaded, so this
184 # field will be populated below with the recent roll CL link.
185 "review_link": MatchSafe(REVIEW_LINK_RE.search(body)),
186 # Link to the commit message on google code.
187 "revision_link": ("https://code.google.com/p/v8/source/detail?r=%s"
191 def GetReleasesFromBranch(self, branch):
192 self.GitReset("svn/%s" % branch)
195 for git_hash in self.GitLog(format="%H").splitlines():
196 if self._config[VERSION_FILE] not in self.GitChangedFiles(git_hash):
198 if self.ExceedsMax(releases):
199 break # pragma: no cover
200 if not self.GitCheckoutFileSafe(self._config[VERSION_FILE], git_hash):
201 break # pragma: no cover
203 release, patch_level = self.GetRelease(git_hash, branch)
204 releases.append(release)
206 # Follow branches only until their creation point.
207 # TODO(machenbach): This omits patches if the version file wasn't
208 # manipulated correctly. Find a better way to detect the point where
209 # the parent of the branch head leads to the trunk branch.
210 if branch != "trunk" and patch_level == "0":
213 # Allow Ctrl-C interrupt.
214 except (KeyboardInterrupt, SystemExit): # pragma: no cover
217 # Clean up checked-out version file.
218 self.GitCheckoutFileSafe(self._config[VERSION_FILE], "HEAD")
222 self.GitCreateBranch(self._config[BRANCHNAME])
223 # Get relevant remote branches, e.g. "svn/3.25".
224 branches = filter(lambda s: re.match(r"^svn/\d+\.\d+$", s),
226 # Remove 'svn/' prefix.
227 branches = map(lambda s: s[4:], branches)
230 if self._options.branch == 'recent':
231 # Get only recent development on trunk, beta and stable.
232 if self._options.max_releases == 0: # pragma: no cover
233 self._options.max_releases = 10
234 beta, stable = SortBranches(branches)[0:2]
235 releases += self.GetReleasesFromBranch(stable)
236 releases += self.GetReleasesFromBranch(beta)
237 releases += self.GetReleasesFromBranch("trunk")
238 elif self._options.branch == 'all': # pragma: no cover
239 # Retrieve the full release history.
240 for branch in branches:
241 releases += self.GetReleasesFromBranch(branch)
242 releases += self.GetReleasesFromBranch("trunk")
243 else: # pragma: no cover
244 # Retrieve history for a specified branch.
245 assert self._options.branch in branches + ["trunk"]
246 releases += self.GetReleasesFromBranch(self._options.branch)
248 self["releases"] = sorted(releases,
249 key=lambda r: SortingKey(r["version"]),
253 # TODO(machenbach): Parts of the Chromium setup are c/p from the chromium_roll
255 class CheckChromium(Step):
256 MESSAGE = "Check the chromium checkout."
259 self["chrome_path"] = self._options.chromium
262 class SwitchChromium(Step):
263 MESSAGE = "Switch to Chromium checkout."
264 REQUIRES = "chrome_path"
267 self["v8_path"] = os.getcwd()
268 os.chdir(self["chrome_path"])
269 # Check for a clean workdir.
270 if not self.GitIsWorkdirClean(): # pragma: no cover
271 self.Die("Workspace is not clean. Please commit or undo your changes.")
272 # Assert that the DEPS file is there.
273 if not os.path.exists(self.Config(DEPS_FILE)): # pragma: no cover
274 self.Die("DEPS file not present.")
277 class UpdateChromiumCheckout(Step):
278 MESSAGE = "Update the checkout and create a new branch."
279 REQUIRES = "chrome_path"
282 os.chdir(self["chrome_path"])
283 self.GitCheckout("master")
285 self.GitCreateBranch(self.Config(BRANCHNAME))
288 class RetrieveChromiumV8Releases(Step):
289 MESSAGE = "Retrieve V8 releases from Chromium DEPS."
290 REQUIRES = "chrome_path"
293 os.chdir(self["chrome_path"])
295 trunk_releases = filter(lambda r: r["branch"] == "trunk", self["releases"])
296 if not trunk_releases: # pragma: no cover
297 print "No trunk releases detected. Skipping chromium history."
300 oldest_v8_rev = int(trunk_releases[-1]["revision"])
304 for git_hash in self.GitLog(format="%H", grep="V8").splitlines():
305 if self._config[DEPS_FILE] not in self.GitChangedFiles(git_hash):
307 if not self.GitCheckoutFileSafe(self._config[DEPS_FILE], git_hash):
308 break # pragma: no cover
309 deps = FileToText(self.Config(DEPS_FILE))
310 match = DEPS_RE.search(deps)
312 svn_rev = self.GitSVNFindSVNRev(git_hash)
313 v8_rev = match.group(1)
314 cr_releases.append([svn_rev, v8_rev])
316 # Stop after reaching beyond the last v8 revision we want to update.
317 # We need a small buffer for possible revert/reland frenzies.
318 # TODO(machenbach): Subtraction is not git friendly.
319 if int(v8_rev) < oldest_v8_rev - 100:
320 break # pragma: no cover
322 # Allow Ctrl-C interrupt.
323 except (KeyboardInterrupt, SystemExit): # pragma: no cover
327 self.GitCheckoutFileSafe(self._config[DEPS_FILE], "HEAD")
329 # Add the chromium ranges to the v8 trunk releases.
330 all_ranges = BuildRevisionRanges(cr_releases)
331 trunk_dict = dict((r["revision"], r) for r in trunk_releases)
332 for revision, ranges in all_ranges.iteritems():
333 trunk_dict.get(revision, {})["chromium_revision"] = ranges
336 # TODO(machenbach): Unify common code with method above.
337 class RietrieveChromiumBranches(Step):
338 MESSAGE = "Retrieve Chromium branch information."
339 REQUIRES = "chrome_path"
342 os.chdir(self["chrome_path"])
344 trunk_releases = filter(lambda r: r["branch"] == "trunk", self["releases"])
345 if not trunk_releases: # pragma: no cover
346 print "No trunk releases detected. Skipping chromium history."
349 oldest_v8_rev = int(trunk_releases[-1]["revision"])
351 # Filter out irrelevant branches.
352 branches = filter(lambda r: re.match(r"branch-heads/\d+", r),
355 # Transform into pure branch numbers.
356 branches = map(lambda r: int(re.match(r"branch-heads/(\d+)", r).group(1)),
359 branches = sorted(branches, reverse=True)
363 for branch in branches:
364 if not self.GitCheckoutFileSafe(self._config[DEPS_FILE],
365 "branch-heads/%d" % branch):
366 break # pragma: no cover
367 deps = FileToText(self.Config(DEPS_FILE))
368 match = DEPS_RE.search(deps)
370 v8_rev = match.group(1)
371 cr_branches.append([str(branch), v8_rev])
373 # Stop after reaching beyond the last v8 revision we want to update.
374 # We need a small buffer for possible revert/reland frenzies.
375 # TODO(machenbach): Subtraction is not git friendly.
376 if int(v8_rev) < oldest_v8_rev - 100:
377 break # pragma: no cover
379 # Allow Ctrl-C interrupt.
380 except (KeyboardInterrupt, SystemExit): # pragma: no cover
384 self.GitCheckoutFileSafe(self._config[DEPS_FILE], "HEAD")
386 # Add the chromium branches to the v8 trunk releases.
387 all_ranges = BuildRevisionRanges(cr_branches)
388 trunk_dict = dict((r["revision"], r) for r in trunk_releases)
389 for revision, ranges in all_ranges.iteritems():
390 trunk_dict.get(revision, {})["chromium_branch"] = ranges
393 class SwitchV8(Step):
394 MESSAGE = "Returning to V8 checkout."
395 REQUIRES = "chrome_path"
398 self.GitCheckout("master")
399 self.GitDeleteBranch(self.Config(BRANCHNAME))
400 os.chdir(self["v8_path"])
404 MESSAGE = "Clean up."
410 class WriteOutput(Step):
411 MESSAGE = "Print output."
414 if self._options.csv:
415 with open(self._options.csv, "w") as f:
416 writer = csv.DictWriter(f,
417 ["version", "branch", "revision",
418 "chromium_revision", "patches_merged"],
420 extrasaction="ignore")
421 for release in self["releases"]:
422 writer.writerow(release)
423 if self._options.json:
424 with open(self._options.json, "w") as f:
425 f.write(json.dumps(self["releases"]))
426 if not self._options.csv and not self._options.json:
427 print self["releases"] # pragma: no cover
430 class Releases(ScriptsBase):
431 def _PrepareOptions(self, parser):
432 parser.add_argument("-b", "--branch", default="recent",
433 help=("The branch to analyze. If 'all' is specified, "
434 "analyze all branches. If 'recent' (default) "
435 "is specified, track beta, stable and trunk."))
436 parser.add_argument("-c", "--chromium",
437 help=("The path to your Chromium src/ "
438 "directory to automate the V8 roll."))
439 parser.add_argument("--csv", help="Path to a CSV file for export.")
440 parser.add_argument("-m", "--max-releases", type=int, default=0,
441 help="The maximum number of releases to track.")
442 parser.add_argument("--json", help="Path to a JSON file for export.")
444 def _ProcessOptions(self, options): # pragma: no cover
453 UpdateChromiumCheckout,
454 RetrieveChromiumV8Releases,
455 RietrieveChromiumBranches,
462 if __name__ == "__main__": # pragma: no cover
463 sys.exit(Releases(CONFIG).Run())