aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2016-05-16 19:59:50 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-05-17 16:14:37 +0000
commit892f12e69b3e81774206378dc4955b5e8c85397c (patch)
tree7ad3d39bb1c3fe2d597625e68c40dcd86c42da8d /src
parentb6c3ad611299056382d952368e4216bd7d87576a (diff)
Export Objective-C header from swift_library.
* Switches the rule to output to genfiles/, this makes C-headers it produces importable by depending targets. RELNOTES: swift_library now generates an Objective-C header for its @objc interfaces. -- MOS_MIGRATED_REVID=122448949
Diffstat (limited to 'src')
-rwxr-xr-xsrc/test/shell/bazel/bazel_apple_test.sh47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/test/shell/bazel/bazel_apple_test.sh b/src/test/shell/bazel/bazel_apple_test.sh
index b9466fd0a4..c17c5acd65 100755
--- a/src/test/shell/bazel/bazel_apple_test.sh
+++ b/src/test/shell/bazel/bazel_apple_test.sh
@@ -97,9 +97,9 @@ EOF
function test_swift_library() {
local swift_lib_pkg=examples/swift
- assert_build_output ./bazel-bin/${swift_lib_pkg}/swift_lib.a \
+ assert_build_output ./bazel-genfiles/${swift_lib_pkg}/swift_lib.a \
${swift_lib_pkg}:swift_lib --ios_sdk_version=$IOS_SDK_VERSION
- assert_build_output ./bazel-bin/${swift_lib_pkg}/swift_lib.swiftmodule \
+ assert_build_output ./bazel-genfiles/${swift_lib_pkg}/swift_lib.swiftmodule \
${swift_lib_pkg}:swift_lib --ios_sdk_version=$IOS_SDK_VERSION
}
@@ -111,4 +111,47 @@ function test_build_app() {
ls bazel-bin/ios/app.ipa || fail "should generate app.ipa"
}
+function test_objc_depends_on_swift() {
+ rm -rf ios
+ mkdir -p ios
+
+ touch ios/dummy.swift
+
+ cat >ios/main.swift <<EOF
+import Foundation
+
+@objc public class Foo: NSObject {
+ public func bar() -> Int { return 42; }
+}
+EOF
+
+ cat >ios/app.m <<EOF
+#import <UIKit/UIKit.h>
+#import "ios/SwiftMain-Swift.h"
+
+int main(int argc, char *argv[]) {
+ @autoreleasepool {
+ NSLog(@"%d", [[[Foo alloc] init] bar]);
+ return UIApplicationMain(argc, argv, nil, nil);
+ }
+}
+EOF
+
+ cat >ios/BUILD <<EOF
+load("//tools/build_defs/apple:swift.bzl", "swift_library")
+
+swift_library(name = "SwiftMain",
+ srcs = ["main.swift"])
+
+objc_binary(name = "bin",
+ # TODO(b/28723643): This dummy is only here to trigger the
+ # USES_SWIFT flag on ObjcProvider and should not be necessary.
+ srcs = ['app.m', 'dummy.swift'],
+ deps = [":SwiftMain"])
+EOF
+
+ bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \
+ //ios:bin >$TEST_log 2>&1 || fail "should build"
+}
+
run_suite "apple_tests"