check-webkit-style can't handle qt-arm, qt-win, qt-mac, qt-5.0, qt-5.0-wk1 and qt...
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / qt.py
1 # Copyright (C) 2010 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 Google name 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 """QtWebKit implementation of the Port interface."""
30
31 import glob
32 import logging
33 import re
34 import sys
35 import os
36
37 from webkitpy.common.memoized import memoized
38 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
39 from webkitpy.layout_tests.port.base import Port
40 from webkitpy.layout_tests.port.xvfbdriver import XvfbDriver
41
42 _log = logging.getLogger(__name__)
43
44
45 class QtPort(Port):
46     ALL_VERSIONS = ['linux', 'win', 'mac']
47     port_name = "qt"
48
49     def _wk2_port_name(self):
50         return "qt-5.0-wk2"
51
52     def _port_flag_for_scripts(self):
53         return "--qt"
54
55     @classmethod
56     def determine_full_port_name(cls, host, options, port_name):
57         if port_name and port_name != cls.port_name:
58             return port_name
59         return port_name + '-' + host.platform.os_name
60
61     # sys_platform exists only for unit testing.
62     def __init__(self, host, port_name, **kwargs):
63         super(QtPort, self).__init__(host, port_name, **kwargs)
64
65         # FIXME: This will allow Port.baseline_search_path and Port._skipped_file_search_paths
66         # to do the right thing, but doesn't include support for qt-4.8 or qt-arm (seen in LayoutTests/platform) yet.
67         self._operating_system = port_name.replace('qt-', '')
68
69         # FIXME: Why is this being set at all?
70         self._version = self.operating_system()
71
72     def _generate_all_test_configurations(self):
73         configurations = []
74         for version in self.ALL_VERSIONS:
75             for build_type in self.ALL_BUILD_TYPES:
76                 configurations.append(TestConfiguration(version=version, architecture='x86', build_type=build_type))
77         return configurations
78
79     def _build_driver(self):
80         # The Qt port builds DRT as part of the main build step
81         return True
82
83     def _path_to_driver(self):
84         return self._build_path('bin/%s' % self.driver_name())
85
86     def _path_to_image_diff(self):
87         return self._build_path('bin/ImageDiff')
88
89     def _path_to_webcore_library(self):
90         if self.operating_system() == 'mac':
91             return self._build_path('lib/QtWebKit.framework/QtWebKit')
92         else:
93             return self._build_path('lib/libQtWebKit.so')
94
95     def _modules_to_search_for_symbols(self):
96         # We search in every library to be reliable in the case of building with CONFIG+=force_static_libs_as_shared.
97         if self.operating_system() == 'mac':
98             frameworks = glob.glob(os.path.join(self._build_path('lib'), '*.framework'))
99             return [os.path.join(framework, os.path.splitext(os.path.basename(framework))[0]) for framework in frameworks]
100         else:
101             suffix = 'dll' if self.operating_system() == 'win' else 'so'
102             return glob.glob(os.path.join(self._build_path('lib'), 'lib*.' + suffix))
103
104     @memoized
105     def qt_version(self):
106         version = ''
107         try:
108             for line in self._executive.run_command(['qmake', '-v']).split('\n'):
109                 match = re.search('Qt\sversion\s(?P<version>\d\.\d)', line)
110                 if match:
111                     version = match.group('version')
112                     break
113         except OSError:
114             version = '4.8'
115         return version
116
117     def _search_paths(self):
118         # Qt port uses same paths for baseline_search_path and _skipped_file_search_paths
119         #
120         # qt-5.0-wk1    qt-5.0-wk2
121         #            \/
122         #         qt-5.0    qt-4.8
123         #                \/
124         #    (qt-linux|qt-mac|qt-win)
125         #                |
126         #               qt
127         search_paths = []
128         version = self.qt_version()
129         if '5.0' in version:
130             if self.get_option('webkit_test_runner'):
131                 search_paths.append('qt-5.0-wk2')
132             else:
133                 search_paths.append('qt-5.0-wk1')
134         if '4.8' in version:
135             search_paths.append('qt-4.8')
136         elif version:
137             search_paths.append('qt-5.0')
138         search_paths.append(self.port_name + '-' + self.operating_system())
139         search_paths.append(self.port_name)
140         return search_paths
141
142     def default_baseline_search_path(self):
143         return map(self._webkit_baseline_path, self._search_paths())
144
145     def expectations_files(self):
146         paths = self._search_paths()
147         if self.get_option('webkit_test_runner'):
148             paths.append('wk2')
149
150         # expectations_files() uses the directories listed in _search_paths reversed.
151         # e.g. qt -> qt-linux -> qt-4.8
152         return list(reversed([self._filesystem.join(self._webkit_baseline_path(p), 'TestExpectations') for p in paths]))
153
154     def setup_environ_for_server(self, server_name=None):
155         clean_env = super(QtPort, self).setup_environ_for_server(server_name)
156         clean_env['QTWEBKIT_PLUGIN_PATH'] = self._build_path('lib/plugins')
157         self._copy_value_from_environ_if_set(clean_env, 'QT_DRT_WEBVIEW_MODE')
158         self._copy_value_from_environ_if_set(clean_env, 'DYLD_IMAGE_SUFFIX')
159         self._copy_value_from_environ_if_set(clean_env, 'QT_WEBKIT_LOG')
160         self._copy_value_from_environ_if_set(clean_env, 'DISABLE_NI_WARNING')
161         self._copy_value_from_environ_if_set(clean_env, 'QT_WEBKIT_PAUSE_UI_PROCESS')
162         self._copy_value_from_environ_if_set(clean_env, 'QT_QPA_PLATFORM_PLUGIN_PATH')
163         return clean_env
164
165     # FIXME: We should find a way to share this implmentation with Gtk,
166     # or teach run-launcher how to call run-safari and move this down to Port.
167     def show_results_html_file(self, results_filename):
168         run_launcher_args = []
169         if self.get_option('webkit_test_runner'):
170             run_launcher_args.append('-2')
171         run_launcher_args.append("file://%s" % results_filename)
172         self._run_script("run-launcher", run_launcher_args)
173
174     def operating_system(self):
175         return self._operating_system
176
177     def check_sys_deps(self, needs_http):
178         result = super(QtPort, self).check_sys_deps(needs_http)
179         if not 'WEBKIT_TESTFONTS' in os.environ:
180             _log.error('\nThe WEBKIT_TESTFONTS environment variable is not defined or not set properly.')
181             _log.error('You must set it before running the tests.')
182             _log.error('Use git to grab the actual fonts from http://gitorious.org/qtwebkit/testfonts')
183             return False
184         return result
185