aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2016-06-03 16:40:09 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-06-06 08:02:06 +0000
commit6d07acbfb9a45e58d9f2dcc95758cb9add1ad2b5 (patch)
treede901eba80169186e1e57c80b47b5ca2aebd3c6a /src
parentbba483fe11cfd3f05e88caec8e7263dba33e2358 (diff)
Add @loader_path to -rpath for xctest targets.
This fixes test timeouts when the app tested is using Swift. In theory this also prevents similar problems with any code that uses dynamic libs packaged in the IPA. -- MOS_MIGRATED_REVID=123976581
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java5
-rwxr-xr-xsrc/test/shell/bazel/bazel_apple_test.sh49
2 files changed, 53 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
index b4e7c855bb..7c49f81c0e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
@@ -133,9 +133,12 @@ public final class IosTest implements RuleConfiguredTargetFactory {
// -bundle_loader causes the code in this test to have access to the symbols in the test rig,
// or more specifically, the flag causes ld to consider the given binary when checking for
// missing symbols.
+ // -rpath @loader_path/Frameworks allows test bundles to load dylibs from the app's
+ // Frameworks directory.
extraLinkArgs = new ExtraLinkArgs(
"-bundle",
- "-bundle_loader", bundleLoader.getExecPathString());
+ "-bundle_loader", bundleLoader.getExecPathString(),
+ "-Xlinker", "-rpath", "-Xlinker", "@loader_path/Frameworks");
extraLinkInputs = ImmutableList.of(bundleLoader);
bundleFormat = ReleaseBundlingSupport.XCTEST_BUNDLE_DIR_FORMAT;
diff --git a/src/test/shell/bazel/bazel_apple_test.sh b/src/test/shell/bazel/bazel_apple_test.sh
index 9f9be2eafb..e2b8d92f36 100755
--- a/src/test/shell/bazel/bazel_apple_test.sh
+++ b/src/test/shell/bazel/bazel_apple_test.sh
@@ -370,4 +370,53 @@ EOF
//ios:swift_lib >$TEST_log 2>&1 || fail "should build"
}
+function test_swift_tests() {
+ make_app
+
+ cat >ios/tests.swift <<EOF
+ import XCTest
+
+class FooTest: XCTestCase {
+ func testFoo() { XCTAssertEqual(2, 3) }
+}
+EOF
+
+ cat >ios/BUILD <<EOF
+load("//tools/build_defs/apple:swift.bzl", "swift_library")
+
+swift_library(name = "SwiftMain",
+ srcs = ["app.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 = ['dummy.swift'],
+ deps = [":SwiftMain"])
+
+ios_application(name = "app",
+ binary = ':bin',
+ infoplist = 'App-Info.plist')
+
+swift_library(name = "SwiftTest",
+ srcs = ["tests.swift"])
+
+ios_test(name = "app_test",
+ srcs = ['dummy.swift'],
+ deps = [":SwiftTest"],
+ xctest_app = "app")
+EOF
+
+ bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \
+ //ios:app_test >$TEST_log 2>&1 || fail "should build"
+
+ otool -lv bazel-bin/ios/app_test_bin \
+ | grep @executable_path/Frameworks -sq \
+ || fail "expected test binary to contain @executable_path in LC_RPATH"
+
+ otool -lv bazel-bin/ios/app_test_bin \
+ | grep @loader_path/Frameworks -sq \
+ || fail "expected test binary to contain @executable_path in LC_RPATH"
+
+}
+
run_suite "apple_tests"