summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjustincohen@chromium.org <justincohen@chromium.org>2014-09-23 16:48:48 +0000
committerjustincohen@chromium.org <justincohen@chromium.org>2014-09-23 16:48:48 +0000
commitc5aaab5e438ba6ca40ec2137a46998b2a35915cb (patch)
treeaf9a9e4139b88737cff81e9079d8d447c11c04cd
parent0eedec84850c360288e00b90eae585ab4150a05b (diff)
downloadgyp-c5aaab5e438ba6ca40ec2137a46998b2a35915cb.tar.gz
Adds swift file support to xcode generation.
BUG= Patch from Josh Converse <jconverse@google.com>! R=justincohen@chromium.org, thomasvl@chromium.org Review URL: https://codereview.chromium.org/560683003 git-svn-id: http://gyp.googlecode.com/svn/trunk@1980 78cadc50-ecff-11dd-a971-7dbc132099af
-rw-r--r--pylib/gyp/generator/xcode.py2
-rw-r--r--pylib/gyp/xcodeproj_file.py1
-rw-r--r--test/mac/gyptest-swift-library.py62
-rw-r--r--test/mac/swift-library/Info.plist28
-rw-r--r--test/mac/swift-library/file.swift9
-rw-r--r--test/mac/swift-library/test.gyp21
6 files changed, 122 insertions, 1 deletions
diff --git a/pylib/gyp/generator/xcode.py b/pylib/gyp/generator/xcode.py
index b4d1e196..907e0480 100644
--- a/pylib/gyp/generator/xcode.py
+++ b/pylib/gyp/generator/xcode.py
@@ -486,7 +486,7 @@ sys.exit(subprocess.call(sys.argv[1:]))" """
def AddSourceToTarget(source, type, pbxp, xct):
# TODO(mark): Perhaps source_extensions and library_extensions can be made a
# little bit fancier.
- source_extensions = ['c', 'cc', 'cpp', 'cxx', 'm', 'mm', 's']
+ source_extensions = ['c', 'cc', 'cpp', 'cxx', 'm', 'mm', 's', 'swift']
# .o is conceptually more of a "source" than a "library," but Xcode thinks
# of "sources" as things to compile and "libraries" (or "frameworks") as
diff --git a/pylib/gyp/xcodeproj_file.py b/pylib/gyp/xcodeproj_file.py
index 7c7f1fbd..759fdd91 100644
--- a/pylib/gyp/xcodeproj_file.py
+++ b/pylib/gyp/xcodeproj_file.py
@@ -1508,6 +1508,7 @@ class PBXFileReference(XCFileLikeElement, XCContainerPortal, XCRemoteObject):
's': 'sourcecode.asm',
'storyboard': 'file.storyboard',
'strings': 'text.plist.strings',
+ 'swift': 'sourcecode.swift',
'ttf': 'file',
'xcassets': 'folder.assetcatalog',
'xcconfig': 'text.xcconfig',
diff --git a/test/mac/gyptest-swift-library.py b/test/mac/gyptest-swift-library.py
new file mode 100644
index 00000000..7db24c34
--- /dev/null
+++ b/test/mac/gyptest-swift-library.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2014 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Verifies that a swift framework builds correctly.
+"""
+
+import TestGyp
+import TestMac
+
+import collections
+import sys
+import subprocess
+
+if sys.platform == 'darwin':
+ test = TestGyp.TestGyp(formats=['xcode'])
+
+ # Ensures that the given symbol is present in the given file, by running nm.
+ def CheckHasSymbolName(path, symbol):
+ output = subprocess.check_output(['nm', '-j', path])
+ idx = output.find(symbol)
+ if idx == -1:
+ print 'Swift: Could not find symobl: %s' % symbol
+ test.fail_test()
+
+ test_cases = []
+
+ # Run this for iOS on XCode 6.0 or greater
+ if TestMac.Xcode.Version() >= '0600':
+ test_cases.append(('Default', 'iphoneos'))
+ test_cases.append(('Default', 'iphonesimulator'))
+
+ # Run it for Mac on XCode 6.1 or greater
+ if TestMac.Xcode.Version() >= '0610':
+ test_cases.append(('Default', None))
+
+ # Generate the project.
+ test.run_gyp('test.gyp', chdir='swift-library')
+
+ # Build and verify for each configuration.
+ for configuration, sdk in test_cases:
+ kwds = collections.defaultdict(list)
+ if test.format == 'xcode':
+ if sdk is not None:
+ kwds['arguments'].extend(['-sdk', sdk])
+
+ test.set_configuration(configuration)
+ test.build('test.gyp', 'SwiftFramework', chdir='swift-library', **kwds)
+
+ filename = 'SwiftFramework.framework/SwiftFramework'
+ result_file = test.built_file_path(filename, chdir='swift-library')
+
+ test.must_exist(result_file)
+
+ # Check to make sure that our swift class (GypSwiftTest) is present in the
+ # built binary
+ CheckHasSymbolName(result_file, "C14SwiftFramework12GypSwiftTest")
+
+ test.pass_test()
diff --git a/test/mac/swift-library/Info.plist b/test/mac/swift-library/Info.plist
new file mode 100644
index 00000000..804990ca
--- /dev/null
+++ b/test/mac/swift-library/Info.plist
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.${PRODUCT_NAME:identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
diff --git a/test/mac/swift-library/file.swift b/test/mac/swift-library/file.swift
new file mode 100644
index 00000000..88db7da5
--- /dev/null
+++ b/test/mac/swift-library/file.swift
@@ -0,0 +1,9 @@
+import Foundation
+
+public class GypSwiftTest {
+ let myProperty = false
+
+ init() {
+ self.myProperty = true
+ }
+} \ No newline at end of file
diff --git a/test/mac/swift-library/test.gyp b/test/mac/swift-library/test.gyp
new file mode 100644
index 00000000..373a677c
--- /dev/null
+++ b/test/mac/swift-library/test.gyp
@@ -0,0 +1,21 @@
+# Copyright (c) 2011 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+{
+ 'targets': [
+ {
+ 'target_name': 'SwiftFramework',
+ 'product_name': 'SwiftFramework',
+ 'type': 'shared_library',
+ 'mac_bundle': 1,
+ 'xcode_settings': {
+ 'INFOPLIST_FILE': 'Info.plist',
+ 'CODE_SIGNING_REQUIRED': 'NO',
+ 'CONFIGURATION_BUILD_DIR':'build/Default',
+ },
+ 'sources': [
+ 'file.swift',
+ ],
+ },
+ ],
+}