Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / tools / push-to-trunk / auto_push.py
1 #!/usr/bin/env python
2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 #       notice, this list of conditions and the following disclaimer.
9 #     * Redistributions in binary form must reproduce the above
10 #       copyright notice, this list of conditions and the following
11 #       disclaimer in the documentation and/or other materials provided
12 #       with the distribution.
13 #     * Neither the name of Google Inc. nor the names of its
14 #       contributors may be used to endorse or promote products derived
15 #       from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 import argparse
30 import json
31 import os
32 import re
33 import sys
34 import urllib
35
36 from common_includes import *
37 import push_to_trunk
38
39 PUSH_MESSAGE_RE = re.compile(r".* \(based on ([a-fA-F0-9]+)\)$")
40
41 class Preparation(Step):
42   MESSAGE = "Preparation."
43
44   def RunStep(self):
45     self.InitialEnvironmentChecks(self.default_cwd)
46     self.CommonPrepare()
47
48
49 class CheckAutoPushSettings(Step):
50   MESSAGE = "Checking settings file."
51
52   def RunStep(self):
53     settings_file = os.path.realpath(self.Config("SETTINGS_LOCATION"))
54     if os.path.exists(settings_file):
55       settings_dict = json.loads(FileToText(settings_file))
56       if settings_dict.get("enable_auto_roll") is False:
57         self.Die("Push to trunk disabled by auto-roll settings file: %s"
58                  % settings_file)
59
60
61 class CheckTreeStatus(Step):
62   MESSAGE = "Checking v8 tree status message."
63
64   def RunStep(self):
65     status_url = "https://v8-status.appspot.com/current?format=json"
66     status_json = self.ReadURL(status_url, wait_plan=[5, 20, 300, 300])
67     self["tree_message"] = json.loads(status_json)["message"]
68     if re.search(r"nopush|no push", self["tree_message"], flags=re.I):
69       self.Die("Push to trunk disabled by tree state: %s"
70                % self["tree_message"])
71
72
73 class FetchLKGR(Step):
74   MESSAGE = "Fetching V8 LKGR."
75
76   def RunStep(self):
77     lkgr_url = "https://v8-status.appspot.com/lkgr"
78     # Retry several times since app engine might have issues.
79     self["lkgr"] = self.ReadURL(lkgr_url, wait_plan=[5, 20, 300, 300])
80
81
82 class CheckLastPush(Step):
83   MESSAGE = "Checking last V8 push to trunk."
84
85   def RunStep(self):
86     last_push = self.FindLastTrunkPush()
87
88     # Retrieve the bleeding edge revision of the last push from the text in
89     # the push commit message.
90     last_push_title = self.GitLog(n=1, format="%s", git_hash=last_push)
91     last_push_be = PUSH_MESSAGE_RE.match(last_push_title).group(1)
92
93     if not last_push_be:  # pragma: no cover
94       self.Die("Could not retrieve bleeding edge revision for trunk push %s"
95                % last_push)
96
97     if self["lkgr"] == last_push_be:
98       print "Already pushed current lkgr %s" % last_push_be
99       return True
100
101
102 class PushToCandidates(Step):
103   MESSAGE = "Pushing to candidates if specified."
104
105   def RunStep(self):
106     print "Pushing lkgr %s to candidates." % self["lkgr"]
107
108     args = [
109       "--author", self._options.author,
110       "--reviewer", self._options.reviewer,
111       "--revision", self["lkgr"],
112       "--force",
113     ]
114
115     if self._options.svn:
116       args.extend(["--svn", self._options.svn])
117     if self._options.svn_config:
118       args.extend(["--svn-config", self._options.svn_config])
119     if self._options.vc_interface:
120       args.extend(["--vc-interface", self._options.vc_interface])
121     if self._options.work_dir:
122       args.extend(["--work-dir", self._options.work_dir])
123
124     # TODO(machenbach): Update the script before calling it.
125     if self._options.push:
126       self._side_effect_handler.Call(push_to_trunk.PushToTrunk().Run, args)
127
128
129 class AutoPush(ScriptsBase):
130   def _PrepareOptions(self, parser):
131     parser.add_argument("-p", "--push",
132                         help="Push to trunk. Dry run if unspecified.",
133                         default=False, action="store_true")
134
135   def _ProcessOptions(self, options):
136     if not options.author or not options.reviewer:  # pragma: no cover
137       print "You need to specify author and reviewer."
138       return False
139     options.requires_editor = False
140     return True
141
142   def _Config(self):
143     return {
144       "PERSISTFILE_BASENAME": "/tmp/v8-auto-push-tempfile",
145       "SETTINGS_LOCATION": "~/.auto-roll",
146     }
147
148   def _Steps(self):
149     return [
150       Preparation,
151       CheckAutoPushSettings,
152       CheckTreeStatus,
153       FetchLKGR,
154       CheckLastPush,
155       PushToCandidates,
156     ]
157
158
159 if __name__ == "__main__":  # pragma: no cover
160   sys.exit(AutoPush().Run())