initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / layout_tests / port / chromium_linux.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 """Chromium Linux implementation of the Port interface."""
31
32 import logging
33
34 import chromium
35
36
37 _log = logging.getLogger(__name__)
38
39
40 class ChromiumLinuxPort(chromium.ChromiumPort):
41     SUPPORTED_ARCHITECTURES = ('x86', 'x86_64')
42
43     FALLBACK_PATHS = {
44         'x86_64': [
45             'chromium-linux',
46             'chromium-win',
47             'chromium',
48             'win',
49             'mac',
50         ],
51         'x86': [
52             'chromium-linux-x86',
53             'chromium-linux',
54             'chromium-win',
55             'chromium',
56             'win',
57             'mac',
58         ],
59     }
60
61     def __init__(self, port_name=None, **kwargs):
62         port_name = port_name or 'chromium-linux'
63         chromium.ChromiumPort.__init__(self, port_name=port_name, **kwargs)
64         # We re-set the port name once the base object is fully initialized
65         # in order to be able to find the DRT binary properly.
66         if port_name.endswith('-linux'):
67             self._architecture = self._determine_architecture()
68             # FIXME: This is an ugly hack to avoid renaming the GPU port.
69             if port_name == 'chromium-linux':
70                 port_name = port_name + '-' + self._architecture
71         else:
72             base, arch = port_name.rsplit('-', 1)
73             assert base in ('chromium-linux', 'chromium-gpu-linux')
74             self._architecture = arch
75         assert self._architecture in self.SUPPORTED_ARCHITECTURES
76         assert port_name in ('chromium-linux', 'chromium-gpu-linux',
77                              'chromium-linux-x86', 'chromium-linux-x86_64',
78                              'chromium-gpu-linux-x86_64')
79         self._name = port_name
80         self._operating_system = 'linux'
81         self._version = 'lucid'  # We only support lucid right now.
82
83     def _determine_architecture(self):
84         driver_path = self._path_to_driver()
85         file_output = ''
86         if self._filesystem.exists(driver_path):
87             # The --dereference flag tells file to follow symlinks
88             file_output = self._executive.run_command(['file', '--dereference', driver_path], return_stderr=True)
89
90         if 'ELF 32-bit LSB executable' in file_output:
91             return 'x86'
92         if 'ELF 64-bit LSB executable' in file_output:
93             return 'x86_64'
94         if file_output:
95             _log.warning('Could not determine architecture from "file" output: %s' % file_output)
96
97         # We don't know what the architecture is; default to 'x86' because
98         # maybe we're rebaselining and the binary doesn't actually exist,
99         # or something else weird is going on. It's okay to do this because
100         # if we actually try to use the binary, check_build() should fail.
101         return 'x86_64'
102
103     def baseline_search_path(self):
104         port_names = self.FALLBACK_PATHS[self._architecture]
105         return map(self._webkit_baseline_path, port_names)
106
107     def check_build(self, needs_http):
108         result = chromium.ChromiumPort.check_build(self, needs_http)
109         result = self.check_wdiff() and result
110
111         if not result:
112             _log.error('For complete Linux build requirements, please see:')
113             _log.error('')
114             _log.error('    http://code.google.com/p/chromium/wiki/LinuxBuildInstructions')
115         return result
116
117     #
118     # PROTECTED METHODS
119     #
120
121     def _build_path(self, *comps):
122         if self.get_option('build_directory'):
123             return self._filesystem.join(self.get_option('build_directory'), *comps)
124
125         base = self.path_from_chromium_base()
126         if self._filesystem.exists(self._filesystem.join(base, 'sconsbuild')):
127             return self._filesystem.join(base, 'sconsbuild', *comps)
128         if self._filesystem.exists(self._filesystem.join(base, 'out', *comps)):
129             return self._filesystem.join(base, 'out', *comps)
130         base = self.path_from_webkit_base()
131         if self._filesystem.exists(self._filesystem.join(base, 'sconsbuild')):
132             return self._filesystem.join(base, 'sconsbuild', *comps)
133         return self._filesystem.join(base, 'out', *comps)
134
135     def _check_apache_install(self):
136         result = self._check_file_exists(self._path_to_apache(), "apache2")
137         result = self._check_file_exists(self._path_to_apache_config_file(), "apache2 config file") and result
138         if not result:
139             _log.error('    Please install using: "sudo apt-get install apache2 libapache2-mod-php5"')
140             _log.error('')
141         return result
142
143     def _check_lighttpd_install(self):
144         result = self._check_file_exists(
145             self._path_to_lighttpd(), "LigHTTPd executable")
146         result = self._check_file_exists(self._path_to_lighttpd_php(), "PHP CGI executable") and result
147         result = self._check_file_exists(self._path_to_lighttpd_modules(), "LigHTTPd modules") and result
148         if not result:
149             _log.error('    Please install using: "sudo apt-get install lighttpd php5-cgi"')
150             _log.error('')
151         return result
152
153     def check_wdiff(self, logging=True):
154         result = self._check_file_exists(self._path_to_wdiff(), 'wdiff')
155         if not result and logging:
156             _log.error('    Please install using: "sudo apt-get install wdiff"')
157             _log.error('')
158         # FIXME: The ChromiumMac port always returns True.
159         return result
160
161     def _path_to_apache(self):
162         if self._is_redhat_based():
163             return '/usr/sbin/httpd'
164         else:
165             return '/usr/sbin/apache2'
166
167     def _path_to_apache_config_file(self):
168         if self._is_redhat_based():
169             config_name = 'fedora-httpd.conf'
170         else:
171             config_name = 'apache2-debian-httpd.conf'
172
173         return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf', config_name)
174
175     def _path_to_lighttpd(self):
176         return "/usr/sbin/lighttpd"
177
178     def _path_to_lighttpd_modules(self):
179         return "/usr/lib/lighttpd"
180
181     def _path_to_lighttpd_php(self):
182         return "/usr/bin/php-cgi"
183
184     def _path_to_driver(self, configuration=None):
185         if not configuration:
186             configuration = self.get_option('configuration')
187         binary_name = 'DumpRenderTree'
188         return self._build_path(configuration, binary_name)
189
190     def _path_to_helper(self):
191         return None
192
193     def _path_to_wdiff(self):
194         if self._is_redhat_based():
195             return '/usr/bin/dwdiff'
196         else:
197             return '/usr/bin/wdiff'
198
199     def _is_redhat_based(self):
200         return self._filesystem.exists(self._filesystem.join('/etc', 'redhat-release'))