Title: [232583] trunk/Tools
Revision
232583
Author
[email protected]
Date
2018-06-07 09:24:49 -0700 (Thu, 07 Jun 2018)

Log Message

webkitperl: Generalize .internal SDK suffix
https://bugs.webkit.org/show_bug.cgi?id=186352
<rdar://problem/40853947>

Reviewed by Alexey Proskuryakov.

* Scripts/build-webkit:
* Scripts/package-root:
(usage):
* Scripts/webkitdirs.pm:
(parseAvailableXcodeSDKS): Parse 'xcodebuild -showsdks' output.
(availableXcodeSDKS): Generate a list of all available Xcode SDKs on this machine.
(determineXcodeSDK): Always prefer .internal SDKs if available.
* Scripts/webkitperl/webkitdirs_unittest/availableXcodeSDKS.pl:

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (232582 => 232583)


--- trunk/Tools/ChangeLog	2018-06-07 16:11:43 UTC (rev 232582)
+++ trunk/Tools/ChangeLog	2018-06-07 16:24:49 UTC (rev 232583)
@@ -1,3 +1,20 @@
+2018-06-07  Jonathan Bedard  <[email protected]>
+
+        webkitperl: Generalize .internal SDK suffix
+        https://bugs.webkit.org/show_bug.cgi?id=186352
+        <rdar://problem/40853947>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Scripts/build-webkit:
+        * Scripts/package-root:
+        (usage):
+        * Scripts/webkitdirs.pm:
+        (parseAvailableXcodeSDKS): Parse 'xcodebuild -showsdks' output.
+        (availableXcodeSDKS): Generate a list of all available Xcode SDKs on this machine.
+        (determineXcodeSDK): Always prefer .internal SDKs if available.
+        * Scripts/webkitperl/webkitdirs_unittest/availableXcodeSDKS.pl:
+        
 2018-06-07  Fujii Hironori  <[email protected]>
 
         [Win][MiniBrowser] Support multiple windows properly

Modified: trunk/Tools/Scripts/build-webkit (232582 => 232583)


--- trunk/Tools/Scripts/build-webkit	2018-06-07 16:11:43 UTC (rev 232582)
+++ trunk/Tools/Scripts/build-webkit	2018-06-07 16:24:49 UTC (rev 232583)
@@ -101,7 +101,7 @@
   --sdk=<sdk>                       Use a specific Xcode SDK (iOS and Mac only)
   --ios-device                      Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
   --device                          DEPRECATED alias of --ios-device
-  --ios-simulator                   Use the current iphonesimulator SDK (iOS only)
+  --ios-simulator                   Use "iphonesimulator.internal" SDK if installed, else "iphonesimulator" SDK (iOS only)
   --simulator                       DEPRECATED alias of --ios-simulator
   --coverage                        Enable code coverage support (Mac only)
   --analyze                         Enable static anaylsis (iOS and Mac only)

Modified: trunk/Tools/Scripts/package-root (232582 => 232583)


--- trunk/Tools/Scripts/package-root	2018-06-07 16:11:43 UTC (rev 232582)
+++ trunk/Tools/Scripts/package-root	2018-06-07 16:24:49 UTC (rev 232583)
@@ -47,9 +47,9 @@
       --help                            Show this help message
       --sdk                             Specifies SDK for which the roots are staged
                                         (Default: currently installed Base SDK)
-      --ios-device                      Equivalent to --sdk iphoneos.internal
+      --ios-device                      Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
       --device                          DEPRECATED alias of --ios-device
-      --ios-simulator                   Equivalent to --sdk iphonesimulator
+      --ios-simulator                   Use "iphonesimulator.internal" SDK if installed, else "iphonesimulator" SDK (iOS only)
       --simulator                       DEPRECATED alias of --ios-simulator
       --debug                           Package roots from Debug-<platform>
       --release                         Package roots from Release-<platform>

Modified: trunk/Tools/Scripts/webkitdirs.pm (232582 => 232583)


--- trunk/Tools/Scripts/webkitdirs.pm	2018-06-07 16:11:43 UTC (rev 232582)
+++ trunk/Tools/Scripts/webkitdirs.pm	2018-06-07 16:24:49 UTC (rev 232583)
@@ -61,6 +61,7 @@
        &appDisplayNameFromBundle
        &appendToEnvironmentVariableList
        &archCommandLineArgumentsForRestrictedEnvironmentVariables
+       &availableXcodeSDKs
        &baseProductDir
        &chdirWebKit
        &checkFrameworks
@@ -503,34 +504,71 @@
     return @args;
 }
 
+# FIXME: Convert to json <rdar://problem/21594308>
+sub parseAvailableXcodeSDKs($)
+{
+    my @outputToParse = @{$_[0]};
+    my @result = ();
+    foreach my $line (@outputToParse) {
+        # Examples:
+        #    iOS 12.0 -sdk iphoneos12.0
+        #    Simulator - iOS 12.0 -sdk iphonesimulator12.0
+        #    macOS 10.14 -sdk macosx10.14
+        if ($line =~ /-sdk (\D+)([\d\.]+)(\D*)\n/) {
+            if ($3) {
+                push @result, "$1.$3";
+            } else {
+                push @result, "$1";
+            }
+        }
+    }
+    return @result;
+}
+
+sub availableXcodeSDKs
+{
+    my @output = `xcodebuild -showsdks`;
+    return parseAvailableXcodeSDKs(\@output);
+}
+
 sub determineXcodeSDK
 {
     return if defined $xcodeSDK;
     my $sdk;
+    
+    # The user explicitly specified the sdk, don't assume anything
     if (checkForArgumentAndRemoveFromARGVGettingValue("--sdk", \$sdk)) {
         $xcodeSDK = $sdk;
+        return;
     }
     if (checkForArgumentAndRemoveFromARGV("--device") || checkForArgumentAndRemoveFromARGV("--ios-device")) {
-        my $hasInternalSDK = exitStatus(system("xcrun --sdk iphoneos.internal --show-sdk-version > /dev/null 2>&1")) == 0;
-        $xcodeSDK ||= $hasInternalSDK ? "iphoneos.internal" : "iphoneos";
+        $xcodeSDK ||= "iphoneos";
     }
     if (checkForArgumentAndRemoveFromARGV("--simulator") || checkForArgumentAndRemoveFromARGV("--ios-simulator")) {
         $xcodeSDK ||= 'iphonesimulator';
     }
     if (checkForArgumentAndRemoveFromARGV("--tvos-device")) {
-        my $hasInternalSDK = exitStatus(system("xcrun --sdk appletvos.internal --show-sdk-version > /dev/null 2>&1")) == 0;
-        $xcodeSDK ||=  $hasInternalSDK ? "appletvos.internal" : "appletvos";
+        $xcodeSDK ||=  "appletvos";
     }
     if (checkForArgumentAndRemoveFromARGV("--tvos-simulator")) {
         $xcodeSDK ||= "appletvsimulator";
     }
     if (checkForArgumentAndRemoveFromARGV("--watchos-device")) {
-        my $hasInternalSDK = exitStatus(system("xcrun --sdk watchos.internal --show-sdk-version > /dev/null 2>&1")) == 0;
-        $xcodeSDK ||=  $hasInternalSDK ? "watchos.internal" : "watchos";
+        $xcodeSDK ||=  "watchos";
     }
     if (checkForArgumentAndRemoveFromARGV("--watchos-simulator")) {
         $xcodeSDK ||= "watchsimulator";
     }
+    return if !defined $xcodeSDK;
+    
+    # Prefer the internal version of an sdk, if it exists.
+    my @availableSDKs = availableXcodeSDKs();
+
+    foreach my $sdk (@availableSDKs) {
+        next if $sdk ne "$xcodeSDK.internal";
+        $xcodeSDK = $sdk;
+        last;
+    }
 }
 
 sub xcodeSDK

Added: trunk/Tools/Scripts/webkitperl/webkitdirs_unittest/availableXcodeSDKS.pl (0 => 232583)


--- trunk/Tools/Scripts/webkitperl/webkitdirs_unittest/availableXcodeSDKS.pl	                        (rev 0)
+++ trunk/Tools/Scripts/webkitperl/webkitdirs_unittest/availableXcodeSDKS.pl	2018-06-07 16:24:49 UTC (rev 232583)
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2018 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.
+
+# Unit tests for webkitdirs::parseAvailableXcodeSDKs($).
+
+use strict;
+use warnings;
+
+use Config;
+use Test::More;
+use webkitdirs;
+
+plan(tests => 2);
+
+my @fullXcodebuildOutput = <<END =~ m/(^.*\n)/mg;
+iOS SDKs:
+iOS 12.0                          -sdk iphoneos12.0
+iOS 12.0 Internal                 -sdk iphoneos12.0.internal
+
+iOS Simulator SDKs:
+Simulator - iOS 12.0 Internal     -sdk iphonesimulator12.0
+
+macOS SDKs:
+macOS 10.14                       -sdk macosx10.14
+macOS 10.14 Internal              -sdk macosx10.14internal
+
+END
+
+my @result = parseAvailableXcodeSDKs(\@fullXcodebuildOutput);
+my @expectedResult = ("iphoneos", "iphoneos.internal", "iphonesimulator", "macosx", "macosx.internal");
+is_deeply(\@result, \@expectedResult, "parseAvailableXcodeSDKs: Full xcodebuild output");
+
+my @closeMatchOutput = <<END =~ m/(^.*\n)/mg;
+Non-matching SDKs:
+watchOS 5.0                       -SDK watchos5.0
+tvOS 12.0                         -sdk appletvos
+iOS 12.0                          -SDK iphoneos12.0.internal.4
+
+END
+
+my @emptyList = ();
+@result = parseAvailableXcodeSDKs(\@closeMatchOutput);
+is_deeply(\@result, \@emptyList, "parseAvailableXcodeSDKs: Near matches");
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to