Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apple/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bzl_library(
"//apple/internal:apple_xcframework_import",
"//apple/internal:local_provisioning_profiles",
"//apple/internal:xcframework_rules",
"//apple/testing/default_runner:apple_xctestrun_runner",
"@bazel_features//:features",
"@rules_cc//cc:find_cc_toolchain_bzl",
"@rules_cc//cc/common",
Expand Down
5 changes: 5 additions & 0 deletions apple/apple.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ load(
_apple_static_xcframework = "apple_static_xcframework",
_apple_xcframework = "apple_xcframework",
)
load(
"//apple/testing/default_runner:apple_xctestrun_runner.bzl",
_apple_xctestrun_runner = "apple_xctestrun_runner",
)

apple_dynamic_framework_import = _apple_dynamic_framework_import
apple_dynamic_xcframework_import = _apple_dynamic_xcframework_import
Expand All @@ -51,6 +55,7 @@ apple_static_library = _apple_static_library
apple_static_xcframework = _apple_static_xcframework
apple_static_xcframework_import = _apple_static_xcframework_import
apple_universal_binary = _apple_universal_binary
apple_xctestrun_runner = _apple_xctestrun_runner
apple_xcframework = _apple_xcframework
local_provisioning_profile = _local_provisioning_profile
provisioning_profile_repository = _provisioning_profile_repository
Expand Down
1 change: 1 addition & 0 deletions apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ List of environment variables to inherit from the external environment.
""",
),
"runner": attr.label(
cfg = transition_support.apple_rule_transition,
doc = """
The runner target that will provide the logic on how to run the tests. Needs to provide the
AppleTestRunnerInfo provider.
Expand Down
8 changes: 8 additions & 0 deletions apple/internal/testing/apple_test_rule_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _get_template_substitutions(
test_host_bundle_name = "",
test_filter = None,
test_host_dossier = None,
test_minimum_os_version,
test_type):
"""Dictionary with the substitutions to be applied to the template script.

Expand All @@ -139,6 +140,7 @@ def _get_template_substitutions(
test_host_bundle_name: Optional. The bundle_name for the test host rule if one was assigned.
test_host_dossier: Optional. A File representing the dossier generated for the test host, if
one exists.
test_minimum_os_version: String. The minimum OS version from the test rule.
test_type: String. The test type received from the test rule implementation.

Returns:
Expand All @@ -155,6 +157,7 @@ def _get_template_substitutions(
"test_host_bundle_name": test_host_bundle_name,
"test_host_path": test_host_artifact.short_path if test_host_artifact else "",
"test_host_dossier_path": test_host_dossier.short_path if test_host_dossier else "",
"test_minimum_os_version": test_minimum_os_version,
"test_type": test_type.upper(),
}
return {"%(" + k + ")s": substitutions[k] for k in substitutions}
Expand Down Expand Up @@ -273,6 +276,10 @@ def _apple_test_rule_impl(*, ctx, requires_dossiers, test_type):
A full set of providers required to define an Apple test rule.
"""
runner_attr = ctx.attr.runner
if type(runner_attr) == "list":
if len(runner_attr) != 1:
fail("Expected exactly one configured test runner, got {}".format(len(runner_attr)))
runner_attr = runner_attr[0]
runner_info = runner_attr[AppleTestRunnerInfo]
execution_requirements = getattr(runner_info, "execution_requirements", {})

Expand Down Expand Up @@ -365,6 +372,7 @@ def _apple_test_rule_impl(*, ctx, requires_dossiers, test_type):
test_host_artifact = test_host_artifact,
test_host_bundle_name = test_host_bundle_name,
test_host_dossier = test_host_dossier,
test_minimum_os_version = ctx.attr.minimum_os_version,
test_type = test_type,
),
is_executable = True,
Expand Down
4 changes: 0 additions & 4 deletions apple/internal/testing/tvos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ tvos_ui_test = rule_factory.create_apple_test_rule(
Builds and bundles a tvOS UI `.xctest` test bundle. Runs the tests using the
provided test runner when invoked with `bazel test`.

Note: tvOS UI tests are not currently supported in the default test runner.

The following is a list of the `tvos_ui_test` specific attributes; for a list of
the attributes inherited by all test rules, please check the
[Bazel documentation](https://bazel.build/reference/be/common-definitions#common-attributes-tests).
Expand Down Expand Up @@ -244,8 +242,6 @@ tvos_unit_test = rule_factory.create_apple_test_rule(
Builds and bundles a tvOS Unit `.xctest` test bundle. Runs the tests using the
provided test runner when invoked with `bazel test`.

Note: tvOS unit tests are not currently supported in the default test runner.

`tvos_unit_test` targets can work in two modes: as app or library tests. If the
`test_host` attribute is set to an `tvos_application` target, the tests will run
within that application's context. If no `test_host` is provided, the tests will
Expand Down
4 changes: 0 additions & 4 deletions apple/internal/testing/visionos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ visionos_ui_test = rule_factory.create_apple_test_rule(
Builds and bundles a visionOS UI `.xctest` test bundle. Runs the tests using the
provided test runner when invoked with `bazel test`.

Note: visionOS UI tests are not currently supported in the default test runner.

The following is a list of the `visionos_ui_test` specific attributes; for a list of
the attributes inherited by all test rules, please check the
[Bazel documentation](https://bazel.build/reference/be/common-definitions#common-attributes-tests).
Expand Down Expand Up @@ -239,8 +237,6 @@ visionos_unit_test = rule_factory.create_apple_test_rule(
Builds and bundles a visionOS Unit `.xctest` test bundle. Runs the tests using the
provided test runner when invoked with `bazel test`.

Note: visionOS unit tests are not currently supported in the default test runner.

`visionos_unit_test` targets can work in two modes: as app or library tests. If the
`test_host` attribute is set to an `visionos_application` target, the tests will run
within that application's context. If no `test_host` is provided, the tests will
Expand Down
87 changes: 33 additions & 54 deletions apple/testing/default_runner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,23 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load(
"//apple/testing/default_runner:ios_test_runner.bzl",
"ios_test_runner",
)
load(
"//apple/testing/default_runner:ios_xctestrun_runner.bzl",
"ios_xctestrun_runner",
)
load(
"//apple/testing/default_runner:macos_test_runner.bzl",
"macos_test_runner",
"//apple/testing/default_runner:apple_xctestrun_runner.bzl",
"apple_xctestrun_runner",
)
load(
"//apple/testing/default_runner:tvos_test_runner.bzl",
"tvos_test_runner",
)
load(
"//apple/testing/default_runner:visionos_test_runner.bzl",
"visionos_test_runner",
)
load(
"//apple/testing/default_runner:watchos_test_runner.bzl",
"watchos_test_runner",
"//apple/testing/default_runner:ios_test_runner.bzl",
"ios_test_runner",
)

licenses(["notice"])

bzl_library(
name = "ios_test_runner",
srcs = ["ios_test_runner.bzl"],
name = "apple_xctestrun_runner",
srcs = ["apple_xctestrun_runner.bzl"],
visibility = ["//apple:__pkg__"],
deps = [
"//apple:providers",
"@apple_support//xcode:providers",
"@bazel_skylib//rules:common_settings",
],
)
Expand All @@ -42,6 +27,13 @@ bzl_library(
name = "ios_xctestrun_runner",
srcs = ["ios_xctestrun_runner.bzl"],
visibility = ["//apple:__pkg__"],
deps = [":apple_xctestrun_runner"],
)

bzl_library(
name = "ios_test_runner",
srcs = ["ios_test_runner.bzl"],
visibility = ["//apple:__pkg__"],
deps = [
"//apple:providers",
"@apple_support//xcode:providers",
Expand All @@ -52,45 +44,31 @@ bzl_library(
bzl_library(
name = "macos_test_runner",
srcs = ["macos_test_runner.bzl"],
deps = [
"//apple:providers",
"@apple_support//lib:xcode_support",
],
deps = [":apple_xctestrun_runner"],
)

bzl_library(
name = "tvos_test_runner",
srcs = ["tvos_test_runner.bzl"],
deps = [
"//apple:providers",
],
deps = [":apple_xctestrun_runner"],
)

bzl_library(
name = "visionos_test_runner",
srcs = ["visionos_test_runner.bzl"],
deps = [
"//apple:providers",
],
deps = [":apple_xctestrun_runner"],
)

bzl_library(
name = "watchos_test_runner",
srcs = ["watchos_test_runner.bzl"],
deps = [
"//apple:providers",
],
deps = [":apple_xctestrun_runner"],
)

exports_files([
"apple_xctestrun_runner.template.sh",
"apple_xctestrun_runner.template.xctestrun",
"ios_test_runner.template.sh",
"ios_xctestrun_runner.template.sh",
"ios_xctestrun_runner.template.xctestrun",
"macos_test_runner.template.sh",
"macos_test_runner.template.xctestrun",
"tvos_test_runner.template.sh",
"visionos_test_runner.template.sh",
"watchos_test_runner.template.sh",
"xctrunner_entitlements.template.plist",
])

Expand All @@ -111,56 +89,57 @@ sh_binary(
visibility = ["//visibility:public"],
)

ios_test_runner(
name = "ios_legacy_runner",
visibility = ["//visibility:public"],
)

ios_xctestrun_runner(
apple_xctestrun_runner(
name = "ios_default_runner",
# Used by the rule implementations, so it needs to be public; but
# should be considered an implementation detail of the rules and
# not used by other things.
visibility = ["//visibility:public"],
)

ios_xctestrun_runner(
ios_test_runner(
name = "ios_legacy_runner",
deprecation = "ios_legacy_runner is deprecated. Use ios_default_runner or a custom apple_xctestrun_runner instead.",
visibility = ["//visibility:public"],
)

apple_xctestrun_runner(
name = "ios_xctestrun_random_runner",
random = True,
visibility = ["//visibility:public"],
)

ios_xctestrun_runner(
apple_xctestrun_runner(
name = "ios_xctestrun_ordered_runner",
random = False,
visibility = ["//visibility:public"],
)

macos_test_runner(
apple_xctestrun_runner(
name = "macos_default_runner",
# Used by the rule implementations, so it needs to be public; but
# should be considered an implementation detail of the rules and
# not used by other things.
visibility = ["//visibility:public"],
)

tvos_test_runner(
apple_xctestrun_runner(
name = "tvos_default_runner",
# Used by the rule implementations, so it needs to be public; but
# should be considered an implementation detail of the rules and
# not used by other things.
visibility = ["//visibility:public"],
)

visionos_test_runner(
apple_xctestrun_runner(
name = "visionos_default_runner",
# Used by the rule implementations, so it needs to be public; but
# should be considered an implementation detail of the rules and
# not used by other things.
visibility = ["//visibility:public"],
)

watchos_test_runner(
apple_xctestrun_runner(
name = "watchos_default_runner",
# Used by the rule implementations, so it needs to be public; but
# should be considered an implementation detail of the rules and
Expand Down
Loading