|
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 "gtk": GtkPort, |
|
49 "mac": MacPort, |
|
50 "win": WinPort, |
|
51 "qt": QtPort, |
|
52 } |
|
53 default_port = { |
|
54 "Windows": WinPort, |
|
55 "Darwin": MacPort, |
|
56 } |
|
57 # Do we really need MacPort as the ultimate default? |
|
58 return ports.get(port_name, default_port.get(platform.system(), MacPort)) |
|
59 |
|
60 @staticmethod |
|
61 def makeArgs(): |
|
62 args = '--makeargs="-j%s"' % Executive().cpu_count() |
|
63 if os.environ.has_key('MAKEFLAGS'): |
|
64 args = '--makeargs="%s"' % os.environ['MAKEFLAGS'] |
|
65 return args |
|
66 |
|
67 @classmethod |
|
68 def name(cls): |
|
69 raise NotImplementedError("subclasses must implement") |
|
70 |
|
71 @classmethod |
|
72 def flag(cls): |
|
73 raise NotImplementedError("subclasses must implement") |
|
74 |
|
75 @classmethod |
|
76 def update_webkit_command(cls): |
|
77 return [cls.script_path("update-webkit")] |
|
78 |
|
79 @classmethod |
|
80 def build_webkit_command(cls, build_style=None): |
|
81 command = [cls.script_path("build-webkit")] |
|
82 if build_style == "debug": |
|
83 command.append("--debug") |
|
84 if build_style == "release": |
|
85 command.append("--release") |
|
86 return command |
|
87 |
|
88 @classmethod |
|
89 def run_javascriptcore_tests_command(cls): |
|
90 return [cls.script_path("run-javascriptcore-tests")] |
|
91 |
|
92 @classmethod |
|
93 def run_webkit_tests_command(cls): |
|
94 return [cls.script_path("run-webkit-tests")] |
|
95 |
|
96 @classmethod |
|
97 def run_python_unittests_command(cls): |
|
98 return [cls.script_path("test-webkitpy")] |
|
99 |
|
100 @classmethod |
|
101 def run_perl_unittests_command(cls): |
|
102 return [cls.script_path("test-webkitperl")] |
|
103 |
|
104 |
|
105 class MacPort(WebKitPort): |
|
106 |
|
107 @classmethod |
|
108 def name(cls): |
|
109 return "Mac" |
|
110 |
|
111 @classmethod |
|
112 def flag(cls): |
|
113 return "--port=mac" |
|
114 |
|
115 @classmethod |
|
116 def _system_version(cls): |
|
117 version_string = platform.mac_ver()[0] # e.g. "10.5.6" |
|
118 version_tuple = version_string.split('.') |
|
119 return map(int, version_tuple) |
|
120 |
|
121 @classmethod |
|
122 def is_leopard(cls): |
|
123 return tuple(cls._system_version()[:2]) == (10, 5) |
|
124 |
|
125 |
|
126 class WinPort(WebKitPort): |
|
127 |
|
128 @classmethod |
|
129 def name(cls): |
|
130 return "Win" |
|
131 |
|
132 @classmethod |
|
133 def flag(cls): |
|
134 # FIXME: This is lame. We should autogenerate this from a codename or something. |
|
135 return "--port=win" |
|
136 |
|
137 |
|
138 class GtkPort(WebKitPort): |
|
139 |
|
140 @classmethod |
|
141 def name(cls): |
|
142 return "Gtk" |
|
143 |
|
144 @classmethod |
|
145 def flag(cls): |
|
146 return "--port=gtk" |
|
147 |
|
148 @classmethod |
|
149 def build_webkit_command(cls, build_style=None): |
|
150 command = WebKitPort.build_webkit_command(build_style=build_style) |
|
151 command.append("--gtk") |
|
152 command.append(WebKitPort.makeArgs()) |
|
153 return command |
|
154 |
|
155 @classmethod |
|
156 def run_webkit_tests_command(cls): |
|
157 command = WebKitPort.run_webkit_tests_command() |
|
158 command.append("--gtk") |
|
159 return command |
|
160 |
|
161 |
|
162 class QtPort(WebKitPort): |
|
163 |
|
164 @classmethod |
|
165 def name(cls): |
|
166 return "Qt" |
|
167 |
|
168 @classmethod |
|
169 def flag(cls): |
|
170 return "--port=qt" |
|
171 |
|
172 @classmethod |
|
173 def build_webkit_command(cls, build_style=None): |
|
174 command = WebKitPort.build_webkit_command(build_style=build_style) |
|
175 command.append("--qt") |
|
176 command.append(WebKitPort.makeArgs()) |
|
177 return command |
|
178 |
|
179 |
|
180 class ChromiumPort(WebKitPort): |
|
181 |
|
182 @classmethod |
|
183 def name(cls): |
|
184 return "Chromium" |
|
185 |
|
186 @classmethod |
|
187 def flag(cls): |
|
188 return "--port=chromium" |
|
189 |
|
190 @classmethod |
|
191 def update_webkit_command(cls): |
|
192 command = WebKitPort.update_webkit_command() |
|
193 command.append("--chromium") |
|
194 return command |
|
195 |
|
196 @classmethod |
|
197 def build_webkit_command(cls, build_style=None): |
|
198 command = WebKitPort.build_webkit_command(build_style=build_style) |
|
199 command.append("--chromium") |
|
200 return command |