• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
31import os
32import platform
33import sys
34
35from webkitpy.common.system.executive import Executive
36
37
38class WebKitPort(object):
39
40    # We might need to pass scm into this function for scm.checkout_root
41    @classmethod
42    def script_path(cls, script_name):
43        return os.path.join("Tools", "Scripts", script_name)
44
45    @classmethod
46    def script_shell_command(cls, script_name):
47        script_path = cls.script_path(script_name)
48        # Win32 does not support shebang. We need to detect the interpreter ourself.
49        if sys.platform == 'win32':
50            interpreter = Executive.interpreter_for_script(script_path)
51            if interpreter:
52                return [interpreter, script_path]
53        return [script_path]
54
55    @staticmethod
56    def port(port_name):
57        ports = {
58            "chromium": ChromiumPort,
59            "chromium-xvfb": ChromiumXVFBPort,
60            "gtk": GtkPort,
61            "mac": MacPort,
62            "win": WinPort,
63            "qt": QtPort,
64            "efl": EflPort,
65        }
66        default_port = {
67            "Windows": WinPort,
68            "Darwin": MacPort,
69        }
70        # Do we really need MacPort as the ultimate default?
71        return ports.get(port_name, default_port.get(platform.system(), MacPort))
72
73    @staticmethod
74    def makeArgs():
75        args = '--makeargs="-j%s"' % Executive().cpu_count()
76        if os.environ.has_key('MAKEFLAGS'):
77            args = '--makeargs="%s"' % os.environ['MAKEFLAGS']
78        return args
79
80    @classmethod
81    def name(cls):
82        raise NotImplementedError("subclasses must implement")
83
84    @classmethod
85    def flag(cls):
86        raise NotImplementedError("subclasses must implement")
87
88    @classmethod
89    def update_webkit_command(cls):
90        return cls.script_shell_command("update-webkit")
91
92    @classmethod
93    def check_webkit_style_command(cls):
94        return cls.script_shell_command("check-webkit-style")
95
96    @classmethod
97    def prepare_changelog_command(cls):
98        return cls.script_shell_command("prepare-ChangeLog")
99
100    @classmethod
101    def build_webkit_command(cls, build_style=None):
102        command = cls.script_shell_command("build-webkit")
103        if build_style == "debug":
104            command.append("--debug")
105        if build_style == "release":
106            command.append("--release")
107        return command
108
109    @classmethod
110    def run_javascriptcore_tests_command(cls):
111        return cls.script_shell_command("run-javascriptcore-tests")
112
113    @classmethod
114    def run_webkit_tests_command(cls):
115        return cls.script_shell_command("run-webkit-tests")
116
117    @classmethod
118    def run_python_unittests_command(cls):
119        return cls.script_shell_command("test-webkitpy")
120
121    @classmethod
122    def run_perl_unittests_command(cls):
123        return cls.script_shell_command("test-webkitperl")
124
125    @classmethod
126    def layout_tests_results_path(cls):
127        return "/tmp/layout-test-results/results.html"
128
129
130class MacPort(WebKitPort):
131
132    @classmethod
133    def name(cls):
134        return "Mac"
135
136    @classmethod
137    def flag(cls):
138        return "--port=mac"
139
140    @classmethod
141    def _system_version(cls):
142        version_string = platform.mac_ver()[0]  # e.g. "10.5.6"
143        version_tuple = version_string.split('.')
144        return map(int, version_tuple)
145
146    @classmethod
147    def is_leopard(cls):
148        return tuple(cls._system_version()[:2]) == (10, 5)
149
150
151class WinPort(WebKitPort):
152
153    @classmethod
154    def name(cls):
155        return "Win"
156
157    @classmethod
158    def flag(cls):
159        # FIXME: This is lame.  We should autogenerate this from a codename or something.
160        return "--port=win"
161
162
163class GtkPort(WebKitPort):
164
165    @classmethod
166    def name(cls):
167        return "Gtk"
168
169    @classmethod
170    def flag(cls):
171        return "--port=gtk"
172
173    @classmethod
174    def build_webkit_command(cls, build_style=None):
175        command = WebKitPort.build_webkit_command(build_style=build_style)
176        command.append("--gtk")
177        command.append(WebKitPort.makeArgs())
178        return command
179
180    @classmethod
181    def run_webkit_tests_command(cls):
182        command = WebKitPort.run_webkit_tests_command()
183        command.append("--gtk")
184        return command
185
186
187class QtPort(WebKitPort):
188
189    @classmethod
190    def name(cls):
191        return "Qt"
192
193    @classmethod
194    def flag(cls):
195        return "--port=qt"
196
197    @classmethod
198    def build_webkit_command(cls, build_style=None):
199        command = WebKitPort.build_webkit_command(build_style=build_style)
200        command.append("--qt")
201        command.append(WebKitPort.makeArgs())
202        return command
203
204
205class EflPort(WebKitPort):
206
207    @classmethod
208    def name(cls):
209        return "Efl"
210
211    @classmethod
212    def flag(cls):
213        return "--port=efl"
214
215    @classmethod
216    def build_webkit_command(cls, build_style=None):
217        command = WebKitPort.build_webkit_command(build_style=build_style)
218        command.append("--efl")
219        command.append(WebKitPort.makeArgs())
220        return command
221
222
223class ChromiumPort(WebKitPort):
224
225    @classmethod
226    def name(cls):
227        return "Chromium"
228
229    @classmethod
230    def flag(cls):
231        return "--port=chromium"
232
233    @classmethod
234    def update_webkit_command(cls):
235        command = WebKitPort.update_webkit_command()
236        command.append("--chromium")
237        return command
238
239    @classmethod
240    def build_webkit_command(cls, build_style=None):
241        command = WebKitPort.build_webkit_command(build_style=build_style)
242        command.append("--chromium")
243        command.append("--update-chromium")
244        return command
245
246    @classmethod
247    def run_webkit_tests_command(cls):
248        command = cls.script_shell_command("new-run-webkit-tests")
249        command.append("--chromium")
250        command.append("--no-pixel-tests")
251        return command
252
253    @classmethod
254    def run_javascriptcore_tests_command(cls):
255        return None
256
257
258class ChromiumXVFBPort(ChromiumPort):
259
260    @classmethod
261    def flag(cls):
262        return "--port=chromium-xvfb"
263
264    @classmethod
265    def run_webkit_tests_command(cls):
266        # FIXME: We should find a better way to do this.
267        return ["xvfb-run"] + ChromiumPort.run_webkit_tests_command()
268