bb4924a75c9950406f2b9f970f63ea5a6eeb078d
[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             "chromium": ChromiumPort,
65             "chromium-android": ChromiumAndroidPort,
66             "chromium-xvfb": ChromiumXVFBPort,
67             "gtk": GtkPort,
68             "mac": MacPort,
69             "win": WinPort,
70             "qt": QtPort,
71             "efl": EflPort,
72         }
73         default_port = {
74             "Windows": WinPort,
75             "Darwin": MacPort,
76         }
77         # Do we really need MacPort as the ultimate default?
78         return ports.get(port_name, default_port.get(platform.system(), MacPort))()
79
80     def makeArgs(self):
81         # FIXME: This shouldn't use a static Executive().
82         args = '--makeargs="-j%s"' % Executive().cpu_count()
83         if os.environ.has_key('MAKEFLAGS'):
84             args = '--makeargs="%s"' % os.environ['MAKEFLAGS']
85         return args
86
87     def update_webkit_command(self, non_interactive=False):
88         return self.script_shell_command("update-webkit")
89
90     def check_webkit_style_command(self):
91         return self.script_shell_command("check-webkit-style")
92
93     def prepare_changelog_command(self):
94         return self.script_shell_command("prepare-ChangeLog")
95
96     def build_webkit_command(self, build_style=None):
97         command = self.script_shell_command("build-webkit")
98         if build_style == "debug":
99             command.append("--debug")
100         if build_style == "release":
101             command.append("--release")
102         return command
103
104     def run_javascriptcore_tests_command(self):
105         return self.script_shell_command("run-javascriptcore-tests")
106
107     def run_webkit_unit_tests_command(self):
108         return None
109
110     def run_webkit_tests_command(self):
111         return self.script_shell_command("run-webkit-tests")
112
113     def run_python_unittests_command(self):
114         return self.script_shell_command("test-webkitpy")
115
116     def run_perl_unittests_command(self):
117         return self.script_shell_command("test-webkitperl")
118
119
120 class MacPort(DeprecatedPort):
121     port_flag_name = "mac"
122
123
124 class WinPort(DeprecatedPort):
125     port_flag_name = "win"
126
127
128 class GtkPort(DeprecatedPort):
129     port_flag_name = "gtk"
130
131     def build_webkit_command(self, build_style=None):
132         command = super(GtkPort, self).build_webkit_command(build_style=build_style)
133         command.append("--gtk")
134         command.append("--update-gtk")
135         command.append(super(GtkPort, self).makeArgs())
136         return command
137
138     def run_webkit_tests_command(self):
139         command = super(GtkPort, self).run_webkit_tests_command()
140         command.append("--gtk")
141         return command
142
143
144 class QtPort(DeprecatedPort):
145     port_flag_name = "qt"
146
147     def build_webkit_command(self, build_style=None):
148         command = super(QtPort, self).build_webkit_command(build_style=build_style)
149         command.append("--qt")
150         command.append(super(QtPort, self).makeArgs())
151         return command
152
153
154 class EflPort(DeprecatedPort):
155     port_flag_name = "efl"
156
157     def build_webkit_command(self, build_style=None):
158         command = super(EflPort, self).build_webkit_command(build_style=build_style)
159         command.append("--efl")
160         command.append("--update-efl")
161         command.append(super(EflPort, self).makeArgs())
162         return command
163
164
165 class ChromiumPort(DeprecatedPort):
166     port_flag_name = "chromium"
167
168     def update_webkit_command(self, non_interactive=False):
169         command = super(ChromiumPort, self).update_webkit_command(non_interactive=non_interactive)
170         command.append("--chromium")
171         if non_interactive:
172             command.append("--force-update")
173         return command
174
175     def build_webkit_command(self, build_style=None):
176         command = super(ChromiumPort, self).build_webkit_command(build_style=build_style)
177         command.append("--chromium")
178         command.append("--update-chromium")
179         return command
180
181     def run_webkit_tests_command(self):
182         # Note: This could be run-webkit-tests now.
183         command = self.script_shell_command("new-run-webkit-tests")
184         command.append("--chromium")
185         command.append("--skip-failing-tests")
186         return command
187
188     def run_webkit_unit_tests_command(self):
189         return self.script_shell_command("run-chromium-webkit-unit-tests")
190
191     def run_javascriptcore_tests_command(self):
192         return None
193
194
195 class ChromiumAndroidPort(ChromiumPort):
196     port_flag_name = "chromium-android"
197
198     def update_webkit_command(self, non_interactive=False):
199         command = super(ChromiumAndroidPort, self).update_webkit_command(non_interactive=non_interactive)
200         command.append("--chromium-android")
201         return command
202
203     def build_webkit_command(self, build_style=None):
204         command = super(ChromiumAndroidPort, self).build_webkit_command(build_style=build_style)
205         command.append("--chromium-android")
206         return command
207
208
209 class ChromiumXVFBPort(ChromiumPort):
210     port_flag_name = "chromium-xvfb"
211
212     def run_webkit_tests_command(self):
213         return ["xvfb-run"] + super(ChromiumXVFBPort, self).run_webkit_tests_command()