2010-10-14 Adam Barth <abarth@webkit.org>
[WebKit-https.git] / WebKitTools / Scripts / webkitpy / common / config / ports.py
1 # Copyright (C) 2009, Google Inc. All rights reserved.
2 #
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 disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #     * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # 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 # WebKit's Python module for understanding the various ports
30
31 import os
32 import platform
33
34 from webkitpy.common.system.executive import Executive
35
36
37 class WebKitPort(object):
38
39     # We might need to pass scm into this function for scm.checkout_root
40     @classmethod
41     def script_path(cls, script_name):
42         return os.path.join("WebKitTools", "Scripts", script_name)
43
44     @staticmethod
45     def port(port_name):
46         ports = {
47             "chromium": ChromiumPort,
48             "chromium-xvfb": ChromiumXVFBPort,
49             "gtk": GtkPort,
50             "mac": MacPort,
51             "win": WinPort,
52             "qt": QtPort,
53             "efl": EflPort,
54         }
55         default_port = {
56             "Windows": WinPort,
57             "Darwin": MacPort,
58         }
59         # Do we really need MacPort as the ultimate default?
60         return ports.get(port_name, default_port.get(platform.system(), MacPort))
61
62     @staticmethod
63     def makeArgs():
64         args = '--makeargs="-j%s"' % Executive().cpu_count()
65         if os.environ.has_key('MAKEFLAGS'):
66             args = '--makeargs="%s"' % os.environ['MAKEFLAGS']
67         return args
68
69     @classmethod
70     def name(cls):
71         raise NotImplementedError("subclasses must implement")
72
73     @classmethod
74     def flag(cls):
75         raise NotImplementedError("subclasses must implement")
76
77     @classmethod
78     def update_webkit_command(cls):
79         return [cls.script_path("update-webkit")]
80
81     @classmethod
82     def build_webkit_command(cls, build_style=None):
83         command = [cls.script_path("build-webkit")]
84         if build_style == "debug":
85             command.append("--debug")
86         if build_style == "release":
87             command.append("--release")
88         return command
89
90     @classmethod
91     def run_javascriptcore_tests_command(cls):
92         return [cls.script_path("run-javascriptcore-tests")]
93
94     @classmethod
95     def run_webkit_tests_command(cls):
96         return [cls.script_path("run-webkit-tests")]
97
98     @classmethod
99     def run_python_unittests_command(cls):
100         return [cls.script_path("test-webkitpy")]
101
102     @classmethod
103     def run_perl_unittests_command(cls):
104         return [cls.script_path("test-webkitperl")]
105
106
107 class MacPort(WebKitPort):
108
109     @classmethod
110     def name(cls):
111         return "Mac"
112
113     @classmethod
114     def flag(cls):
115         return "--port=mac"
116
117     @classmethod
118     def _system_version(cls):
119         version_string = platform.mac_ver()[0]  # e.g. "10.5.6"
120         version_tuple = version_string.split('.')
121         return map(int, version_tuple)
122
123     @classmethod
124     def is_leopard(cls):
125         return tuple(cls._system_version()[:2]) == (10, 5)
126
127
128 class WinPort(WebKitPort):
129
130     @classmethod
131     def name(cls):
132         return "Win"
133
134     @classmethod
135     def flag(cls):
136         # FIXME: This is lame.  We should autogenerate this from a codename or something.
137         return "--port=win"
138
139
140 class GtkPort(WebKitPort):
141
142     @classmethod
143     def name(cls):
144         return "Gtk"
145
146     @classmethod
147     def flag(cls):
148         return "--port=gtk"
149
150     @classmethod
151     def build_webkit_command(cls, build_style=None):
152         command = WebKitPort.build_webkit_command(build_style=build_style)
153         command.append("--gtk")
154         command.append(WebKitPort.makeArgs())
155         return command
156
157     @classmethod
158     def run_webkit_tests_command(cls):
159         command = WebKitPort.run_webkit_tests_command()
160         command.append("--gtk")
161         return command
162
163
164 class QtPort(WebKitPort):
165
166     @classmethod
167     def name(cls):
168         return "Qt"
169
170     @classmethod
171     def flag(cls):
172         return "--port=qt"
173
174     @classmethod
175     def build_webkit_command(cls, build_style=None):
176         command = WebKitPort.build_webkit_command(build_style=build_style)
177         command.append("--qt")
178         command.append(WebKitPort.makeArgs())
179         return command
180
181
182 class EflPort(WebKitPort):
183
184     @classmethod
185     def name(cls):
186         return "Efl"
187
188     @classmethod
189     def flag(cls):
190         return "--port=efl"
191
192     @classmethod
193     def build_webkit_command(cls, build_style=None):
194         command = WebKitPort.build_webkit_command(build_style=build_style)
195         command.append("--efl")
196         command.append(WebKitPort.makeArgs())
197         return command
198
199
200 class ChromiumPort(WebKitPort):
201
202     @classmethod
203     def name(cls):
204         return "Chromium"
205
206     @classmethod
207     def flag(cls):
208         return "--port=chromium"
209
210     @classmethod
211     def update_webkit_command(cls):
212         command = WebKitPort.update_webkit_command()
213         command.append("--chromium")
214         return command
215
216     @classmethod
217     def build_webkit_command(cls, build_style=None):
218         command = WebKitPort.build_webkit_command(build_style=build_style)
219         command.append("--chromium")
220         return command
221
222     @classmethod
223     def run_webkit_tests_command(cls):
224         return [
225             cls.script_path("new-run-webkit-tests"),
226             "--chromium",
227             "--use-drt",
228             "--no-pixel-tests",
229         ]
230
231     @classmethod
232     def run_javascriptcore_tests_command(cls):
233         return None
234
235
236 class ChromiumXVFBPort(ChromiumPort):
237
238     @classmethod
239     def flag(cls):
240         return "--port=chromium-xvfb"
241
242     @classmethod
243     def run_webkit_tests_command(cls):
244         # FIXME: We should find a better way to do this.
245         return ["xvfb-run"] + ChromiumPort.run_webkit_tests_command()