0c20dae5124a27d57b86e7dac52f734cc5664f97
[WebKit-https.git] / Tools / 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 import sys
34
35 from webkitpy.common.system.executive import Executive
36
37
38 class DeprecatedPort(object):
39     results_directory = "/tmp/layout-test-results"
40
41     # Subclasses must override
42     port_flag_name = None
43
44     # FIXME: This is only used by BotInfo.
45     def name(self):
46         return self.__class__
47
48     def flag(self):
49         if self.port_flag_name:
50             return "--port=%s" % self.port_flag_name
51         return None
52
53     # We might need to pass scm into this function for scm.checkout_root
54     def script_path(self, script_name):
55         return os.path.join("Tools", "Scripts", script_name)
56
57     def script_shell_command(self, script_name):
58         script_path = self.script_path(script_name)
59         return Executive.shell_command_for_script(script_path)
60
61     @staticmethod
62     def port(port_name):
63         ports = {
64             "gtk": GtkPort,
65             "gtk-wk2": GtkWK2Port,
66             "mac": MacPort,
67             "mac-wk2": MacWK2Port,
68             "win": WinPort,
69             "qt": QtPort,
70             "qt-wk2": QtWK2Port,
71             "efl": EflPort,
72             "efl-wk2": EflWK2Port,
73         }
74         default_port = {
75             "Windows": WinPort,
76             "Darwin": MacPort,
77         }
78         # Do we really need MacPort as the ultimate default?
79         return ports.get(port_name, default_port.get(platform.system(), MacPort))()
80
81     def makeArgs(self):
82         # FIXME: This shouldn't use a static Executive().
83         args = '--makeargs="-j%s"' % Executive().cpu_count()
84         if os.environ.has_key('MAKEFLAGS'):
85             args = '--makeargs="%s"' % os.environ['MAKEFLAGS']
86         return args
87
88     def update_webkit_command(self, non_interactive=False):
89         return self.script_shell_command("update-webkit")
90
91     def check_webkit_style_command(self):
92         return self.script_shell_command("check-webkit-style")
93
94     def prepare_changelog_command(self):
95         return self.script_shell_command("prepare-ChangeLog")
96
97     def build_webkit_command(self, build_style=None):
98         command = self.script_shell_command("build-webkit")
99         if build_style == "debug":
100             command.append("--debug")
101         if build_style == "release":
102             command.append("--release")
103         return command
104
105     def run_javascriptcore_tests_command(self):
106         return self.script_shell_command("run-javascriptcore-tests")
107
108     def run_webkit_unit_tests_command(self):
109         return None
110
111     def run_webkit_tests_command(self):
112         return self.script_shell_command("run-webkit-tests")
113
114     def run_python_unittests_command(self):
115         return self.script_shell_command("test-webkitpy")
116
117     def run_perl_unittests_command(self):
118         return self.script_shell_command("test-webkitperl")
119
120     def run_bindings_tests_command(self):
121         return self.script_shell_command("run-bindings-tests")
122
123
124 class MacPort(DeprecatedPort):
125     port_flag_name = "mac"
126
127
128 class MacWK2Port(DeprecatedPort):
129     port_flag_name = "mac-wk2"
130
131     def run_webkit_tests_command(self):
132         command = super(MacWK2Port, self).run_webkit_tests_command()
133         command.append("-2")
134         return command
135
136
137 class WinPort(DeprecatedPort):
138     port_flag_name = "win"
139
140     def run_bindings_tests_command(self):
141         return None
142
143
144 class GtkPort(DeprecatedPort):
145     port_flag_name = "gtk"
146
147     def build_webkit_command(self, build_style=None):
148         command = super(GtkPort, self).build_webkit_command(build_style=build_style)
149         command.append("--gtk")
150         command.append("--update-gtk")
151         command.append("--no-webkit2")
152         command.append(super(GtkPort, self).makeArgs())
153         return command
154
155     def run_webkit_tests_command(self):
156         command = super(GtkPort, self).run_webkit_tests_command()
157         command.append("--gtk")
158         return command
159
160
161 class GtkWK2Port(DeprecatedPort):
162     port_flag_name = "gtk-wk2"
163
164     def build_webkit_command(self, build_style=None):
165         command = super(GtkWK2Port, self).build_webkit_command(build_style=build_style)
166         command.append("--gtk")
167         command.append("--update-gtk")
168         command.append("--no-webkit1")
169         command.append(super(GtkWK2Port, self).makeArgs())
170         return command
171
172     def run_webkit_tests_command(self):
173         command = super(GtkWK2Port, self).run_webkit_tests_command()
174         command.append("--gtk")
175         command.append("-2")
176         return command
177
178
179 class QtPort(DeprecatedPort):
180     port_flag_name = "qt"
181
182     def build_webkit_command(self, build_style=None):
183         command = super(QtPort, self).build_webkit_command(build_style=build_style)
184         command.append("--qt")
185         command.append("--no-webkit2")
186         command.append(super(QtPort, self).makeArgs())
187         return command
188
189     def run_webkit_tests_command(self):
190         command = super(QtPort, self).run_webkit_tests_command()
191         command.append("--qt")
192         return command
193
194
195 class QtWK2Port(DeprecatedPort):
196     port_flag_name = "qt-wk2"
197
198     def build_webkit_command(self, build_style=None):
199         command = super(QtWK2Port, self).build_webkit_command(build_style=build_style)
200         command.append("--qt")
201         command.append(super(QtWK2Port, self).makeArgs())
202         return command
203
204     def run_webkit_tests_command(self):
205         command = super(QtWK2Port, self).run_webkit_tests_command()
206         command.append("--qt")
207         command.append("-2")
208         return command
209
210
211 class EflPort(DeprecatedPort):
212     port_flag_name = "efl"
213
214     def build_webkit_command(self, build_style=None):
215         command = super(EflPort, self).build_webkit_command(build_style=build_style)
216         command.append("--efl")
217         command.append("--update-efl")
218         command.append("--no-webkit2")
219         command.append(super(EflPort, self).makeArgs())
220         return command
221
222
223 class EflWK2Port(DeprecatedPort):
224     port_flag_name = "efl-wk2"
225
226     def build_webkit_command(self, build_style=None):
227         command = super(EflWK2Port, self).build_webkit_command(build_style=build_style)
228         command.append("--efl")
229         command.append("--update-efl")
230         command.append("--no-webkit1")
231         command.append(super(EflWK2Port, self).makeArgs())
232         return command