Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / v8 / tools / push-to-trunk / 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 CLUSTERFUZZ_API_KEY_FILE = "CLUSTERFUZZ_API_KEY_FILE"
16
17 CONFIG = {
18   PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile",
19   CLUSTERFUZZ_API_KEY_FILE: ".cf_api_key",
20 }
21
22 CR_DEPS_URL = 'http://src.chromium.org/svn/trunk/src/DEPS'
23
24 class CheckActiveRoll(Step):
25   MESSAGE = "Check active roll."
26
27   @staticmethod
28   def ContainsChromiumRoll(changes):
29     for change in changes:
30       if change["subject"].startswith("Update V8 to"):
31         return True
32     return False
33
34   def RunStep(self):
35     params = {
36       "closed": 3,
37       "owner": self._options.author,
38       "limit": 30,
39       "format": "json",
40     }
41     params = urllib.urlencode(params)
42     search_url = "https://codereview.chromium.org/search"
43     result = self.ReadURL(search_url, params, wait_plan=[5, 20])
44     if self.ContainsChromiumRoll(json.loads(result)["results"]):
45       print "Stop due to existing Chromium roll."
46       return True
47
48
49 class DetectLastPush(Step):
50   MESSAGE = "Detect commit ID of the last push to trunk."
51
52   def RunStep(self):
53     push_hash = self.FindLastTrunkPush(include_patches=True)
54     self["last_push"] = self.GitSVNFindSVNRev(push_hash)
55
56
57 class DetectLastRoll(Step):
58   MESSAGE = "Detect commit ID of the last Chromium roll."
59
60   def RunStep(self):
61     # Interpret the DEPS file to retrieve the v8 revision.
62     Var = lambda var: '%s'
63     exec(self.ReadURL(CR_DEPS_URL))
64     last_roll = vars['v8_revision']
65     if last_roll >= self["last_push"]:
66       print("There is no newer v8 revision than the one in Chromium (%s)."
67             % last_roll)
68       return True
69
70
71 class CheckClusterFuzz(Step):
72   MESSAGE = "Check ClusterFuzz api for new problems."
73
74   def RunStep(self):
75     if not os.path.exists(self.Config(CLUSTERFUZZ_API_KEY_FILE)):
76       print "Skipping ClusterFuzz check. No api key file found."
77       return False
78     api_key = FileToText(self.Config(CLUSTERFUZZ_API_KEY_FILE))
79     # Check for open, reproducible issues that have no associated bug.
80     result = self._side_effect_handler.ReadClusterFuzzAPI(
81         api_key, job_type="linux_asan_d8_dbg", reproducible="True",
82         open="True", bug_information="",
83         revision_greater_or_equal=str(self["last_push"]))
84     if result:
85       print "Stop due to pending ClusterFuzz issues."
86       return True
87
88
89 class RollChromium(Step):
90   MESSAGE = "Roll V8 into Chromium."
91
92   def RunStep(self):
93     if self._options.roll:
94       args = [
95         "--author", self._options.author,
96         "--reviewer", self._options.reviewer,
97         "--chromium", self._options.chromium,
98         "--force",
99         "--use-commit-queue",
100       ]
101       if self._options.sheriff:
102         args.extend([
103             "--sheriff", "--googlers-mapping", self._options.googlers_mapping])
104       R = chromium_roll.ChromiumRoll
105       self._side_effect_handler.Call(
106           R(chromium_roll.CONFIG, self._side_effect_handler).Run,
107           args)
108
109
110 class AutoRoll(ScriptsBase):
111   def _PrepareOptions(self, parser):
112     parser.add_argument("-c", "--chromium", required=True,
113                         help=("The path to your Chromium src/ "
114                               "directory to automate the V8 roll."))
115     parser.add_argument("--roll",
116                         help="Make Chromium roll. Dry run if unspecified.",
117                         default=False, action="store_true")
118
119   def _ProcessOptions(self, options):  # pragma: no cover
120     if not options.reviewer:
121       print "A reviewer (-r) is required."
122       return False
123     if not options.author:
124       print "An author (-a) is required."
125       return False
126     return True
127
128   def _Steps(self):
129     return [
130       CheckActiveRoll,
131       DetectLastPush,
132       DetectLastRoll,
133       CheckClusterFuzz,
134       RollChromium,
135     ]
136
137
138 if __name__ == "__main__":  # pragma: no cover
139   sys.exit(AutoRoll(CONFIG).Run())