<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212741] trunk/Tools</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212741">212741</a></dd>
<dt>Author</dt> <dd>jbedard@apple.com</dd>
<dt>Date</dt> <dd>2017-02-21 13:03:55 -0800 (Tue, 21 Feb 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>webkitpy: Refactor Device class
https://bugs.webkit.org/show_bug.cgi?id=168332
Reviewed by Alexey Proskuryakov.
Separate the more specific SimulatedDevice from the abstract
idea of a device.
* Scripts/webkitpy/xcode/device.py: Added.
(Device): Base device class.
(Device.__init__): Initialize _host, name and udid.
(Device.install_app): Function declaration.
(Device.launch_app): Ditto.
(Device.__eq__): Compare two devices by udid.
(Device.__ne__): Ditto.
(Device.__repr__): Return device name and udid in formatted string.
* Scripts/webkitpy/xcode/simulated_device.py: Copied from Tools/Scripts/webkitpy/xcode/simulator.py.
(SimulatedDevice):
(SimulatedDevice.__init__): Call Device.__init__ first.
(SimulatedDevice.delete): Device -> SimulatedDevice.
(SimulatedDevice.reset): Ditto.
(SimulatedDevice.__eq__): Moved to device.py.
(SimulatedDevice.__ne__): Ditto.
(SimulatedDevice.__repr__): Call Device __repr__ first.
(DeviceType): Kept in Scripts/webkitpy/xcode/simulator.py.
(Runtime): Kept in Scripts/webkitpy/xcode/simulator.py.
(Device): Renamed SimulatedDevice.
(Simulator): Kept in Scripts/webkitpy/xcode/simulator.py.
* Scripts/webkitpy/xcode/simulator.py:
(Simulator): Define Simulator.Device class as None.
(Simulator.__init__): Import SimulatedDevice as Simulator.Device.
(Simulator.delete_device): Use Simulator.Device.
(Simulator.reset_device): Ditto.
(Simulator._parse_devices): Ditto.
(Simulator.lookup_or_create_device): Make
(Device): Moved to simulated_device as SimulatedDevice.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpyxcodesimulatorpy">trunk/Tools/Scripts/webkitpy/xcode/simulator.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsScriptswebkitpyxcodedevicepy">trunk/Tools/Scripts/webkitpy/xcode/device.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyxcodesimulated_devicepy">trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (212740 => 212741)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-21 20:57:03 UTC (rev 212740)
+++ trunk/Tools/ChangeLog        2017-02-21 21:03:55 UTC (rev 212741)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2017-02-21 Jonathan Bedard <jbedard@apple.com>
+
+ webkitpy: Refactor Device class
+ https://bugs.webkit.org/show_bug.cgi?id=168332
+
+ Reviewed by Alexey Proskuryakov.
+
+ Separate the more specific SimulatedDevice from the abstract
+ idea of a device.
+
+ * Scripts/webkitpy/xcode/device.py: Added.
+ (Device): Base device class.
+ (Device.__init__): Initialize _host, name and udid.
+ (Device.install_app): Function declaration.
+ (Device.launch_app): Ditto.
+ (Device.__eq__): Compare two devices by udid.
+ (Device.__ne__): Ditto.
+ (Device.__repr__): Return device name and udid in formatted string.
+ * Scripts/webkitpy/xcode/simulated_device.py: Copied from Tools/Scripts/webkitpy/xcode/simulator.py.
+ (SimulatedDevice):
+ (SimulatedDevice.__init__): Call Device.__init__ first.
+ (SimulatedDevice.delete): Device -> SimulatedDevice.
+ (SimulatedDevice.reset): Ditto.
+ (SimulatedDevice.__eq__): Moved to device.py.
+ (SimulatedDevice.__ne__): Ditto.
+ (SimulatedDevice.__repr__): Call Device __repr__ first.
+ (DeviceType): Kept in Scripts/webkitpy/xcode/simulator.py.
+ (Runtime): Kept in Scripts/webkitpy/xcode/simulator.py.
+ (Device): Renamed SimulatedDevice.
+ (Simulator): Kept in Scripts/webkitpy/xcode/simulator.py.
+ * Scripts/webkitpy/xcode/simulator.py:
+ (Simulator): Define Simulator.Device class as None.
+ (Simulator.__init__): Import SimulatedDevice as Simulator.Device.
+ (Simulator.delete_device): Use Simulator.Device.
+ (Simulator.reset_device): Ditto.
+ (Simulator._parse_devices): Ditto.
+ (Simulator.lookup_or_create_device): Make
+ (Device): Moved to simulated_device as SimulatedDevice.
+
</ins><span class="cx"> 2017-02-21 JF Bastien <jfbastien@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix cmake build
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodedevicepy"></a>
<div class="addfile"><h4>Added: trunk/Tools/Scripts/webkitpy/xcode/device.py (0 => 212741)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/device.py         (rev 0)
+++ trunk/Tools/Scripts/webkitpy/xcode/device.py        2017-02-21 21:03:55 UTC (rev 212741)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>+# Copyright (C) 2017 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+class Device(object):
+ def __init__(self, name, udid, host):
+ self._host = host
+ self.name = name
+ self.udid = udid
+
+ def install_app(self, app_path, env=None):
+ raise NotImplementedError
+
+ def launch_app(self, bundle_id, args, env=None):
+ raise NotImplementedError
+
+ def __eq__(self, other):
+ return self.udid == other.udid
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __repr__(self):
+ return 'Device "{name}": {udid}.'.format(
+ name=self.name,
+ udid=self.udid)
</ins></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodesimulated_devicepy"></a>
<div class="addfile"><h4>Added: trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py (0 => 212741)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py         (rev 0)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py        2017-02-21 21:03:55 UTC (rev 212741)
</span><span class="lines">@@ -0,0 +1,184 @@
</span><ins>+# Copyright (C) 2014-2017 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import logging
+import re
+import subprocess
+
+from webkitpy.xcode.device import Device
+from webkitpy.xcode.simulator import Simulator
+from webkitpy.common.host import Host
+
+_log = logging.getLogger(__name__)
+
+
+class SimulatedDevice(Device):
+ """
+ Represents a CoreSimulator device underneath a runtime
+ """
+
+ def __init__(self, name, udid, available, runtime, host):
+ """
+ :param name: The device name
+ :type name: str
+ :param udid: The device UDID (a UUID string)
+ :type udid: str
+ :param available: Whether the device is available for use.
+ :type available: bool
+ :param runtime: The iOS Simulator runtime that hosts this device
+ :type runtime: Runtime
+ :param host: The host which can run command line commands
+ :type host: Host
+ """
+ super(SimulatedDevice, self).__init__(name, udid, host)
+ self.available = available
+ self.runtime = runtime
+
+ @property
+ def state(self):
+ """
+ :returns: The current state of the device.
+ :rtype: Simulator.DeviceState
+ """
+ return Simulator.device_state(self.udid)
+
+ @property
+ def path(self):
+ """
+ :returns: The filesystem path that contains the simulator device's data.
+ :rtype: str
+ """
+ return Simulator.device_directory(self.udid)
+
+ @classmethod
+ def create(cls, name, device_type, runtime):
+ """
+ Create a new CoreSimulator device.
+ :param name: The name of the device.
+ :type name: str
+ :param device_type: The CoreSimulatort device type.
+ :type device_type: DeviceType
+ :param runtime: The CoreSimualtor runtime.
+ :type runtime: Runtime
+ :return: The new device or raises a CalledProcessError if ``simctl create`` failed.
+ :rtype: Device
+ """
+ device_udid = subprocess.check_output(['xcrun', 'simctl', 'create', name, device_type.identifier, runtime.identifier]).rstrip()
+ _log.debug('"xcrun simctl create %s %s %s" returned %s', name, device_type.identifier, runtime.identifier, device_udid)
+ Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN)
+ return Simulator().find_device_by_udid(device_udid)
+
+ @classmethod
+ def shutdown(cls, udid):
+ """
+ Shut down the given CoreSimulator device.
+ :param udid: The udid of the device.
+ :type udid: str
+ """
+ device_state = Simulator.device_state(udid)
+ if device_state == Simulator.DeviceState.BOOTING or device_state == Simulator.DeviceState.BOOTED:
+ _log.debug('xcrun simctl shutdown %s', udid)
+ # Don't throw on error. Device shutdown seems to be racy with Simulator app killing.
+ subprocess.call(['xcrun', 'simctl', 'shutdown', udid])
+
+ Simulator.wait_until_device_is_in_state(udid, Simulator.DeviceState.SHUTDOWN)
+
+ @classmethod
+ def delete(cls, udid):
+ """
+ Delete the given CoreSimulator device.
+ :param udid: The udid of the device.
+ :type udid: str
+ """
+ SimulatedDevice.shutdown(udid)
+ try:
+ _log.debug('xcrun simctl delete %s', udid)
+ subprocess.check_call(['xcrun', 'simctl', 'delete', udid])
+ except subprocess.CalledProcessError:
+ raise RuntimeError('"xcrun simctl delete" failed: device state is {}'.format(Simulator.device_state(udid)))
+
+ @classmethod
+ def reset(cls, udid):
+ """
+ Reset the given CoreSimulator device.
+ :param udid: The udid of the device.
+ :type udid: str
+ """
+ SimulatedDevice.shutdown(udid)
+ try:
+ _log.debug('xcrun simctl erase %s', udid)
+ subprocess.check_call(['xcrun', 'simctl', 'erase', udid])
+ except subprocess.CalledProcessError:
+ raise RuntimeError('"xcrun simctl erase" failed: device state is {}'.format(Simulator.device_state(udid)))
+
+ def install_app(self, app_path, env=None):
+ # FIXME: This is a workaround for <rdar://problem/30273973>, Racey failure of simctl install.
+ for x in xrange(3):
+ if self._host.executive.run_command(['xcrun', 'simctl', 'install', self.udid, app_path], return_exit_code=True):
+ return False
+ try:
+ bundle_id = self._host.executive.run_command([
+ '/usr/libexec/PlistBuddy',
+ '-c',
+ 'Print CFBundleIdentifier',
+ self._host.filesystem.join(app_path, 'Info.plist'),
+ ]).rstrip()
+ self._host.executive.kill_process(self.launch_app(bundle_id, [], env=env, attempts=1))
+ return True
+ except RuntimeError:
+ pass
+ return False
+
+ def launch_app(self, bundle_id, args, env=None, attempts=3):
+ environment_to_use = {}
+ SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'
+ for value in (env or {}):
+ if not value.startswith(SIMCTL_ENV_PREFIX):
+ environment_to_use[SIMCTL_ENV_PREFIX + value] = env[value]
+ else:
+ environment_to_use[value] = env[value]
+
+ # FIXME: This is a workaround for <rdar://problem/30172453>.
+ def _log_debug_error(error):
+ _log.debug(error.message_with_output())
+
+ output = None
+ for x in xrange(attempts):
+ output = self._host.executive.run_command(
+ ['xcrun', 'simctl', 'launch', self.udid, bundle_id] + args,
+ env=environment_to_use,
+ error_handler=_log_debug_error,
+ )
+ match = re.match(r'(?P<bundle>[^:]+): (?P<pid>\d+)\n', output)
+ if match:
+ break
+
+ if not match or match.group('bundle') != bundle_id:
+ raise RuntimeError('Failed to find process id for {}: {}'.format(bundle_id, output))
+ return int(match.group('pid'))
+
+ def __repr__(self):
+ return '<{device_info} State: {state}. Runtime: {runtime}, Available: {available}>'.format(
+ device_info=super(SimulatedDevice, self).__repr__(),
+ state=self.state,
+ available=self.available,
+ runtime=self.runtime.identifier)
</ins></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodesimulatorpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/xcode/simulator.py (212740 => 212741)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/simulator.py        2017-02-21 20:57:03 UTC (rev 212740)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulator.py        2017-02-21 21:03:55 UTC (rev 212741)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-# Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
</del><ins>+# Copyright (C) 2014-2017 Apple Inc. All rights reserved.
</ins><span class="cx"> #
</span><span class="cx"> # Redistribution and use in source and binary forms, with or without
</span><span class="cx"> # modification, are permitted provided that the following conditions
</span><span class="lines">@@ -162,168 +162,6 @@
</span><span class="cx"> num_devices=len(self.devices))
</span><span class="cx">
</span><span class="cx">
</span><del>-class Device(object):
- """
- Represents a CoreSimulator device underneath a runtime
- """
-
- def __init__(self, name, udid, available, runtime, host):
- """
- :param name: The device name
- :type name: str
- :param udid: The device UDID (a UUID string)
- :type udid: str
- :param available: Whether the device is available for use.
- :type available: bool
- :param runtime: The iOS Simulator runtime that hosts this device
- :type runtime: Runtime
- :param host: The host which can run command line commands
- :type host: Host
- """
- self._host = host
- self.name = name
- self.udid = udid
- self.available = available
- self.runtime = runtime
-
- @property
- def state(self):
- """
- :returns: The current state of the device.
- :rtype: Simulator.DeviceState
- """
- return Simulator.device_state(self.udid)
-
- @property
- def path(self):
- """
- :returns: The filesystem path that contains the simulator device's data.
- :rtype: str
- """
- return Simulator.device_directory(self.udid)
-
- @classmethod
- def create(cls, name, device_type, runtime):
- """
- Create a new CoreSimulator device.
- :param name: The name of the device.
- :type name: str
- :param device_type: The CoreSimulatort device type.
- :type device_type: DeviceType
- :param runtime: The CoreSimualtor runtime.
- :type runtime: Runtime
- :return: The new device or raises a CalledProcessError if ``simctl create`` failed.
- :rtype: Device
- """
- device_udid = subprocess.check_output(['xcrun', 'simctl', 'create', name, device_type.identifier, runtime.identifier]).rstrip()
- _log.debug('"xcrun simctl create %s %s %s" returned %s', name, device_type.identifier, runtime.identifier, device_udid)
- Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN)
- return Simulator().find_device_by_udid(device_udid)
-
- @classmethod
- def shutdown(cls, udid):
- """
- Shut down the given CoreSimulator device.
- :param udid: The udid of the device.
- :type udid: str
- """
- device_state = Simulator.device_state(udid)
- if device_state == Simulator.DeviceState.BOOTING or device_state == Simulator.DeviceState.BOOTED:
- _log.debug('xcrun simctl shutdown %s', udid)
- # Don't throw on error. Device shutdown seems to be racy with Simulator app killing.
- subprocess.call(['xcrun', 'simctl', 'shutdown', udid])
-
- Simulator.wait_until_device_is_in_state(udid, Simulator.DeviceState.SHUTDOWN)
-
- @classmethod
- def delete(cls, udid):
- """
- Delete the given CoreSimulator device.
- :param udid: The udid of the device.
- :type udid: str
- """
- Device.shutdown(udid)
- try:
- _log.debug('xcrun simctl delete %s', udid)
- subprocess.check_call(['xcrun', 'simctl', 'delete', udid])
- except subprocess.CalledProcessError:
- raise RuntimeError('"xcrun simctl delete" failed: device state is {}'.format(Simulator.device_state(udid)))
-
- @classmethod
- def reset(cls, udid):
- """
- Reset the given CoreSimulator device.
- :param udid: The udid of the device.
- :type udid: str
- """
- Device.shutdown(udid)
- try:
- _log.debug('xcrun simctl erase %s', udid)
- subprocess.check_call(['xcrun', 'simctl', 'erase', udid])
- except subprocess.CalledProcessError:
- raise RuntimeError('"xcrun simctl erase" failed: device state is {}'.format(Simulator.device_state(udid)))
-
- def install_app(self, app_path, env=None):
- # FIXME: This is a workaround for <rdar://problem/30273973>, Racey failure of simctl install.
- for x in xrange(3):
- if self._host.executive.run_command(['xcrun', 'simctl', 'install', self.udid, app_path], return_exit_code=True):
- return False
- try:
- bundle_id = self._host.executive.run_command([
- '/usr/libexec/PlistBuddy',
- '-c',
- 'Print CFBundleIdentifier',
- self._host.filesystem.join(app_path, 'Info.plist'),
- ]).rstrip()
- self._host.executive.kill_process(self.launch_app(bundle_id, [], env=env, attempts=1))
- return True
- except RuntimeError:
- pass
- return False
-
- def launch_app(self, bundle_id, args, env=None, attempts=3):
- environment_to_use = {}
- SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'
- for value in (env or {}):
- if not value.startswith(SIMCTL_ENV_PREFIX):
- environment_to_use[SIMCTL_ENV_PREFIX + value] = env[value]
- else:
- environment_to_use[value] = env[value]
-
- # FIXME: This is a workaround for <rdar://problem/30172453>.
- def _log_debug_error(error):
- _log.debug(error.message_with_output())
-
- output = None
- for x in xrange(attempts):
- output = self._host.executive.run_command(
- ['xcrun', 'simctl', 'launch', self.udid, bundle_id] + args,
- env=environment_to_use,
- error_handler=_log_debug_error,
- )
- match = re.match(r'(?P<bundle>[^:]+): (?P<pid>\d+)\n', output)
- if match:
- break
-
- if not match or match.group('bundle') != bundle_id:
- raise RuntimeError('Failed to find process id for {}: {}'.format(bundle_id, output))
- return int(match.group('pid'))
-
- def __eq__(self, other):
- return self.udid == other.udid
-
- def __ne__(self, other):
- return not self.__eq__(other)
-
- def __repr__(self):
- return '<Device "{name}": {udid}. State: {state}. Runtime: {runtime}, Available: {available}>'.format(
- name=self.name,
- udid=self.udid,
- state=self.state,
- available=self.available,
- runtime=self.runtime.identifier)
-
-
</del><span class="cx"> # FIXME: This class is fragile because it parses the output of the simctl command line utility, which may change.
</span><span class="cx"> # We should find a better way to query for simulator device state and capabilities. Maybe take a similiar
</span><span class="cx"> # approach as in webkitdirs.pm and utilize the parsed output from the device.plist files in the sub-
</span><span class="lines">@@ -344,8 +182,14 @@
</span><span class="cx"> '\s*(?P<name>[^(]+ )\((?P<udid>[^)]+)\) \((?P<state>[^)]+)\)( \((?P<availability>[^)]+)\))?')
</span><span class="cx">
</span><span class="cx"> _managed_devices = {}
</span><ins>+ Device = None
</ins><span class="cx">
</span><span class="cx"> def __init__(self, host=None):
</span><ins>+ # FIXME: This circular import should be resolved.
+ if not Simulator.Device:
+ from webkitpy.xcode.simulated_device import SimulatedDevice
+ Simulator.Device = SimulatedDevice
+
</ins><span class="cx"> self._host = host or Host()
</span><span class="cx"> self.runtimes = []
</span><span class="cx"> self.device_types = []
</span><span class="lines">@@ -438,11 +282,11 @@
</span><span class="cx">
</span><span class="cx"> @staticmethod
</span><span class="cx"> def delete_device(udid):
</span><del>- Device.delete(udid)
</del><ins>+ Simulator.Device.delete(udid)
</ins><span class="cx">
</span><span class="cx"> @staticmethod
</span><span class="cx"> def reset_device(udid):
</span><del>- Device.reset(udid)
</del><ins>+ Simulator.Device.reset(udid)
</ins><span class="cx">
</span><span class="cx"> def refresh(self):
</span><span class="cx"> """
</span><span class="lines">@@ -523,7 +367,7 @@
</span><span class="cx"> raise RuntimeError('Expected == Device Pairs == header but got: "{}"'.format(line))
</span><span class="cx"> break
</span><span class="cx"> if current_runtime:
</span><del>- device = Device(name=device_match.group('name').rstrip(),
</del><ins>+ device = Simulator.Device(name=device_match.group('name').rstrip(),
</ins><span class="cx"> udid=device_match.group('udid'),
</span><span class="cx"> available=device_match.group('availability') is None,
</span><span class="cx"> runtime=current_runtime,
</span><span class="lines">@@ -659,7 +503,7 @@
</span><span class="cx"> if testing_device:
</span><span class="cx"> _log.debug('lookup_or_create_device %s %s %s found %s', name, device_type, runtime, testing_device.name)
</span><span class="cx"> return testing_device
</span><del>- testing_device = Device.create(name, device_type, runtime)
</del><ins>+ testing_device = Simulator.Device.create(name, device_type, runtime)
</ins><span class="cx"> _log.debug('lookup_or_create_device %s %s %s created %s', name, device_type, runtime, testing_device.name)
</span><span class="cx"> assert(testing_device.available)
</span><span class="cx"> return testing_device
</span></span></pre>
</div>
</div>
</body>
</html>