From de352e9e2eb03a662b10a27a2a230e1ec04d3275 Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Fri, 2 Sep 2022 08:35:53 -0700 Subject: [PATCH] Pass `-enable-testing` when compiling the sources in a `swift_test` in 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 82f828b983baecd0fa3ee14a6754eb71938895c0) Signed-off-by: Brentley Jones --- swift/swift_test.bzl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/swift/swift_test.bzl b/swift/swift_test.bzl index ba7fcd51b..0947af9e8 100644 --- a/swift/swift_test.bzl +++ b/swift/swift_test.bzl @@ -391,8 +391,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,