19d20a217d15bd1d97a3ce2aceeed399a7155b89
[WebKit-https.git] / Tools / Scripts / webkitpy / port / watch_simulator.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.port.config import apple_additions
28 from webkitpy.port.watch import WatchPort
29 from webkitpy.xcode.device_type import DeviceType
30 from webkitpy.xcode.simulated_device import SimulatedDeviceManager
31
32 _log = logging.getLogger(__name__)
33
34
35 class WatchSimulatorPort(WatchPort):
36     port_name = 'watchos-simulator'
37
38     ARCHITECTURES = ['i386']
39     DEFAULT_ARCHITECTURE = 'i386'
40
41     DEVICE_MANAGER = SimulatedDeviceManager
42
43     DEFAULT_DEVICE_TYPE = DeviceType(hardware_family='Apple Watch', hardware_type='Series 3 - 42mm')
44     SDK = apple_additions().get_sdk('watchsimulator') if apple_additions() else 'watchsimulator'
45
46     def architecture(self):
47         return self.DEFAULT_ARCHITECTURE
48
49     # This supports the mapping of a port name such as watchos-simulator-5 to the construction of a port
50     # using watchOS 5.
51     @staticmethod
52     def _version_from_name(name):
53         if len(name.split('-')) > 2 and name.split('-')[2].isdigit():
54             return Version.from_string(name.split('-')[2])
55         return None
56
57     @memoized
58     def device_version(self):
59         if self.get_option('version'):
60             return Version.from_string(self.get_option('version'))
61         return WatchSimulatorPort._version_from_name(self._name) or self.host.platform.xcode_sdk_version('watchsimulator')
62
63     def environment_for_api_tests(self):
64         inherited_env = super(WatchSimulatorPort, self).environment_for_api_tests()
65         new_environment = {}
66         SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'
67         for value in inherited_env:
68             if not value.startswith(SIMCTL_ENV_PREFIX):
69                 new_environment[SIMCTL_ENV_PREFIX + value] = inherited_env[value]
70             else:
71                 new_environment[value] = inherited_env[value]
72         return new_environment
73
74     def operating_system(self):
75         return 'watchos-simulator'
76
77     def setup_environ_for_server(self, server_name=None):
78         _log.debug('Setting up environment for server on {}'.format(self.operating_system()))
79         env = super(WatchSimulatorPort, self).setup_environ_for_server(server_name)
80         if server_name == self.driver_name() and self.get_option('leaks'):
81             env['MallocStackLogging'] = '1'
82             env['__XPC_MallocStackLogging'] = '1'
83             env['MallocScribble'] = '1'
84             env['__XPC_MallocScribble'] = '1'
85         return env
86
87     def reset_preferences(self):
88         SimulatedDeviceManager.tear_down(self.host)
89
90     def nm_command(self):
91         return self.xcrun_find('nm')
92
93     @property
94     @memoized
95     def developer_dir(self):
96         return self._executive.run_command(['xcode-select', '--print-path']).rstrip()
97
98     def logging_patterns_to_strip(self):
99         return []
100
101     def stderr_patterns_to_strip(self):
102         return []