⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 260758 in webkit


Ignore:
Timestamp:
Apr 27, 2020, 9:04:30 AM (6 years ago)
Author:
ap@apple.com
Message:

Make run-safari --ios-simulator work again
https://bugs.webkit.org/show_bug.cgi?id=211008

Reviewed by Darin Adler.

While at it, removed all direct uses of device.plist, and all use of Foundation.

  • Scripts/webkitdirs.pm: Stopped exporting unused simulator related functions. New

code should be using webkitpy.
(simulatorDeviceFromJSON): Helper function for parsing simctl output.
(iOSSimulatorDevices): Use simctl instead of reading device.plist.
(createiOSSimulatorDevice): Device creation appears to be synchronous, I couldn't
find any reason for waiting and retrying.
(iosSimulatorApplicationsPath): This is part of the actual fix - runtime path built
here was incorrect; switched to one provided by simctl.
(shutDownIOSSimulatorDevice): Added an early return to avoid stderr spew.
(relaunchIOSSimulator): Another part of the actual fix: open Simulator.app before booting the
simulator to have it visible; CurrentDeviceUDID doesn't work.
(iosSimulatorDeviceByUDID): Stop using device.plist.
(runIOSWebKitAppInSimulator): Stop quitting Simulator.app, we only needed to shut down
the device.
(iOSSimulatorDevicesPath): Deleted.
(quitIOSSimulator): Deleted.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r260756 r260758  
     12020-04-27  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Make run-safari --ios-simulator work again
     4        https://bugs.webkit.org/show_bug.cgi?id=211008
     5
     6        Reviewed by Darin Adler.
     7
     8        While at it, removed all direct uses of device.plist, and all use of Foundation.
     9
     10        * Scripts/webkitdirs.pm: Stopped exporting unused simulator related functions. New
     11        code should be using webkitpy.
     12        (simulatorDeviceFromJSON): Helper function for parsing simctl output.
     13        (iOSSimulatorDevices): Use simctl instead of reading device.plist.
     14        (createiOSSimulatorDevice): Device creation appears to be synchronous, I couldn't
     15        find any reason for waiting and retrying.
     16        (iosSimulatorApplicationsPath): This is part of the actual fix - runtime path built
     17        here was incorrect; switched to one provided by simctl.
     18        (shutDownIOSSimulatorDevice): Added an early return to avoid stderr spew.
     19        (relaunchIOSSimulator): Another part of the actual fix: open Simulator.app before booting the
     20        simulator to have it visible; CurrentDeviceUDID doesn't work.
     21        (iosSimulatorDeviceByUDID): Stop using device.plist.
     22        (runIOSWebKitAppInSimulator): Stop quitting Simulator.app, we only needed to shut down
     23        the device.
     24        (iOSSimulatorDevicesPath): Deleted.
     25        (quitIOSSimulator): Deleted.
     26
    1272020-04-27  Daniel Bates  <dabates@apple.com>
    228
  • trunk/Tools/Scripts/webkitdirs.pm

    r260240 r260758  
    4343use File::Temp qw(tempdir);
    4444use File::stat;
     45use JSON::PP;
    4546use List::Util;
    4647use POSIX;
     
    7172       &executableProductDir
    7273       &extractNonHostConfiguration
    73        &findOrCreateSimulatorForIOSDevice
    74        &iosSimulatorDeviceByName
    7574       &iosVersion
    7675       &nmPath
     
    7978       &printHelpAndExitForRunAndDebugWebKitAppIfNeeded
    8079       &productDir
    81        &quitIOSSimulator
    82        &relaunchIOSSimulator
    83        &restartIOSSimulatorDevice
    8480       &runIOSWebKitApp
    8581       &runMacWebKitApp
     
    9490       &shouldUseFlatpak
    9591       &runInFlatpak
    96        &shutDownIOSSimulatorDevice
    9792       &sourceDir
    9893       &willUseIOSDeviceSDK
    9994       &willUseIOSSimulatorSDK
    10095       DO_NOT_USE_OPEN_COMMAND
    101        SIMULATOR_DEVICE_SUFFIX_FOR_WEBKIT_DEVELOPMENT
    10296       USE_OPEN_COMMAND
    10397   );
     
    125119use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
    126120use constant DO_NOT_USE_OPEN_COMMAND => 2;
    127 use constant SIMULATOR_DEVICE_STATE_SHUTDOWN => "1";
    128 use constant SIMULATOR_DEVICE_STATE_BOOTED => "3";
     121use constant SIMULATOR_DEVICE_STATE_SHUTDOWN => "Shutdown";
     122use constant SIMULATOR_DEVICE_STATE_BOOTED => "Booted";
    129123use constant SIMULATOR_DEVICE_SUFFIX_FOR_WEBKIT_DEVELOPMENT  => "For WebKit Development";
    130124
     
    15121506}
    15131507
    1514 sub iOSSimulatorDevicesPath
    1515 {
    1516     return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
     1508sub simulatorDeviceFromJSON
     1509{
     1510    my $runtime = shift;
     1511    my $jsonDevice = shift;
     1512
     1513    return {
     1514        "UDID" => $jsonDevice->{udid},
     1515        "name" => $jsonDevice->{name},
     1516        "runtime" => $runtime,
     1517        "state" => $jsonDevice->{state},
     1518        "deviceType" => $jsonDevice->{deviceTypeIdentifier}
     1519    };
    15171520}
    15181521
    15191522sub iOSSimulatorDevices
    15201523{
    1521     eval "require Foundation";
    1522     my $devicesPath = iOSSimulatorDevicesPath();
    1523     opendir(DEVICES, $devicesPath);
    1524     my @udids = grep {
    1525         $_ =~ m/^[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}$/;
    1526     } readdir(DEVICES);
    1527     close(DEVICES);
    1528 
    1529     # FIXME: We should parse the device.plist file ourself and map the dictionary keys in it to known
    1530     #        dictionary keys so as to decouple our representation of the plist from the actual structure
    1531     #        of the plist, which may change.
    1532     my @devices = map {
    1533         Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_("$devicesPath/$_/device.plist"));
    1534     } @udids;
     1524    my $output = `xcrun simctl list devices --json`;
     1525    my $runtimes = decode_json($output)->{devices};
     1526    if (!$runtimes) {
     1527        die "No simulator devices found";
     1528    }
     1529
     1530    my @devices = ();
     1531    while ((my $runtime, my $devicesForRuntime) = each %$runtimes) {
     1532        foreach my $jsonDevice (@$devicesForRuntime) {
     1533            next if $jsonDevice->{availabilityError};
     1534            push @devices, simulatorDeviceFromJSON($runtime, $jsonDevice);
     1535        }
     1536    }
    15351537
    15361538    return @devices;
     
    15461548    die "Couldn't create simulator device: $name $deviceTypeId $runtimeId" if not $created;
    15471549
    1548     system("xcrun", "--sdk", "iphonesimulator", "simctl", "list");
    1549 
    1550     print "Waiting for device to be created ...\n";
    1551     sleep 5;
    1552     for (my $tries = 0; $tries < 5; $tries++){
    1553         my @devices = iOSSimulatorDevices();
    1554         foreach my $device (@devices) {
    1555             return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
    1556         }
    1557         sleep 5;
    1558     }
    1559     die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
     1550    my @devices = iOSSimulatorDevices();
     1551    foreach my $device (@devices) {
     1552        return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
     1553    }
     1554
     1555    die "Device $name $deviceTypeId $runtimeId wasn't found";
    15601556}
    15611557
     
    26432639sub iosSimulatorApplicationsPath()
    26442640{
    2645     # FIXME: We should ask simctl for this information, instead of guessing from available runtimes.
    2646     my $runtimePath = File::Spec->catdir(sdkPlatformDirectory("iphoneos"), "Library", "Developer", "CoreSimulator", "Profiles", "Runtimes");
    2647     opendir(RUNTIMES, $runtimePath);
    2648     my @runtimes = grep {/.*\.simruntime/} readdir(RUNTIMES);
    2649     close(RUNTIMES);
    2650     my $sult = File::Spec->catdir($runtimePath, @runtimes ? $runtimes[0] : "iOS.simruntime", "Contents", "Resources", "RuntimeRoot", "Applications");
    2651     return $sult;
     2641    my $output = `xcrun simctl list runtimes iOS --json`;
     2642    my $runtimes = decode_json($output)->{runtimes};
     2643    if (!$runtimes) {
     2644        die "No iOS simulator runtimes found";
     2645    }
     2646    my $runtimePath = @$runtimes[0]->{runtimeRoot};
     2647    return File::Spec->catdir($runtimePath, "Applications");
    26522648}
    26532649
     
    27142710{
    27152711    my ($simulatorDevice) = @_;
     2712
     2713    return if $simulatorDevice->{state} eq SIMULATOR_DEVICE_STATE_SHUTDOWN;
    27162714    system("xcrun --sdk iphonesimulator simctl shutdown $simulatorDevice->{UDID} > /dev/null 2>&1");
    27172715}
     
    27282726{
    27292727    my ($simulatedDevice) = @_;
    2730     quitIOSSimulator($simulatedDevice->{UDID});
    2731 
    2732     # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
     2728    shutDownIOSSimulatorDevice($simulatedDevice);
     2729
    27332730    chomp(my $developerDirectory = $ENV{DEVELOPER_DIR} || `xcode-select --print-path`);
    2734     my $iosSimulatorPath = File::Spec->catfile($developerDirectory, "Applications", "Simulator.app");
     2731    my $iosSimulatorPath = File::Spec->catfile($developerDirectory, "Applications", "Simulator.app");
     2732    # Simulator.app needs to be running before the simulator is booted to have it visible.
    27352733    system("open", "-a", $iosSimulatorPath, "--args", "-CurrentDeviceUDID", $simulatedDevice->{UDID}) == 0 or die "Failed to open $iosSimulatorPath: $!";
     2734    system("xcrun", "simctl", "boot", $simulatedDevice->{UDID}) == 0 or die "Failed to boot simulator $simulatedDevice->{UDID}: $!";
    27362735
    27372736    waitUntilIOSSimulatorDeviceIsInState($simulatedDevice->{UDID}, SIMULATOR_DEVICE_STATE_BOOTED);
    27382737    waitUntilProcessNotRunning("com.apple.datamigrator");
    2739 }
    2740 
    2741 sub quitIOSSimulator(;$)
    2742 {
    2743     my ($waitForShutdownOfSimulatedDeviceUDID) = @_;
    2744     # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
    2745     if (exitStatus(system {"osascript"} "osascript", "-e", 'tell application id "com.apple.iphonesimulator" to quit')) {
    2746         # osascript returns a non-zero exit status if Simulator.app is not registered in LaunchServices.
    2747         return;
    2748     }
    2749 
    2750     if (!defined($waitForShutdownOfSimulatedDeviceUDID)) {
    2751         return;
    2752     }
    2753     # FIXME: We assume that $waitForShutdownOfSimulatedDeviceUDID was not booted using the simctl command line tool.
    2754     #        Otherwise we will spin indefinitely since quiting the iOS Simulator will not shutdown this device. We
    2755     #        should add a maximum time limit to wait for a device to shutdown and either return an error or die()
    2756     #        on expiration of the time limit.
    2757     waitUntilIOSSimulatorDeviceIsInState($waitForShutdownOfSimulatedDeviceUDID, SIMULATOR_DEVICE_STATE_SHUTDOWN);
    27582738}
    27592739
     
    27742754{
    27752755    my ($simulatedDeviceUDID) = @_;
    2776     my $devicePlistPath = File::Spec->catfile(iOSSimulatorDevicesPath(), $simulatedDeviceUDID, "device.plist");
    2777     if (!-f $devicePlistPath) {
    2778         return;
    2779     }
    2780     # FIXME: We should parse the device.plist file ourself and map the dictionary keys in it to known
    2781     #        dictionary keys so as to decouple our representation of the plist from the actual structure
    2782     #        of the plist, which may change.
    2783     eval "require Foundation";
    2784     return Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_($devicePlistPath));
     2756
     2757    my $output = `xcrun simctl list devices $simulatedDeviceUDID --json`;
     2758    my $runtimes = decode_json($output)->{devices};
     2759
     2760    while ((my $runtime, my $devicesForRuntime) = each %$runtimes) {
     2761        next if not @$devicesForRuntime;
     2762        die "Multiple devices found for UDID $simulatedDeviceUDID: $output" if scalar(@$devicesForRuntime) > 1;
     2763        return simulatorDeviceFromJSON($runtime, @$devicesForRuntime[0]);       
     2764    }
     2765    return undef;
    27852766}
    27862767
     
    28722853            # FIXME: Only restore the system-installed version of the app instead of erasing all contents and settings.
    28732854            print "Quitting iOS Simulator...\n";
    2874             quitIOSSimulator($simulatedDeviceUDID);
     2855            shutDownIOSSimulatorDevice($simulatedDevice);
    28752856            print "Erasing contents and settings for simulator device \"$simulatedDevice->{name}\".\n";
    28762857            exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "erase", $simulatedDeviceUDID)) == 0 or die;
Note: See TracChangeset for help on using the changeset viewer.