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
  • Loading branch information
allevato authored and swiple-rules-gardener committed Sep 2, 2022
1 parent 585e7a7 commit 5da9abd
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 @@ -282,8 +282,14 @@ def _swift_test_impl(ctx):
output_groups = {}
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)

compilation_contexts = get_compilation_contexts(all_deps)
swift_infos = get_providers(all_deps, SwiftInfo)
Expand Down

1 comment on commit 5da9abd

@brentleyjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.