9183e4af838ee4fd5d9b4da0466bc9718e6a64dc
[WebKit-https.git] / Tools / Scripts / webkitpy / port / watch.py
1 # Copyright (C) 2018 Apple 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
5 # are met:
6 # 1.  Redistributions of source code must retain the above copyright
7 #     notice, this list of conditions and the following disclaimer.
8 # 2.  Redistributions in binary form must reproduce the above copyright
9 #     notice, this list of conditions and the following disclaimer in the
10 #     documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23 import logging
24
25 from webkitpy.common.memoized import memoized
26 from webkitpy.common.version import Version
27 from webkitpy.common.version_name_map import VersionNameMap, INTERNAL_TABLE
28 from webkitpy.port.config import apple_additions
29 from webkitpy.port.device_port import DevicePort
30 from webkitpy.xcode.device_type import DeviceType
31
32
33 _log = logging.getLogger(__name__)
34
35
36 class WatchPort(DevicePort):
37     port_name = 'watchos'
38
39     CURRENT_VERSION = Version(5)
40     DEFAULT_DEVICE_TYPE = DeviceType(software_variant='watchOS')
41
42     def __init__(self, *args, **kwargs):
43         super(WatchPort, self).__init__(*args, **kwargs)
44
45         if self.get_option('webkit_test_runner', False) == False:
46             raise RuntimeError('DumpRenderTree is not supported on this platform.')
47
48     def driver_name(self):
49         if self.get_option('driver_name'):
50             return self.get_option('driver_name')
51         return 'WebKitTestRunnerApp.app'
52
53     def version_name(self):
54         if self._os_version is None:
55             return None
56         return VersionNameMap.map(self.host.platform).to_name(self._os_version, platform=WatchPort.port_name)
57
58     def test_expectations_file_position(self):
59         return 4
60
61     def default_baseline_search_path(self, **kwargs):
62         versions_to_fallback = []
63         if self.device_version() == self.CURRENT_VERSION:
64             versions_to_fallback = [self.CURRENT_VERSION]
65         elif self.device_version():
66             temp_version = Version(self.device_version().major)
67             while temp_version.major != self.CURRENT_VERSION.major:
68                 versions_to_fallback.append(Version.from_iterable(temp_version))
69                 if temp_version < self.CURRENT_VERSION:
70                     temp_version.major += 1
71                 else:
72                     temp_version.major -= 1
73
74         expectations = []
75         for version in versions_to_fallback:
76             if apple_additions():
77                 apple_name = VersionNameMap.map(self.host.platform).to_name(version, platform=WatchPort.port_name, table=INTERNAL_TABLE)
78                 expectations.append(self._apple_baseline_path('{}-{}'.format(self.port_name, apple_name.lower().replace(' ', ''))))
79             expectations.append(self._webkit_baseline_path('{}-{}'.format(self.port_name, version.major)))
80
81         if apple_additions():
82             expectations.append(self._apple_baseline_path(self.port_name))
83         expectations.append(self._webkit_baseline_path(self.port_name))
84
85         for version in versions_to_fallback:
86             apple_name = None
87             if apple_additions():
88                 apple_name = VersionNameMap.map(self.host.platform).to_name(version, platform=WatchPort.port_name, table=INTERNAL_TABLE)
89             if apple_name:
90                 expectations.append(
91                     self._apple_baseline_path('{}-{}'.format(WatchPort.port_name, apple_name.lower().replace(' ', ''))))
92             expectations.append(self._webkit_baseline_path('{}-{}'.format(WatchPort.port_name, version.major)))
93
94         if apple_additions():
95             expectations.append(self._apple_baseline_path(WatchPort.port_name))
96         expectations.append(self._webkit_baseline_path(WatchPort.port_name))
97
98         expectations.append(self._webkit_baseline_path('wk2'))
99
100         return expectations