<!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>[178601] 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/178601">178601</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2015-01-16 13:58:28 -0800 (Fri, 16 Jan 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/171968">r171968</a>): run-safari --simulator fails to launch Safari on iOS
https://bugs.webkit.org/show_bug.cgi?id=135589
Reviewed by David Kilzer.
Derived from a patch by David Farler.
Following the removal IPhoneSimulatorNotification.pm in <http://trac.webkit.org/changeset/171968>
run-safari --simulator fails to launch Safari on iOS. We need to implement run-safari
in terms of the simctl command line utility.
* Scripts/webkitdirs.pm: Added constant SIMULATOR_DEVICE_STATE_BOOTED.
(eraseIOSSimulatorDevice): Added.
(bootedIOSSimulatorDevice): Added.
(iosSimulatorApplicationsPath): Added.
(installedMobileSafariBundle): Implemented in terms of iosSimulatorApplicationsPath().
(openIOSSimulator): Modified to launch iOS Simulator using OPEN(1).
(quitIOSSimulator): Added.
(iosSimulatorDeviceByName): Modified to find the first simulator device that matches
the specified name and currently selected iOS runtime.
(isIOSSimulatorSystemInstalledApp): Added.
(runIOSWebKitAppInSimulator): Modified to use simctl launch to launch an app in the simulator.
(deleteiOSSimulatorDevice): Deleted.
(loadIPhoneSimulatorNotificationIfNeeded): Deleted.
(installAndLaunchIOSWebKitAppInSimulator): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitdirspm">trunk/Tools/Scripts/webkitdirs.pm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (178600 => 178601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-01-16 21:42:50 UTC (rev 178600)
+++ trunk/Tools/ChangeLog        2015-01-16 21:58:28 UTC (rev 178601)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-01-16 Daniel Bates <dabates@apple.com>
+
+ REGRESSION (r171968): run-safari --simulator fails to launch Safari on iOS
+ https://bugs.webkit.org/show_bug.cgi?id=135589
+
+ Reviewed by David Kilzer.
+
+ Derived from a patch by David Farler.
+
+ Following the removal IPhoneSimulatorNotification.pm in <http://trac.webkit.org/changeset/171968>
+ run-safari --simulator fails to launch Safari on iOS. We need to implement run-safari
+ in terms of the simctl command line utility.
+
+ * Scripts/webkitdirs.pm: Added constant SIMULATOR_DEVICE_STATE_BOOTED.
+ (eraseIOSSimulatorDevice): Added.
+ (bootedIOSSimulatorDevice): Added.
+ (iosSimulatorApplicationsPath): Added.
+ (installedMobileSafariBundle): Implemented in terms of iosSimulatorApplicationsPath().
+ (openIOSSimulator): Modified to launch iOS Simulator using OPEN(1).
+ (quitIOSSimulator): Added.
+ (iosSimulatorDeviceByName): Modified to find the first simulator device that matches
+ the specified name and currently selected iOS runtime.
+ (isIOSSimulatorSystemInstalledApp): Added.
+ (runIOSWebKitAppInSimulator): Modified to use simctl launch to launch an app in the simulator.
+ (deleteiOSSimulatorDevice): Deleted.
+ (loadIPhoneSimulatorNotificationIfNeeded): Deleted.
+ (installAndLaunchIOSWebKitAppInSimulator): Deleted.
+
</ins><span class="cx"> 2015-01-16 Alex Christensen <alex.christensen@flexsim.com>
</span><span class="cx">
</span><span class="cx"> Resurrect the WinCairo bot.
</span></span></pre></div>
<a id="trunkToolsScriptswebkitdirspm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitdirs.pm (178600 => 178601)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitdirs.pm        2015-01-16 21:42:50 UTC (rev 178600)
+++ trunk/Tools/Scripts/webkitdirs.pm        2015-01-16 21:58:28 UTC (rev 178601)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> use version;
</span><span class="cx"> use warnings;
</span><span class="cx"> use Config;
</span><ins>+use Cwd qw(realpath);
</ins><span class="cx"> use Digest::MD5 qw(md5_hex);
</span><span class="cx"> use FindBin;
</span><span class="cx"> use File::Basename;
</span><span class="lines">@@ -63,7 +64,6 @@
</span><span class="cx"> &currentSVNRevision
</span><span class="cx"> &debugSafari
</span><span class="cx"> &findOrCreateSimulatorForIOSDevice
</span><del>- &installAndLaunchIOSWebKitAppInSimulator
</del><span class="cx"> &iosSimulatorDeviceByName
</span><span class="cx"> &nmPath
</span><span class="cx"> &openIOSSimulator
</span><span class="lines">@@ -86,6 +86,7 @@
</span><span class="cx">
</span><span class="cx"> use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
</span><span class="cx"> use constant INCLUDE_OPTIONS_FOR_DEBUGGING => 1;
</span><ins>+use constant SIMULATOR_DEVICE_STATE_BOOTED => "3";
</ins><span class="cx">
</span><span class="cx"> our @EXPORT_OK;
</span><span class="cx">
</span><span class="lines">@@ -1178,12 +1179,23 @@
</span><span class="cx"> die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-sub deleteiOSSimulatorDevice
</del><ins>+sub eraseIOSSimulatorDevice($)
</ins><span class="cx"> {
</span><span class="cx"> my $udid = shift;
</span><del>- return system("xcrun", "--sdk", "iphonesimulator", "simctl", "delete", $udid);
</del><ins>+ return exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "erase", $udid)) == 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+sub bootedIOSSimulatorDevice()
+{
+ my @devices = iOSSimulatorDevices();
+ for my $device (@devices) {
+ if ($device->{state} eq SIMULATOR_DEVICE_STATE_BOOTED) {
+ return $device;
+ }
+ }
+ return undef;
+}
+
</ins><span class="cx"> sub willUseIOSDeviceSDKWhenBuilding()
</span><span class="cx"> {
</span><span class="cx"> return xcodeSDKPlatformName() eq "iphoneos";
</span><span class="lines">@@ -2026,9 +2038,14 @@
</span><span class="cx"> setUpGuardMallocIfNeeded();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+sub iosSimulatorApplicationsPath()
+{
+ return File::Spec->catdir(XcodeSDKPath(), "Applications");
+}
+
</ins><span class="cx"> sub installedMobileSafariBundle()
</span><span class="cx"> {
</span><del>- return File::Spec->catfile(XcodeSDKPath(), "Applications", "MobileSafari.app");
</del><ins>+ return File::Spec->catfile(iosSimulatorApplicationsPath(), "MobileSafari.app");
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> sub mobileSafariBundle()
</span><span class="lines">@@ -2066,44 +2083,36 @@
</span><span class="cx"> return $bundleDisplayName;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-sub loadIPhoneSimulatorNotificationIfNeeded()
</del><ins>+sub openIOSSimulator($)
</ins><span class="cx"> {
</span><del>- return if $didLoadIPhoneSimulatorNotification;
- push(@INC, productDir() . "/lib/perl5/darwin-thread-multi-2level");
- require IPhoneSimulatorNotification;
- $didLoadIPhoneSimulatorNotification = 1;
-}
-
-sub openIOSSimulator()
-{
</del><ins>+ my ($simulatedDevice) = @_;
</ins><span class="cx"> chomp(my $developerDirectory = $ENV{DEVELOPER_DIR} || `xcode-select --print-path`);
</span><span class="cx"> my $iosSimulatorPath = File::Spec->catfile($developerDirectory, "Applications", "iOS Simulator.app");
</span><span class="cx">
</span><del>- loadIPhoneSimulatorNotificationIfNeeded();
</del><ins>+ system("open", "-a", $iosSimulatorPath, "--args", "-CurrentDeviceUDID", $simulatedDevice->{UDID}) == 0 or die "Failed to open $iosSimulatorPath: $!";
+ my $device;
+ do {
+ $device = iosSimulatorDeviceByName($simulatedDevice->{name});
+ sleep(2);
+ } while ($device->{state} ne SIMULATOR_DEVICE_STATE_BOOTED);
+}
</ins><span class="cx">
</span><del>- my $iPhoneSimulatorNotification = new IPhoneSimulatorNotification;
- $iPhoneSimulatorNotification->startObservingReadyNotification();
- system("open", "-a", $iosSimulatorPath, "--args", "-SessionOnLaunch", "NO") == 0 or die "Failed to open $iosSimulatorPath: $!";
- while (!$iPhoneSimulatorNotification->hasReceivedReadyNotification()) {
- my $date = NSDate->alloc()->initWithTimeIntervalSinceNow_(0.1);
- NSRunLoop->currentRunLoop->runUntilDate_($date);
- $date->release();
- }
- $iPhoneSimulatorNotification->stopObservingReadyNotification();
</del><ins>+sub quitIOSSimulator()
+{
+ return system {"osascript"} "osascript", "-e", 'tell application "iOS Simulator" to quit';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> sub iosSimulatorDeviceByName($)
</span><span class="cx"> {
</span><span class="cx"> my ($simulatorName) = @_;
</span><del>- my @devices = grep {$_->{name} eq $simulatorName} iOSSimulatorDevices();
- my $deviceToUse = $devices[0];
- if (@devices > 1) {
- print "Warning: Found more than one simulator device named '$simulatorName'.\n";
- print " Using simulator device with UDID: $deviceToUse->{UDID}.\n";
- print " To see the list of simulator devices, run:\n";
- print " xcrun --sdk iphonesimulator simctl list\n";
</del><ins>+ my $simulatorRuntime = iosSimulatorRuntime();
+ my @devices = iOSSimulatorDevices();
+ for my $device (@devices) {
+ if ($device->{name} eq $simulatorName && $device->{runtime} eq $simulatorRuntime) {
+ return $device;
+ }
</ins><span class="cx"> }
</span><del>- return $deviceToUse;
</del><ins>+ return undef;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> sub iosSimulatorRuntime()
</span><span class="lines">@@ -2130,13 +2139,26 @@
</span><span class="cx"> return createiOSSimulatorDevice($simulatorName, $simulatorDeviceType, iosSimulatorRuntime());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+sub isIOSSimulatorSystemInstalledApp($)
+{
+ my ($appBundle) = @_;
+ my $simulatorApplicationsPath = iosSimulatorApplicationsPath();
+ return substr(realpath($appBundle), 0, length($simulatorApplicationsPath)) eq $simulatorApplicationsPath;
+}
+
</ins><span class="cx"> sub runIOSWebKitAppInSimulator($;$)
</span><span class="cx"> {
</span><span class="cx"> my ($appBundle, $simulatorOptions) = @_;
</span><span class="cx"> my $productDir = productDir();
</span><del>- my $appDisplayName = appDisplayNameFromBundle($appBundle);
- print "Starting $appDisplayName with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
</del><ins>+ my $appDisplayName = appDisplayNameFromBundle($appBundle);;
+ my $simulatedDevice = findOrCreateSimulatorForIOSDevice("For WebKit Development");
</ins><span class="cx">
</span><ins>+ my $bootedSimulatorDevice = bootedIOSSimulatorDevice();
+ if (!$bootedSimulatorDevice || $bootedSimulatorDevice->{UDID} ne $simulatedDevice->{UDID}) {
+ quitIOSSimulator();
+ openIOSSimulator($simulatedDevice);
+ }
+
</ins><span class="cx"> $simulatorOptions = {} unless $simulatorOptions;
</span><span class="cx">
</span><span class="cx"> my %simulatorENV;
</span><span class="lines">@@ -2146,79 +2168,23 @@
</span><span class="cx"> setupIOSWebKitEnvironment($productDir);
</span><span class="cx"> %simulatorENV = %ENV;
</span><span class="cx"> }
</span><del>- $simulatorOptions->{applicationEnvironment} = \%simulatorENV;
- return installAndLaunchIOSWebKitAppInSimulator($appBundle, findOrCreateSimulatorForIOSDevice("For WebKit Development"), $simulatorOptions) <= 0;
-}
-
-# Launches the iOS WebKit-based application in the specified simulator device and dynamically
-# linked against the built WebKit. The application will be installed if applicable.
-#
-# Args:
-# $appBundle: the path to the app bundle to launch.
-# $simulatedDevice: the simulator device to use to run the app.
-# $simulatorOptions: a hash reference representing optional simulator options.
-# sessionUUID: a unique identifier to use for the iOS Simulator session. Defaults to an identifier
-# of the form "theAwesomeUniqueSessionIdentifierForX" where X is the display name of
-# the specified app.
-# applicationArguments: an array reference representing the arguments to pass to the app (defaults to \@ARGV).
-# applicationEnvironment: a hash reference representing the environment variables to use when launching the app (defaults to {}).
-#
-# Returns the process identifier of the launched app.
-sub installAndLaunchIOSWebKitAppInSimulator($$;$)
-{
- my ($appBundle, $simulatedDevice, $simulatorOptions) = @_;
-
- loadIPhoneSimulatorNotificationIfNeeded();
-
- my $makeNSDictionaryFromHash = sub {
- my ($dict) = @_;
- my $result = NSMutableDictionary->alloc()->initWithCapacity_(scalar(keys %{$dict}));
- for my $key (keys %{$dict}) {
- $result->setObject_forKey_(NSString->stringWithCString_($dict->{$key}), NSString->stringWithCString_($key));
- }
- return $result->autorelease();
- };
- my $makeNSArrayFromArray = sub {
- my ($array) = @_;
- my $result = NSMutableArray->alloc()->initWithCapacity_(scalar(@{$array}));
- for my $item (@{$array}) {
- $result->addObject_(NSString->stringWithCString_($item));
- }
- return $result->autorelease();
- };
-
- my $simulatorENVHashRef = {};
- $simulatorENVHashRef = $simulatorOptions->{applicationEnvironment} if $simulatorOptions && $simulatorOptions->{applicationEnvironment};
</del><span class="cx"> my $applicationArguments = \@ARGV;
</span><span class="cx"> $applicationArguments = $simulatorOptions->{applicationArguments} if $simulatorOptions && $simulatorOptions->{applicationArguments};
</span><del>- my $sessionUUID;
- if ($simulatorOptions && $simulatorOptions->{sessionUUID}) {
- $sessionUUID = $simulatorOptions->{sessionUUID};
- } else {
- $sessionUUID = "theAwesomeUniqueSessionIdentifierFor" . appDisplayNameFromBundle($appBundle);
</del><ins>+
+ # Prefix the environment variables with SIMCTL_CHILD_ per `xcrun simctl help launch`.
+ foreach my $key (keys %simulatorENV) {
+ $ENV{"SIMCTL_CHILD_$key"} = $simulatorENV{$key};
</ins><span class="cx"> }
</span><del>- # FIXME: We should have the iOS application adopt the files descriptors for our standard output and error streams.
- my $sessionInfo = {
- applicationArguments => &$makeNSArrayFromArray($applicationArguments),
- applicationEnvironment => &$makeNSDictionaryFromHash($simulatorENVHashRef),
- applicationIdentifier => NSString->stringWithCString_(appIdentifierFromBundle($appBundle)),
- applicationPath => NSString->stringWithCString_($appBundle),
- deviceUDID => NSString->stringWithCString_($simulatedDevice->{UDID}),
- sessionUUID => NSString->stringWithCString_($sessionUUID),
- };
</del><span class="cx">
</span><del>- openIOSSimulator();
-
- my $iPhoneSimulatorNotification = new IPhoneSimulatorNotification;
- $iPhoneSimulatorNotification->startObservingApplicationLaunchedNotification();
- $iPhoneSimulatorNotification->postStartSessionNotification($sessionInfo);
- while (!$iPhoneSimulatorNotification->hasReceivedApplicationLaunchedNotification()) {
- my $date = NSDate->alloc()->initWithTimeIntervalSinceNow_(0.1);
- NSRunLoop->currentRunLoop->runUntilDate_($date);
- $date->release();
</del><ins>+ # FIXME: We should also erase the iOS Simulator device when alternating between running a
+ # custom-built MobileSafari and the system-installed MobileSafari.
+ if (!isIOSSimulatorSystemInstalledApp($appBundle)) {
+ eraseIOSSimulatorDevice($simulatedDevice->{UDID}) or die;
</ins><span class="cx"> }
</span><del>- $iPhoneSimulatorNotification->stopObservingApplicationLaunchedNotification();
- return $iPhoneSimulatorNotification->applicationLaunchedApplicationPID();
</del><ins>+
+ my $appIdentifier = appIdentifierFromBundle($appBundle);
+ print "Starting $appDisplayName with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
+ return exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "launch", $simulatedDevice->{UDID}, $appIdentifier, @$applicationArguments));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> sub runIOSWebKitApp($)
</span></span></pre>
</div>
</div>
</body>
</html>