aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell/bazel/apple
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2016-11-05 16:02:18 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-07 09:53:05 +0000
commit349e478687a00e28f8a68a2b90e85de4b5c2eb02 (patch)
treed17cb70222a18edf42c9c71dc22d4163b563d92e /src/test/shell/bazel/apple
parent6e8e9c081ed9d0fbbc77b3da5248d49ca034e5e8 (diff)
Allow swiftc to correctly recognize main.swift as script target.
* This change removes forced -parse-as-library mode in favor of the driver figuring out how to parse each source. This means that main.swift will be parsed as a script and can contain top-level expressions. -- MOS_MIGRATED_REVID=138285669
Diffstat (limited to 'src/test/shell/bazel/apple')
-rwxr-xr-xsrc/test/shell/bazel/apple/bazel_apple_test.sh56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/test/shell/bazel/apple/bazel_apple_test.sh b/src/test/shell/bazel/apple/bazel_apple_test.sh
index 667e98e174..1f8f9ea485 100755
--- a/src/test/shell/bazel/apple/bazel_apple_test.sh
+++ b/src/test/shell/bazel/apple/bazel_apple_test.sh
@@ -222,7 +222,7 @@ function test_swift_import_objc_framework() {
# Copy the prebuilt framework into app's directory.
cp -RL "${BAZEL_RUNFILES}/tools/build_defs/apple/test/testdata/BlazeFramework.framework" ios
- cat >ios/main.swift <<EOF
+ cat >ios/app.swift <<EOF
import UIKit
import BlazeFramework
@@ -248,7 +248,7 @@ objc_binary(name = "bin",
deps = [":swift_lib"])
swift_library(name = "swift_lib",
- srcs = ["main.swift"],
+ srcs = ["app.swift"],
deps = [":dylib"])
objc_framework(name = "dylib",
@@ -752,4 +752,56 @@ EOF
expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/local-fastbuild/genfiles/ios/swift_lib/_objs/ios_swift_lib.swiftmodule"
}
+function test_swiftc_script_mode() {
+ rm -rf ios
+ mkdir -p ios
+ touch ios/foo.swift
+
+ cat >ios/top.swift <<EOF
+print() // Top level expression outside of main.swift, should fail.
+EOF
+
+ cat >ios/main.swift <<EOF
+import UIKit
+
+class AppDelegate: UIResponder, UIApplicationDelegate {}
+
+#if swift(>=3)
+UIApplicationMain(
+ CommandLine.argc,
+ UnsafeMutableRawPointer(CommandLine.unsafeArgv)
+ .bindMemory(
+ to: UnsafeMutablePointer<Int8>.self,
+ capacity: Int(CommandLine.argc)),
+ nil,
+ NSStringFromClass(AppDelegate.self)
+)
+#else
+UIApplicationMain(
+ Process.argc, UnsafeMutablePointer<UnsafeMutablePointer<CChar>>(Process.unsafeArgv),
+ nil, NSStringFromClass(AppDelegate)
+)
+#endif
+EOF
+
+cat >ios/BUILD <<EOF
+load("//tools/build_defs/apple:swift.bzl", "swift_library")
+
+swift_library(name = "main_should_compile_as_script",
+ srcs = ["main.swift", "foo.swift"])
+swift_library(name = "top_should_not_compile_as_script",
+ srcs = ["top.swift"])
+swift_library(name = "single_source_should_compile_as_library",
+ srcs = ["foo.swift"])
+EOF
+
+ bazel build --verbose_failures --xcode_version=$XCODE_VERSION \
+ //ios:single_source_should_compile_as_library \
+ //ios:main_should_compile_as_script >$TEST_log 2>&1 || fail "should build"
+
+ ! bazel build --verbose_failures --xcode_version=$XCODE_VERSION \
+ //ios:top_should_not_compile_as_script >$TEST_log 2>&1 || fail "should not build"
+ expect_log "ios/top.swift:1:1: error: expressions are not allowed at the top level"
+}
+
run_suite "apple_tests"