• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6import argparse
7import json
8import os
9import sys
10import urllib
11
12from common_includes import *
13import chromium_roll
14
15CONFIG = {
16  PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile",
17}
18
19CR_DEPS_URL = 'http://src.chromium.org/svn/trunk/src/DEPS'
20
21class CheckActiveRoll(Step):
22  MESSAGE = "Check active roll."
23
24  @staticmethod
25  def ContainsChromiumRoll(changes):
26    for change in changes:
27      if change["subject"].startswith("Update V8 to"):
28        return True
29    return False
30
31  def RunStep(self):
32    params = {
33      "closed": 3,
34      "owner": self._options.author,
35      "limit": 30,
36      "format": "json",
37    }
38    params = urllib.urlencode(params)
39    search_url = "https://codereview.chromium.org/search"
40    result = self.ReadURL(search_url, params, wait_plan=[5, 20])
41    if self.ContainsChromiumRoll(json.loads(result)["results"]):
42      print "Stop due to existing Chromium roll."
43      return True
44
45
46class DetectLastPush(Step):
47  MESSAGE = "Detect commit ID of the last push to trunk."
48
49  def RunStep(self):
50    push_hash = self.FindLastTrunkPush(include_patches=True)
51    self["last_push"] = self.GitSVNFindSVNRev(push_hash)
52
53
54class DetectLastRoll(Step):
55  MESSAGE = "Detect commit ID of the last Chromium roll."
56
57  def RunStep(self):
58    # Interpret the DEPS file to retrieve the v8 revision.
59    Var = lambda var: '%s'
60    exec(self.ReadURL(CR_DEPS_URL))
61    last_roll = vars['v8_revision']
62    if last_roll >= self["last_push"]:
63      print("There is no newer v8 revision than the one in Chromium (%s)."
64            % last_roll)
65      return True
66
67
68class RollChromium(Step):
69  MESSAGE = "Roll V8 into Chromium."
70
71  def RunStep(self):
72    if self._options.roll:
73      args = [
74        "--author", self._options.author,
75        "--reviewer", self._options.reviewer,
76        "--chromium", self._options.chromium,
77        "--force",
78      ]
79      if self._options.sheriff:
80        args.extend([
81            "--sheriff", "--googlers-mapping", self._options.googlers_mapping])
82      R = chromium_roll.ChromiumRoll
83      self._side_effect_handler.Call(
84          R(chromium_roll.CONFIG, self._side_effect_handler).Run,
85          args)
86
87
88class AutoRoll(ScriptsBase):
89  def _PrepareOptions(self, parser):
90    parser.add_argument("-c", "--chromium", required=True,
91                        help=("The path to your Chromium src/ "
92                              "directory to automate the V8 roll."))
93    parser.add_argument("--roll",
94                        help="Make Chromium roll. Dry run if unspecified.",
95                        default=False, action="store_true")
96
97  def _ProcessOptions(self, options):  # pragma: no cover
98    if not options.reviewer:
99      print "A reviewer (-r) is required."
100      return False
101    if not options.author:
102      print "An author (-a) is required."
103      return False
104    return True
105
106  def _Steps(self):
107    return [
108      CheckActiveRoll,
109      DetectLastPush,
110      DetectLastRoll,
111      RollChromium,
112    ]
113
114
115if __name__ == "__main__":  # pragma: no cover
116  sys.exit(AutoRoll(CONFIG).Run())
117