Skip to content

Commit

Permalink
Pass -enable-testing when compiling the sources in a swift_test i…
Browse files Browse the repository at this point in the history
…n discovery mode

When doing manual discovery, this allows the generated sources to `@testable import` that module even when building with `-c opt`.

PiperOrigin-RevId: 471809177
(cherry picked from commit 82f828b)
Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
allevato authored and brentleyjones committed Jun 24, 2024
1 parent da3f04a commit de3dc52
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions swift/swift_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,13 @@ def _swift_test_impl(ctx):
# In test discovery mode (whether manual or by the Obj-C runtime),
# compile the code with `-parse-as-library` to avoid the case where
# a single file with no top-level code still produces an empty
# `main`.
additional_copts = ["-parse-as-library"] if discover_tests else _maybe_parse_as_library_copts(srcs),
# `main`. Also compile with `-enable-testing`, because the generated
# sources will `@testable import` this module, and this allows that
# to work even when building in `-c opt` mode.
additional_copts = [
"-parse-as-library",
"-enable-testing",
] if discover_tests else _maybe_parse_as_library_copts(srcs),
cc_infos = deps_cc_infos,
feature_configuration = feature_configuration,
include_dev_srch_paths = include_dev_srch_paths,
Expand Down

0 comments on commit de3dc52

Please sign in to comment.