Skip to content

Commit

Permalink
Only link in the Bazel test observer when discovering tests.
Browse files Browse the repository at this point in the history
Otherwise, the binary might link to XCTest when it otherwise isn't using it (strongly linking to `@rpath/libXCTestSwiftSupport.dylib`, which won't be found at runtime when not using the `xctest` launcher).

PiperOrigin-RevId: 471801873
(cherry picked from commit 5da9abd)
  • Loading branch information
allevato authored and brentleyjones committed Jun 24, 2024
1 parent e86e638 commit da3f04a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions swift/swift_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,14 @@ def _swift_test_impl(ctx):
srcs = ctx.files.srcs
owner_symbol_graph_dir = None

# Inject the test observer that prints the xUnit-style output for Bazel.
all_deps = ctx.attr.deps + [ctx.attr._test_observer]
all_deps = list(ctx.attr.deps)

# In test discovery mode (whether manual or by the Obj-C runtime), inject
# the test observer that prints the xUnit-style output for Bazel. Otherwise
# don't link this, because we don't want it to pull in link time
# dependencies on XCTest, which the test binary may not be using.
if discover_tests:
all_deps.append(ctx.attr._test_observer)

module_name = ctx.attr.module_name
if not module_name:
Expand Down

0 comments on commit da3f04a

Please sign in to comment.