configure-xcode-for-ios-development does not work with Xcode 7
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Sep 2015 00:21:39 +0000 (00:21 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Sep 2015 00:21:39 +0000 (00:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149640

Reviewed by Alexey Proskuryakov.

When Xcode 7 is installed, running configure-xcode-for-ios-development dies with an error
because it cannot find the Xcode specification files for iOS simulator and device. These
files have moved to a new location in Xcode 7 distribution. Moreover we must add the
relevant definitions to the Xcode 7 specification files directly as opposed to creating
new specification files with the added definitions (as we did in older versions of Xcode)
in order for Xcode 7 to honor these definitions.

* Scripts/configure-xcode-for-ios-development: Sorted forward declarations.
(updateXcodeSpecificationFilesForSDKIfNeeded): Added.
(updateXcode7SpecificationFile): Added.
(createLegacyXcodeSpecificationFilesForSDKIfNeeded): Formerly named createXcodeSpecificationFilesForSDKIfNeeded.
(writeXcodeSpecification): Moved congratulations line to caller so as to write out the
appropriate success message.
(mergeXcodeSpecificationWithSpecificationAndId): Formerly named createXcodeSpecificationFromSpecificationAndId.
(createXcodeSpecificationFilesForSDKIfNeeded): Deleted.
(createXcodeSpecificationFromSpecificationAndId): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190333 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/configure-xcode-for-ios-development

index f219050..22d075a 100644 (file)
@@ -1,3 +1,27 @@
+2015-09-29  Daniel Bates  <dabates@apple.com>
+
+        configure-xcode-for-ios-development does not work with Xcode 7
+        https://bugs.webkit.org/show_bug.cgi?id=149640
+
+        Reviewed by Alexey Proskuryakov.
+
+        When Xcode 7 is installed, running configure-xcode-for-ios-development dies with an error
+        because it cannot find the Xcode specification files for iOS simulator and device. These
+        files have moved to a new location in Xcode 7 distribution. Moreover we must add the
+        relevant definitions to the Xcode 7 specification files directly as opposed to creating
+        new specification files with the added definitions (as we did in older versions of Xcode)
+        in order for Xcode 7 to honor these definitions.
+
+        * Scripts/configure-xcode-for-ios-development: Sorted forward declarations.
+        (updateXcodeSpecificationFilesForSDKIfNeeded): Added.
+        (updateXcode7SpecificationFile): Added.
+        (createLegacyXcodeSpecificationFilesForSDKIfNeeded): Formerly named createXcodeSpecificationFilesForSDKIfNeeded.
+        (writeXcodeSpecification): Moved congratulations line to caller so as to write out the
+        appropriate success message.
+        (mergeXcodeSpecificationWithSpecificationAndId): Formerly named createXcodeSpecificationFromSpecificationAndId.
+        (createXcodeSpecificationFilesForSDKIfNeeded): Deleted.
+        (createXcodeSpecificationFromSpecificationAndId): Deleted.
+
 2015-09-29  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Allow 'prepare-ChangeLog' to be used without Cygwin
index 6c44756..487cf22 100755 (executable)
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 # Checks if Xcode supports building a command line tool for the iOS Simulator.
-# If not, then creates xcspec files in the iOS Simulator SDK for a command line
+# If not, then updates/creates xcspec files in the iOS SDK for a command line
 # tool product- and package- type using the definitions in the OS X SDK for the
 # same types.
 
 use strict;
 use warnings;
 
+use Cwd qw(realpath);
 use English;
 use File::Basename;
 use File::Find;
@@ -40,16 +41,19 @@ use lib $FindBin::Bin;
 use webkitdirs;
 
 sub copyMissingHeadersToIPhoneOSSDKIfNeeded();
-sub createXcodeSpecificationFilesForSDKIfNeeded($);
-sub createXcodeSpecificationFromSpecificationAndId($$$);
+sub createLegacyXcodeSpecificationFilesForSDKIfNeeded($);
+sub mergeXcodeSpecificationWithSpecificationAndId($$$);
+sub readXcodeSpecificationById($$);
 sub sdkDirectory($);
 sub sdkPlatformDirectory($);
-sub readXcodeSpecificationById($$);
+sub updateXcode7SpecificationFile($);
+sub updateXcodeSpecificationFilesForSDKIfNeeded($);
 sub xcodeSDKSpecificationsPath($);
 
 use constant COMMAND_LINE_PACKAGE_TYPE => "com.apple.package-type.mach-o-executable";
 use constant COMMAND_LINE_PRODUCT_TYPE => "com.apple.product-type.tool";
 use constant SDK_TO_XCSPEC_NAME_MAP => +{ "iphoneos" => "iPhoneOS", "iphonesimulator" => "iPhone Simulator " };
+use constant SDK_TO_PLUGIN_XCSPEC_NAME_MAP => +{ "iphoneos" => "Embedded-Device.xcspec", "iphonesimulator" => "Embedded-Simulator.xcspec" };
 
 # FIXME: We should only require running as root if needed. It's not necessary to run as root if
 #        Xcode was installed by the user, say via a download from <http://developer.apple.com>.
@@ -59,7 +63,7 @@ if ($EFFECTIVE_USER_ID) {
 }
 
 for my $sdk (qw(iphoneos iphonesimulator)) {
-    createXcodeSpecificationFilesForSDKIfNeeded($sdk);
+    updateXcodeSpecificationFilesForSDKIfNeeded($sdk);
 }
 
 copyMissingHeadersToIPhoneOSSDKIfNeeded();
@@ -96,7 +100,41 @@ sub copyMissingHeadersToIPhoneOSSDKIfNeeded()
     }
 }
 
-sub createXcodeSpecificationFilesForSDKIfNeeded($)
+sub updateXcodeSpecificationFilesForSDKIfNeeded($)
+{
+    my ($sdkName) = @_;
+    my $xcode7SpecificationFile = realpath(File::Spec->catfile(sdkPlatformDirectory($sdkName), "..", "..", "..", "PlugIns", "IDEiOSSupportCore.ideplugin", "Contents", "Resources", SDK_TO_PLUGIN_XCSPEC_NAME_MAP->{$sdkName}));
+    if (-f $xcode7SpecificationFile) {
+        updateXcode7SpecificationFile($xcode7SpecificationFile);
+    } else {
+        createLegacyXcodeSpecificationFilesForSDKIfNeeded($sdkName);
+    }
+}
+
+sub updateXcode7SpecificationFile($)
+{
+    my ($specificationFile) = @_;
+
+    my $hasPackageTypeForCommandLineTool = !!readXcodeSpecificationById($specificationFile, COMMAND_LINE_PACKAGE_TYPE);
+    my $hasProductTypeForCommandLineTool = !!readXcodeSpecificationById($specificationFile, COMMAND_LINE_PRODUCT_TYPE);
+    if ($hasPackageTypeForCommandLineTool && $hasProductTypeForCommandLineTool) {
+        return; # Xcode knows how to build a command line tool for $sdkName.
+    }
+
+    my $macosxSDKSpecificationsPath = xcodeSDKSpecificationsPath("macosx");
+    if (!$hasPackageTypeForCommandLineTool) {
+        my $packageTypesForMacOSXPath = File::Spec->catfile($macosxSDKSpecificationsPath, "MacOSX Package Types.xcspec");
+        mergeXcodeSpecificationWithSpecificationAndId($specificationFile, $packageTypesForMacOSXPath, COMMAND_LINE_PACKAGE_TYPE);
+    }
+
+    if (!$hasProductTypeForCommandLineTool) {
+        my $productTypesForMacOSXPath = File::Spec->catfile($macosxSDKSpecificationsPath, "MacOSX Product Types.xcspec");
+        mergeXcodeSpecificationWithSpecificationAndId($specificationFile, $productTypesForMacOSXPath, COMMAND_LINE_PRODUCT_TYPE);
+    }
+    print "Successfully updated '$specificationFile'.\n";
+}
+
+sub createLegacyXcodeSpecificationFilesForSDKIfNeeded($)
 {
     my ($sdk) = @_;
     my $sdkSpecificationsPath = xcodeSDKSpecificationsPath($sdk);
@@ -145,13 +183,15 @@ sub createXcodeSpecificationFilesForSDKIfNeeded($)
     if (!$hasPackageTypeForCommandLineTool) {
         my $packageTypesForMacOSXPath = File::Spec->catfile($macosxSDKSpecificationsPath, "MacOSX Package Types.xcspec");
         my $packageTypesForWebKitDevelopmentPath = File::Spec->catfile($sdkSpecificationsPath, "${fileNamePrefix}PackageTypes For WebKit Development.xcspec");
-        createXcodeSpecificationFromSpecificationAndId($packageTypesForWebKitDevelopmentPath, $packageTypesForMacOSXPath, COMMAND_LINE_PACKAGE_TYPE);
+        mergeXcodeSpecificationWithSpecificationAndId($packageTypesForWebKitDevelopmentPath, $packageTypesForMacOSXPath, COMMAND_LINE_PACKAGE_TYPE);
+        print "Successfully created '$packageTypesForWebKitDevelopmentPath'.\n";
     }
 
     if (!$hasProductTypeForCommandLineTool) {
         my $productTypesForMacOSXPath = File::Spec->catfile($macosxSDKSpecificationsPath, "MacOSX Product Types.xcspec");
         my $productTypesForWebKitDevelopmentPath = File::Spec->catfile($sdkSpecificationsPath, "${fileNamePrefix}ProductTypes For WebKit Development.xcspec");
-        createXcodeSpecificationFromSpecificationAndId($productTypesForWebKitDevelopmentPath, $productTypesForMacOSXPath, COMMAND_LINE_PRODUCT_TYPE);
+        mergeXcodeSpecificationWithSpecificationAndId($productTypesForWebKitDevelopmentPath, $productTypesForMacOSXPath, COMMAND_LINE_PRODUCT_TYPE);
+        print "Successfully created '$productTypesForWebKitDevelopmentPath'.\n";
     }
 }
 
@@ -177,7 +217,9 @@ sub writeXcodeSpecification($$)
     my ($tempFileHandle, $tempFilename) = tempfile("webkit-xcspecXXXXXXX", UNLINK => 1);
     print $tempFileHandle $specification;
     close($tempFileHandle);
-    system("/usr/libexec/PlistBuddy -x -c 'clear array' '$xcodeSpecificationFile' > /dev/null") == 0 or die "PlistBuddy exited with $?: $!";
+    if (!-f $xcodeSpecificationFile) {
+        system("/usr/libexec/PlistBuddy -x -c 'clear array' '$xcodeSpecificationFile' > /dev/null") == 0 or die "PlistBuddy exited with $?: $!";
+    }
     system("/usr/libexec/PlistBuddy -x -c 'add 0 dict' '$xcodeSpecificationFile' > /dev/null") == 0 or die "PlistBuddy exited with $?: $!";
     system("/usr/libexec/PlistBuddy -x -c 'merge $tempFilename 0' '$xcodeSpecificationFile' > /dev/null") == 0 or die "PlistBuddy exited with $?: $!";
 }
@@ -233,7 +275,7 @@ sub xcodeSDKSpecificationsPath($)
     return File::Spec->catdir(sdkPlatformDirectory($sdkName), "Developer", "Library", "Xcode", "Specifications");
 }
 
-sub createXcodeSpecificationFromSpecificationAndId($$$)
+sub mergeXcodeSpecificationWithSpecificationAndId($$$)
 {
     my ($targetXcodeSpecificationFile, $sourceXcodeSpecificationFile, $id) = @_;
     my $specification = readXcodeSpecificationById($sourceXcodeSpecificationFile, $id);
@@ -241,5 +283,4 @@ sub createXcodeSpecificationFromSpecificationAndId($$$)
         die "Failed to find '$id' in '$sourceXcodeSpecificationFile'.\n";
     }
     writeXcodeSpecification($targetXcodeSpecificationFile, $specification);
-    print "Successfully created '$targetXcodeSpecificationFile'.\n";
 }