Title: [275081] trunk/Tools
Revision
275081
Author
[email protected]
Date
2021-03-25 23:57:35 -0700 (Thu, 25 Mar 2021)

Log Message

Avoid calling `xcodebuild -showsdks` where possible.
https://bugs.webkit.org/show_bug.cgi?id=223727

Reviewed by Sam Weinig.

run-minibrowser needs to know what port it's running on, since that
affects the build directory to look in to find the MiniBrowser binary.
On macOS, webkitdirs.pm's determinePortName ends up running
`xcodebuild -showsdks` to see if the current SDK has an internal
variant available, but this is slow.  But we don't need to know the
exact SDK name here, just the SDK platform name, to determine the
port name.

So we shuffle some code around to avoid calling `xcodebuild -showsdks`
where we can.  This reduces the time spent in run-minibrowser before
MiniBrowser is launched (crudely measured with `time run-minibrowser
--help`) from 2s to 0.6s on this machine.

* Scripts/webkitdirs.pm:
(readXcodeUserDefault):
(determineArchitecture):
(argumentsForConfiguration):
(availableXcodeSDKs):
(isValidXcodeSDKPlatformName):
(determineXcodeSDKPlatformName):
(determineXcodeSDK):
(xcodeSDKPlatformName):
(determinePortName):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (275080 => 275081)


--- trunk/Tools/ChangeLog	2021-03-26 06:34:08 UTC (rev 275080)
+++ trunk/Tools/ChangeLog	2021-03-26 06:57:35 UTC (rev 275081)
@@ -1,3 +1,34 @@
+2021-03-25  Cameron McCormack  <[email protected]>
+
+        Avoid calling `xcodebuild -showsdks` where possible.
+        https://bugs.webkit.org/show_bug.cgi?id=223727
+
+        Reviewed by Sam Weinig.
+
+        run-minibrowser needs to know what port it's running on, since that
+        affects the build directory to look in to find the MiniBrowser binary.
+        On macOS, webkitdirs.pm's determinePortName ends up running
+        `xcodebuild -showsdks` to see if the current SDK has an internal
+        variant available, but this is slow.  But we don't need to know the
+        exact SDK name here, just the SDK platform name, to determine the
+        port name.
+
+        So we shuffle some code around to avoid calling `xcodebuild -showsdks`
+        where we can.  This reduces the time spent in run-minibrowser before
+        MiniBrowser is launched (crudely measured with `time run-minibrowser
+        --help`) from 2s to 0.6s on this machine.
+
+        * Scripts/webkitdirs.pm:
+        (readXcodeUserDefault):
+        (determineArchitecture):
+        (argumentsForConfiguration):
+        (availableXcodeSDKs):
+        (isValidXcodeSDKPlatformName):
+        (determineXcodeSDKPlatformName):
+        (determineXcodeSDK):
+        (xcodeSDKPlatformName):
+        (determinePortName):
+
 2021-03-25  Alex Christensen  <[email protected]>
 
         Allow WKContentRuleList to block only in frames or only in main frame

Modified: trunk/Tools/Scripts/webkitdirs.pm (275080 => 275081)


--- trunk/Tools/Scripts/webkitdirs.pm	2021-03-26 06:34:08 UTC (rev 275080)
+++ trunk/Tools/Scripts/webkitdirs.pm	2021-03-26 06:57:35 UTC (rev 275081)
@@ -140,6 +140,7 @@
 my @baseProductDirOption;
 my $configuration;
 my $xcodeSDK;
+my $xcodeSDKPlatformName;
 my $simulatorIdiom;
 my $configurationForVisualStudio;
 my $configurationProductDir;
@@ -400,13 +401,13 @@
         if ($architecture) {
             chomp $architecture;
         } else {
-            if ($xcodeSDK =~ /^iphoneos/) {
+            if ($xcodeSDK eq /iphoneos/) {
                 $architecture = 'arm64';
-            } elsif ($xcodeSDK =~ /^watchsimulator/) {
+            } elsif ($xcodeSDK eq /watchsimulator/) {
                 $architecture = 'i386';
-            } elsif ($xcodeSDK =~ /^watchos/) {
+            } elsif ($xcodeSDK eq /watchos/) {
                 $architecture = 'arm64_32 arm64e armv7k';
-            } elsif ($xcodeSDK =~ /^appletvos/) {
+            } elsif ($xcodeSDK eq /appletvos/) {
                 $architecture = 'arm64';
             }
         }
@@ -549,7 +550,7 @@
     determineConfiguration();
     determineArchitecture();
     if (isAppleCocoaWebKit()) {
-        determineXcodeSDK();
+        determineXcodeSDKPlatformName();
     }
 
     my @args = ();
@@ -557,14 +558,14 @@
     # These are determined automatically from stored configuration.
     push(@args, '--debug') if ($configuration =~ "^Debug");
     push(@args, '--release') if ($configuration =~ "^Release");
-    push(@args, '--ios-device') if (defined $xcodeSDK && $xcodeSDK =~ /^iphoneos/);
-    push(@args, '--ios-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^iphonesimulator/ && $simulatorIdiom eq "iPhone");
-    push(@args, '--ipad-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^iphonesimulator/ && $simulatorIdiom eq "iPad");
-    push(@args, '--tvos-device') if (defined $xcodeSDK && $xcodeSDK =~ /^appletvos/);
-    push(@args, '--tvos-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^appletvsimulator/);
-    push(@args, '--watchos-device') if (defined $xcodeSDK && $xcodeSDK =~ /^watchos/);
-    push(@args, '--watchos-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^watchsimulator/);
-    push(@args, '--maccatalyst') if (defined $xcodeSDK && $xcodeSDK =~ /^maccatalyst/);
+    push(@args, '--ios-device') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^iphoneos/);
+    push(@args, '--ios-simulator') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^iphonesimulator/ && $simulatorIdiom eq "iPhone");
+    push(@args, '--ipad-simulator') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^iphonesimulator/ && $simulatorIdiom eq "iPad");
+    push(@args, '--tvos-device') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^appletvos/);
+    push(@args, '--tvos-simulator') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^appletvsimulator/);
+    push(@args, '--watchos-device') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^watchos/);
+    push(@args, '--watchos-simulator') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^watchsimulator/);
+    push(@args, '--maccatalyst') if (defined $xcodeSDKPlatformName && $xcodeSDKPlatformName eq /^maccatalyst/);
     push(@args, '--32-bit') if ($architecture eq "x86" and !isWin64());
     push(@args, '--64-bit') if (isWin64());
     push(@args, '--ftw') if isFTW();
@@ -622,53 +623,76 @@
     return parseAvailableXcodeSDKs(\@output);
 }
 
-sub determineXcodeSDK
-{
-    return if defined $xcodeSDK;
+sub isValidXcodeSDKPlatformName($) {
+    my $name = shift;
+    my @platforms = qw(
+        appletvos
+        appletvsimulator
+        iphoneos
+        iphonesimulator
+        macosx
+        watchos
+        watchsimulator
+        maccatalyst
+    );
+    return grep { $_ eq $name } @platforms;
+}
+
+sub determineXcodeSDKPlatformName {
+    return if defined $xcodeSDKPlatformName;
     my $sdk;
     
     # The user explicitly specified the sdk, don't assume anything
     if (checkForArgumentAndRemoveFromARGVGettingValue("--sdk", \$sdk)) {
-        $xcodeSDK = $sdk;
+        $xcodeSDK = lc $sdk;
+        $xcodeSDKPlatformName = $sdk;
+        $xcodeSDKPlatformName =~ s/\.internal$//;
+        die "Couldn't determine platform name from Xcode SDK" unless isValidXcodeSDKPlatformName($xcodeSDKPlatformName);
         return;
     }
     if (checkForArgumentAndRemoveFromARGV("--device") || checkForArgumentAndRemoveFromARGV("--ios-device")) {
-        $xcodeSDK ||= "iphoneos";
+        $xcodeSDKPlatformName ||= "iphoneos";
     }
     if (checkForArgumentAndRemoveFromARGV("--simulator") || checkForArgumentAndRemoveFromARGV("--ios-simulator")) {
-        $xcodeSDK ||= 'iphonesimulator';
+        $xcodeSDKPlatformName ||= 'iphonesimulator';
         $simulatorIdiom = 'iPhone';
     }
     if (checkForArgumentAndRemoveFromARGV("--ipad-simulator")) {
-        $xcodeSDK ||= 'iphonesimulator';
+        $xcodeSDKPlatformName ||= 'iphonesimulator';
         $simulatorIdiom = 'iPad';
     }
     if (checkForArgumentAndRemoveFromARGV("--tvos-device")) {
-        $xcodeSDK ||=  "appletvos";
+        $xcodeSDKPlatformName ||= "appletvos";
     }
     if (checkForArgumentAndRemoveFromARGV("--tvos-simulator")) {
-        $xcodeSDK ||= "appletvsimulator";
+        $xcodeSDKPlatformName ||= "appletvsimulator";
     }
     if (checkForArgumentAndRemoveFromARGV("--watchos-device")) {
-        $xcodeSDK ||=  "watchos";
+        $xcodeSDKPlatformName ||= "watchos";
     }
     if (checkForArgumentAndRemoveFromARGV("--watchos-simulator")) {
-        $xcodeSDK ||= "watchsimulator";
+        $xcodeSDKPlatformName ||= "watchsimulator";
     }
     if (checkForArgumentAndRemoveFromARGV("--maccatalyst")) {
-        $xcodeSDK ||= "maccatalyst";
+        $xcodeSDKPlatformName ||= "maccatalyst";
     }
 
     # Finally, fall back to macOS if no platform is specified.
-    if (!defined $xcodeSDK) {
-        $xcodeSDK = "macosx";
-    }
-    
+    $xcodeSDKPlatformName ||= "macosx";
+}
+
+sub determineXcodeSDK
+{
+    determineXcodeSDKPlatformName();  # This can set $xcodeSDK if --sdk was used.
+    return if defined $xcodeSDK;
+
+    $xcodeSDK = $xcodeSDKPlatformName;
+
     # Prefer the internal version of an sdk, if it exists.
     my @availableSDKs = availableXcodeSDKs();
 
     foreach my $sdk (@availableSDKs) {
-        next if $sdk ne "$xcodeSDK.internal";
+        next if $sdk ne "$xcodeSDKPlatformName.internal";
         $xcodeSDK = $sdk;
         last;
     }
@@ -685,20 +709,10 @@
     ($xcodeSDK) = @_;
 }
 
-
-sub xcodeSDKPlatformName()
+sub xcodeSDKPlatformName
 {
-    determineXcodeSDK();
-    return "" if !defined $xcodeSDK;
-    return "appletvos" if $xcodeSDK =~ /appletvos/i;
-    return "appletvsimulator" if $xcodeSDK =~ /appletvsimulator/i;
-    return "iphoneos" if $xcodeSDK =~ /iphoneos/i;
-    return "iphonesimulator" if $xcodeSDK =~ /iphonesimulator/i;
-    return "macosx" if $xcodeSDK =~ /macosx/i;
-    return "watchos" if $xcodeSDK =~ /watchos/i;
-    return "watchsimulator" if $xcodeSDK =~ /watchsimulator/i;
-    return "maccatalyst" if $xcodeSDK =~ /maccatalyst/i;
-    die "Couldn't determine platform name from Xcode SDK";
+    determineXcodeSDKPlatformName();
+    return $xcodeSDKPlatformName;
 }
 
 sub XcodeSDKPath
@@ -1344,7 +1358,7 @@
     if (isAnyWindows()) {
         $portName = AppleWin;
     } elsif (isDarwin()) {
-        determineXcodeSDK();
+        determineXcodeSDKPlatformName();
         if (willUseIOSDeviceSDK() || willUseIOSSimulatorSDK()) {
             $portName = iOS;
         } elsif (willUseAppleTVDeviceSDK() || willUseAppleTVSimulatorSDK()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to