<!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>[214399] 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/214399">214399</a></dd>
<dt>Author</dt> <dd>jbedard@apple.com</dd>
<dt>Date</dt> <dd>2017-03-25 07:44:26 -0700 (Sat, 25 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>webkitpy: Use generalized device instead of platform specific one
https://bugs.webkit.org/show_bug.cgi?id=170078

Reviewed by Daniel Bates.

SimulatedDevice is re-created each time 'xcrun simctl list' is called.  Device
should remain persistent.  Changing Device to a more explicit interface.
SimulatedDevice no longer inherits from Device and IOSSimulator returns Devices
wrapping SimulatedDevices.

* Scripts/webkitpy/port/device.py: Added.
(Device):
(Device.__init__): Construct with platform device.
(Device.install_app): Install app at app path on platform device.
(Device.launch_app): Launch app with bundle ID on platform device.
(Device.poll): Poll platform device.
(Device.udid): Access platform device UDID.
(Device.__nonzero__): Check if instantiated with a valid platform device.
(Device.__eq__): Compare by udid.
(Device.__ne__): Ditto.
(Device.__repr__): Print out platform_device representation.
* Scripts/webkitpy/port/ios_simulator.py:
(IOSSimulatorPort.__init__): Initialize the _device_map to an empty dictionary.
(IOSSimulatorPort._device_for_worker_number_map):  Return self._device_map.
(IOSSimulatorPort._create_simulators): Call Simulator.managed_devices directly.
(IOSSimulatorPort._create_devices): Place Simulator.managed_devices into the
device map.
(IOSSimulatorPort._quit_ios_simulator): Reset self._device_map.
* Scripts/webkitpy/xcode/device.py: Removed.
* Scripts/webkitpy/xcode/simulated_device.py:
(SimulatedDevice):
(SimulatedDevice.__init__): Move host, name and did to SimulatedDevice.
(SimulatedDevice.__eq__): Compare two simulated devices.
(SimulatedDevice.__ne__): Ditto.
(SimulatedDevice.__repr__): Print name and udid.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpyportios_simulatorpy">trunk/Tools/Scripts/webkitpy/port/ios_simulator.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyxcodesimulated_devicepy">trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsScriptswebkitpyportdevicepy">trunk/Tools/Scripts/webkitpy/port/device.py</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkToolsScriptswebkitpyxcodedevicepy">trunk/Tools/Scripts/webkitpy/xcode/device.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (214398 => 214399)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-03-25 08:35:07 UTC (rev 214398)
+++ trunk/Tools/ChangeLog        2017-03-25 14:44:26 UTC (rev 214399)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2017-03-25  Jonathan Bedard  &lt;jbedard@apple.com&gt;
+
+        webkitpy: Use generalized device instead of platform specific one
+        https://bugs.webkit.org/show_bug.cgi?id=170078
+
+        Reviewed by Daniel Bates.
+
+        SimulatedDevice is re-created each time 'xcrun simctl list' is called.  Device
+        should remain persistent.  Changing Device to a more explicit interface.
+        SimulatedDevice no longer inherits from Device and IOSSimulator returns Devices
+        wrapping SimulatedDevices.
+
+        * Scripts/webkitpy/port/device.py: Added.
+        (Device):
+        (Device.__init__): Construct with platform device.
+        (Device.install_app): Install app at app path on platform device.
+        (Device.launch_app): Launch app with bundle ID on platform device.
+        (Device.poll): Poll platform device.
+        (Device.udid): Access platform device UDID.
+        (Device.__nonzero__): Check if instantiated with a valid platform device.
+        (Device.__eq__): Compare by udid.
+        (Device.__ne__): Ditto.
+        (Device.__repr__): Print out platform_device representation.
+        * Scripts/webkitpy/port/ios_simulator.py:
+        (IOSSimulatorPort.__init__): Initialize the _device_map to an empty dictionary.
+        (IOSSimulatorPort._device_for_worker_number_map):  Return self._device_map.
+        (IOSSimulatorPort._create_simulators): Call Simulator.managed_devices directly.
+        (IOSSimulatorPort._create_devices): Place Simulator.managed_devices into the
+        device map.
+        (IOSSimulatorPort._quit_ios_simulator): Reset self._device_map.
+        * Scripts/webkitpy/xcode/device.py: Removed.
+        * Scripts/webkitpy/xcode/simulated_device.py:
+        (SimulatedDevice):
+        (SimulatedDevice.__init__): Move host, name and did to SimulatedDevice.
+        (SimulatedDevice.__eq__): Compare two simulated devices.
+        (SimulatedDevice.__ne__): Ditto.
+        (SimulatedDevice.__repr__): Print name and udid.
+
</ins><span class="cx"> 2017-03-25  Adrian Perez de Castro  &lt;aperez@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] No value returned from PrintCustomWidgetTest::createWebKitPrintOperation() in TestPrinting.cpp
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportdevicepyfromrev214398trunkToolsScriptswebkitpyxcodedevicepy"></a>
<div class="copfile"><h4>Copied: trunk/Tools/Scripts/webkitpy/port/device.py (from rev 214398, trunk/Tools/Scripts/webkitpy/xcode/device.py) (0 => 214399)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/device.py                                (rev 0)
+++ trunk/Tools/Scripts/webkitpy/port/device.py        2017-03-25 14:44:26 UTC (rev 214399)
</span><span class="lines">@@ -0,0 +1,52 @@
</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, platform_device):
+        self.platform_device = platform_device
+
+    def install_app(self, app_path, env=None):
+        return self.platform_device.install_app(app_path, env)
+
+    def launch_app(self, bundle_id, args, env=None):
+        return self.platform_device.launch_app(bundle_id, args, env)
+
+    # FIXME: This should be implemented through an executive
+    def poll(self, pid):
+        return self.platform_device.poll(pid)
+
+    @property
+    def udid(self):
+        return self.platform_device.udid
+
+    def __nonzero__(self):
+        return self.platform_device is not None
+
+    def __eq__(self, other):
+        return self.udid == other.udid
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __repr__(self):
+        return str(self.platform_device)
</ins></span></pre></div>
<a id="trunkToolsScriptswebkitpyportios_simulatorpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/ios_simulator.py (214398 => 214399)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/ios_simulator.py        2017-03-25 08:35:07 UTC (rev 214398)
+++ trunk/Tools/Scripts/webkitpy/port/ios_simulator.py        2017-03-25 14:44:26 UTC (rev 214399)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> from webkitpy.common.memoized import memoized
</span><span class="cx"> from webkitpy.layout_tests.models.test_configuration import TestConfiguration
</span><span class="cx"> from webkitpy.port import image_diff
</span><ins>+from webkitpy.port.device import Device
</ins><span class="cx"> from webkitpy.port.ios import IOSPort
</span><span class="cx"> from webkitpy.xcode.simulator import Simulator, Runtime, DeviceType
</span><span class="cx"> from webkitpy.common.system.crashlogs import CrashLogs
</span><span class="lines">@@ -73,7 +74,8 @@
</span><span class="cx">         self._device_class = optional_device_class if optional_device_class else self.DEFAULT_DEVICE_CLASS
</span><span class="cx">         _log.debug('IOSSimulatorPort _device_class is %s', self._device_class)
</span><span class="cx"> 
</span><del>-        self._current_device = Simulator(host).current_device()
</del><ins>+        self._device_map = {}
+        self._current_device = Device(Simulator(host).current_device())
</ins><span class="cx">         if not self._current_device:
</span><span class="cx">             self.set_option('dedicated_simulators', True)
</span><span class="cx">         if not self.get_option('dedicated_simulators'):
</span><span class="lines">@@ -82,7 +84,7 @@
</span><span class="cx">             self.set_option('child_processes', 1)
</span><span class="cx"> 
</span><span class="cx">     def _device_for_worker_number_map(self):
</span><del>-        return Simulator.managed_devices
</del><ins>+        return self._device_map
</ins><span class="cx"> 
</span><span class="cx">     @property
</span><span class="cx">     @memoized
</span><span class="lines">@@ -201,13 +203,13 @@
</span><span class="cx">                 self._create_device(i)
</span><span class="cx"> 
</span><span class="cx">             for i in xrange(self.child_processes()):
</span><del>-                device_udid = self._testing_device(i).udid
</del><ins>+                device_udid = Simulator.managed_devices[i].udid
</ins><span class="cx">                 Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN)
</span><span class="cx">                 Simulator.reset_device(device_udid)
</span><span class="cx">         else:
</span><span class="cx">             assert(self._current_device)
</span><del>-            if self._current_device.name != self.simulator_device_type().name:
-                _log.warn(&quot;Expected simulator of type '&quot; + self.simulator_device_type().name + &quot;' but found simulator of type '&quot; + self._current_device.name + &quot;'&quot;)
</del><ins>+            if self._current_device.platform_device.name != self.simulator_device_type().name:
+                _log.warn(&quot;Expected simulator of type '&quot; + self.simulator_device_type().name + &quot;' but found simulator of type '&quot; + self._current_device.platform_device.name + &quot;'&quot;)
</ins><span class="cx">                 _log.warn('The next block of tests may fail due to device mis-match')
</span><span class="cx"> 
</span><span class="cx">     def _create_devices(self, device_class):
</span><span class="lines">@@ -224,7 +226,7 @@
</span><span class="cx">             return
</span><span class="cx"> 
</span><span class="cx">         for i in xrange(self.child_processes()):
</span><del>-            device_udid = self._testing_device(i).udid
</del><ins>+            device_udid = Simulator.managed_devices[i].udid
</ins><span class="cx">             _log.debug('testing device %s has udid %s', i, device_udid)
</span><span class="cx"> 
</span><span class="cx">             # FIXME: &lt;rdar://problem/20916140&gt; Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
</span><span class="lines">@@ -237,9 +239,14 @@
</span><span class="cx"> 
</span><span class="cx">         _log.info('Waiting for all iOS Simulators to finish booting.')
</span><span class="cx">         for i in xrange(self.child_processes()):
</span><del>-            Simulator.wait_until_device_is_booted(self._testing_device(i).udid)
</del><ins>+            Simulator.wait_until_device_is_booted(Simulator.managed_devices[i].udid)
</ins><span class="cx"> 
</span><ins>+        self._device_map = {}
+        for id, platform_device in Simulator.managed_devices:
+            self._device_map[id] = Device(platform_device)
+
</ins><span class="cx">     def _quit_ios_simulator(self):
</span><ins>+        self._device_map = {}
</ins><span class="cx">         if not self._using_dedicated_simulators():
</span><span class="cx">             return
</span><span class="cx">         _log.debug(&quot;_quit_ios_simulator killing all Simulator processes&quot;)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodedevicepy"></a>
<div class="delfile"><h4>Deleted: trunk/Tools/Scripts/webkitpy/xcode/device.py (214398 => 214399)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/device.py        2017-03-25 08:35:07 UTC (rev 214398)
+++ trunk/Tools/Scripts/webkitpy/xcode/device.py        2017-03-25 14:44:26 UTC (rev 214399)
</span><span class="lines">@@ -1,48 +0,0 @@
</span><del>-# 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 poll(self, pid):
-        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 &quot;{name}&quot;: {udid}.'.format(
-            name=self.name,
-            udid=self.udid)
</del></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodesimulated_devicepy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py (214398 => 214399)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py        2017-03-25 08:35:07 UTC (rev 214398)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py        2017-03-25 14:44:26 UTC (rev 214399)
</span><span class="lines">@@ -27,7 +27,6 @@
</span><span class="cx"> import signal
</span><span class="cx"> import subprocess
</span><span class="cx"> 
</span><del>-from webkitpy.xcode.device import Device
</del><span class="cx"> from webkitpy.xcode.simulator import Simulator
</span><span class="cx"> from webkitpy.common.host import Host
</span><span class="cx"> 
</span><span class="lines">@@ -34,7 +33,7 @@
</span><span class="cx"> _log = logging.getLogger(__name__)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class SimulatedDevice(Device):
</del><ins>+class SimulatedDevice(object):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Represents a CoreSimulator device underneath a runtime
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -52,9 +51,11 @@
</span><span class="cx">         :param host: The host which can run command line commands
</span><span class="cx">         :type host: Host
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        super(SimulatedDevice, self).__init__(name, udid, host)
</del><span class="cx">         self.available = available
</span><span class="cx">         self.runtime = runtime
</span><ins>+        self._host = host
+        self.name = name
+        self.udid = udid
</ins><span class="cx"> 
</span><span class="cx">     @property
</span><span class="cx">     def state(self):
</span><span class="lines">@@ -196,9 +197,16 @@
</span><span class="cx">             return 1
</span><span class="cx">         return None
</span><span class="cx"> 
</span><ins>+    def __eq__(self, other):
+        return self.udid == other.udid
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
</ins><span class="cx">     def __repr__(self):
</span><del>-        return '&lt;{device_info} State: {state}. Runtime: {runtime}, Available: {available}&gt;'.format(
-            device_info=super(SimulatedDevice, self).__repr__(),
</del><ins>+        return '&lt;Device &quot;{name}&quot;: {udid}. State: {state}. Runtime: {runtime}, Available: {available}&gt;'.format(
+            name=self.name,
+            udid=self.udid,
</ins><span class="cx">             state=self.state,
</span><span class="cx">             available=self.available,
</span><span class="cx">             runtime=self.runtime.identifier)
</span></span></pre>
</div>
</div>

</body>
</html>