deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / tools / release / auto_roll.py
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 import argparse
7 import json
8 import os
9 import sys
10 import urllib
11
12 from common_includes import *
13 import chromium_roll
14
15
16 class CheckActiveRoll(Step):
17   MESSAGE = "Check active roll."
18
19   @staticmethod
20   def ContainsChromiumRoll(changes):
21     for change in changes:
22       if change["subject"].startswith("Update V8 to"):
23         return True
24     return False
25
26   def RunStep(self):
27     params = {
28       "closed": 3,
29       "owner": self._options.author,
30       "limit": 30,
31       "format": "json",
32     }
33     params = urllib.urlencode(params)
34     search_url = "https://codereview.chromium.org/search"
35     result = self.ReadURL(search_url, params, wait_plan=[5, 20])
36     if self.ContainsChromiumRoll(json.loads(result)["results"]):
37       print "Stop due to existing Chromium roll."
38       return True
39
40
41 class DetectLastRoll(Step):
42   MESSAGE = "Detect commit ID of the last Chromium roll."
43
44   def RunStep(self):
45     # The revision that should be rolled. Check for the latest of the most
46     # recent releases based on commit timestamp.
47     revisions = self.GetRecentReleases(
48         max_age=self._options.max_age * DAY_IN_SECONDS)
49     assert revisions, "Didn't find any recent release."
50
51     # Interpret the DEPS file to retrieve the v8 revision.
52     # TODO(machenbach): This should be part or the roll-deps api of
53     # depot_tools.
54     Var = lambda var: '%s'
55     exec(FileToText(os.path.join(self._options.chromium, "DEPS")))
56
57     # The revision rolled last.
58     self["last_roll"] = vars['v8_revision']
59     last_version = self.GetVersionTag(self["last_roll"])
60     assert last_version, "The last rolled v8 revision is not tagged."
61
62     # There must be some progress between the last roll and the new candidate
63     # revision (i.e. we don't go backwards). The revisions are ordered newest
64     # to oldest. It is possible that the newest timestamp has no progress
65     # compared to the last roll, i.e. if the newest release is a cherry-pick
66     # on a release branch. Then we look further.
67     for revision in revisions:
68       version = self.GetVersionTag(revision)
69       assert version, "Internal error. All recent releases should have a tag"
70
71       if SortingKey(last_version) < SortingKey(version):
72         self["roll"] = revision
73         break
74     else:
75       print("There is no newer v8 revision than the one in Chromium (%s)."
76             % self["last_roll"])
77       return True
78
79
80 class RollChromium(Step):
81   MESSAGE = "Roll V8 into Chromium."
82
83   def RunStep(self):
84     if self._options.roll:
85       args = [
86         "--author", self._options.author,
87         "--reviewer", self._options.reviewer,
88         "--chromium", self._options.chromium,
89         "--last-roll", self["last_roll"],
90         "--use-commit-queue",
91         self["roll"],
92       ]
93       if self._options.sheriff:
94         args.append("--sheriff")
95       if self._options.dry_run:
96         args.append("--dry-run")
97       if self._options.work_dir:
98         args.extend(["--work-dir", self._options.work_dir])
99       self._side_effect_handler.Call(chromium_roll.ChromiumRoll().Run, args)
100
101
102 class AutoRoll(ScriptsBase):
103   def _PrepareOptions(self, parser):
104     parser.add_argument("-c", "--chromium", required=True,
105                         help=("The path to your Chromium src/ "
106                               "directory to automate the V8 roll."))
107     parser.add_argument("--max-age", default=3, type=int,
108                         help="Maximum age in days of the latest release.")
109     parser.add_argument("--roll", help="Call Chromium roll script.",
110                         default=False, action="store_true")
111
112   def _ProcessOptions(self, options):  # pragma: no cover
113     if not options.reviewer:
114       print "A reviewer (-r) is required."
115       return False
116     if not options.author:
117       print "An author (-a) is required."
118       return False
119     return True
120
121   def _Config(self):
122     return {
123       "PERSISTFILE_BASENAME": "/tmp/v8-auto-roll-tempfile",
124     }
125
126   def _Steps(self):
127     return [
128       CheckActiveRoll,
129       DetectLastRoll,
130       RollChromium,
131     ]
132
133
134 if __name__ == "__main__":  # pragma: no cover
135   sys.exit(AutoRoll().Run())