8a3ff4a0a7c8695dc1ff43a50cbb13a27669780d
[platform/upstream/nodejs.git] / deps / v8 / tools / release / chromium_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 os
8 import sys
9
10 from common_includes import *
11
12
13 ROLL_SUMMARY = ("Summary of changes available at:\n"
14                 "https://chromium.googlesource.com/v8/v8/+log/%s..%s")
15
16
17 class Preparation(Step):
18   MESSAGE = "Preparation."
19
20   def RunStep(self):
21     # Update v8 remote tracking branches.
22     self.GitFetchOrigin()
23
24
25 class DetectLastPush(Step):
26   MESSAGE = "Detect commit ID of last release."
27
28   def RunStep(self):
29     # The revision that should be rolled.
30     self["last_push"] = self._options.last_push or self.GetLatestRelease()
31     self["push_title"] = self.GitLog(n=1, format="%s",
32                                      git_hash=self["last_push"])
33
34     # The master revision this release is based on.
35     self["push_base"] = self.GetLatestReleaseBase()
36
37     # FIXME(machenbach): Manually specifying a revision doesn't work at the
38     # moment. Needs more complicated logic to find the correct push_base above.
39     # Maybe delete that parameter entirely?
40     assert not self._options.last_push
41
42     # Determine the master revision of the last roll.
43     version = self.GetVersionTag(self._options.last_roll)
44     assert version
45     self["last_rolled_base"] = self.GetLatestReleaseBase(version=version)
46     assert self["last_rolled_base"]
47
48
49 class SwitchChromium(Step):
50   MESSAGE = "Switch to Chromium checkout."
51
52   def RunStep(self):
53     self["v8_path"] = os.getcwd()
54     cwd = self._options.chromium
55     os.chdir(cwd)
56     self.InitialEnvironmentChecks(cwd)
57     # Check for a clean workdir.
58     if not self.GitIsWorkdirClean(cwd=cwd):  # pragma: no cover
59       self.Die("Workspace is not clean. Please commit or undo your changes.")
60     # Assert that the DEPS file is there.
61     if not os.path.exists(os.path.join(cwd, "DEPS")):  # pragma: no cover
62       self.Die("DEPS file not present.")
63
64
65 class UpdateChromiumCheckout(Step):
66   MESSAGE = "Update the checkout and create a new branch."
67
68   def RunStep(self):
69     self.GitCheckout("master", cwd=self._options.chromium)
70     self.Command("gclient", "sync --nohooks", cwd=self._options.chromium)
71     self.GitPull(cwd=self._options.chromium)
72
73     # Update v8 remotes.
74     self.GitFetchOrigin()
75
76     self.GitCreateBranch("v8-roll-%s" % self["last_push"],
77                          cwd=self._options.chromium)
78
79
80 class UploadCL(Step):
81   MESSAGE = "Create and upload CL."
82
83   def RunStep(self):
84     # Patch DEPS file.
85     if self.Command(
86         "roll-dep", "v8 %s" % self["last_push"],
87         cwd=self._options.chromium) is None:
88       self.Die("Failed to create deps for %s" % self["last_push"])
89
90     message = []
91     message.append("Update V8 to %s." % self["push_title"].lower())
92
93     message.append(
94         ROLL_SUMMARY % (self["last_rolled_base"][:8], self["push_base"][:8]))
95
96     if self["sheriff"]:
97       message.append("Please reply to the V8 sheriff %s in case of problems."
98           % self["sheriff"])
99     message.append("TBR=%s" % self._options.reviewer)
100     self.GitCommit("\n\n".join(message),
101                    author=self._options.author,
102                    cwd=self._options.chromium)
103     if not self._options.dry_run:
104       self.GitUpload(author=self._options.author,
105                      force=True,
106                      cq=self._options.use_commit_queue,
107                      cwd=self._options.chromium)
108       print "CL uploaded."
109     else:
110       self.GitCheckout("master", cwd=self._options.chromium)
111       self.GitDeleteBranch("v8-roll-%s" % self["last_push"],
112                            cwd=self._options.chromium)
113       print "Dry run - don't upload."
114
115
116 # TODO(machenbach): Make this obsolete. We are only in the chromium chechout
117 # for the initial .git check.
118 class SwitchV8(Step):
119   MESSAGE = "Returning to V8 checkout."
120
121   def RunStep(self):
122     os.chdir(self["v8_path"])
123
124
125 class CleanUp(Step):
126   MESSAGE = "Done!"
127
128   def RunStep(self):
129     print("Congratulations, you have successfully rolled %s into "
130           "Chromium. Please don't forget to update the v8rel spreadsheet."
131           % self["last_push"])
132
133     # Clean up all temporary files.
134     Command("rm", "-f %s*" % self._config["PERSISTFILE_BASENAME"])
135
136
137 class ChromiumRoll(ScriptsBase):
138   def _PrepareOptions(self, parser):
139     parser.add_argument("-c", "--chromium", required=True,
140                         help=("The path to your Chromium src/ "
141                               "directory to automate the V8 roll."))
142     parser.add_argument("-l", "--last-push",
143                         help="The git commit ID of the last candidates push.")
144     parser.add_argument("--last-roll", required=True,
145                         help="The git commit ID of the last rolled version.")
146     parser.add_argument("--use-commit-queue",
147                         help="Check the CQ bit on upload.",
148                         default=False, action="store_true")
149
150   def _ProcessOptions(self, options):  # pragma: no cover
151     if not options.author or not options.reviewer:
152       print "A reviewer (-r) and an author (-a) are required."
153       return False
154
155     options.requires_editor = False
156     options.force = True
157     options.manual = False
158     return True
159
160   def _Config(self):
161     return {
162       "PERSISTFILE_BASENAME": "/tmp/v8-chromium-roll-tempfile",
163     }
164
165   def _Steps(self):
166     return [
167       Preparation,
168       DetectLastPush,
169       DetermineV8Sheriff,
170       SwitchChromium,
171       UpdateChromiumCheckout,
172       UploadCL,
173       SwitchV8,
174       CleanUp,
175     ]
176
177
178 if __name__ == "__main__":  # pragma: no cover
179   sys.exit(ChromiumRoll().Run())