Skip to content

Commit

Permalink
Add test host app transition marker
Browse files Browse the repository at this point in the history
Summary:
If `embed_xctest_frameworks_in_test_host_app` is set on an `apple_test()`, the `config//marker/apple/constraints:embed_xctest_frameworks_enabled` constraint is then added to the `test_host_app` via a transition.

This constraint is then used in `apple_bundle()` to embed XCTest frameworks.

Reviewed By: manicaesar

Differential Revision: D62936576

fbshipit-source-id: 62f95834503eee2dfac8ec71286b0f54c4dd5293
  • Loading branch information
milend authored and facebook-github-bot committed Sep 19, 2024
1 parent c0597e2 commit e6c9982
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
38 changes: 38 additions & 0 deletions apple/apple_test_host_app_transition.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

def _apple_test_host_app_transition_impl(platform: PlatformInfo, refs: struct, attrs: struct) -> PlatformInfo:
if not attrs.embed_xctest_frameworks_in_test_host_app:
return platform

updated_constraints = dict(platform.configuration.constraints)

test_host_marker_setting_label = refs.embed_xctest_frameworks_constraint_setting[ConstraintSettingInfo].label
if test_host_marker_setting_label in updated_constraints:
return platform

test_host_marker_value_info = refs.embed_xctest_frameworks_marker_constraint_value[ConstraintValueInfo]
updated_constraints[test_host_marker_setting_label] = test_host_marker_value_info

return PlatformInfo(
label = platform.label + "-test-host-app",
configuration = ConfigurationInfo(
constraints = updated_constraints,
values = platform.configuration.values,
),
)

apple_test_host_app_transition = transition(
impl = _apple_test_host_app_transition_impl,
refs = {
"embed_xctest_frameworks_constraint_setting": "config//marker/apple/constraints:embed_xctest_frameworks",
"embed_xctest_frameworks_marker_constraint_value": "config//marker/apple/constraints:embed_xctest_frameworks_enabled",
},
attrs = [
"embed_xctest_frameworks_in_test_host_app",
],
)
6 changes: 5 additions & 1 deletion decls/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

load("@prelude//apple:apple_common.bzl", "apple_common")
load("@prelude//apple:apple_rules_impl_utility.bzl", "apple_dsymutil_attrs", "get_apple_toolchain_attr")
load("@prelude//apple:apple_test_host_app_transition.bzl", "apple_test_host_app_transition")
load("@prelude//apple:apple_toolchain_types.bzl", "AppleToolsInfo")
load("@prelude//apple:apple_universal_executable.bzl", "apple_universal_executable_impl")
load("@prelude//apple:cxx_universal_executable.bzl", "cxx_universal_executable_impl")
Expand Down Expand Up @@ -673,7 +674,7 @@ apple_test = prelude_rule(
apple_common.info_plist_arg() |
apple_common.info_plist_substitutions_arg() |
{
"test_host_app": attrs.option(attrs.dep(), default = None, doc = """
"test_host_app": attrs.option(attrs.transition_dep(cfg = apple_test_host_app_transition), default = None, doc = """
A build target identifying
an `apple_bundle()` rule that builds an
application bundle. Output of the specified rule will be used as a test host of this test. This
Expand All @@ -684,6 +685,9 @@ apple_test = prelude_rule(
reference errors during compilation, but if the symbols do not exist, it might result in runtime
crashes).
"""),
"embed_xctest_frameworks_in_test_host_app": attrs.option(attrs.bool(), default = None, doc = """
Controls whether a marker constraint is added to the `test_host_app`.
"""),
} |
cxx_common.srcs_arg() |
cxx_common.platform_srcs_arg() |
Expand Down

0 comments on commit e6c9982

Please sign in to comment.