Skip to content

Commit

Permalink
Expose a new AppleDeviceTestRunnerInfo provider from device-based t…
Browse files Browse the repository at this point in the history
…est runners

This allows downstream rules and aspects to know what device type and OS version was selected.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones committed Nov 7, 2024
1 parent 45db53e commit f2cc7a5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
16 changes: 16 additions & 0 deletions apple/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ target.
},
)

AppleDeviceTestRunnerInfo = provider(
doc = """
Provider that device-based runner targets must propagate.
""",
fields = {
"device_type": """
The device type of the iOS simulator to run test. The supported types correspond
to the output of `xcrun simctl list devicetypes`. E.g., iPhone X, iPad Air.
""",
"os_version": """
The os version of the iOS simulator to run test. The supported os versions
correspond to the output of `xcrun simctl list runtimes`. E.g., 15.5.
""",
},
)

AppleProvisioningProfileInfo = provider(
doc = "Provides information about a provisioning profile.",
fields = {
Expand Down
7 changes: 6 additions & 1 deletion apple/testing/default_runner/ios_test_runner.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleDeviceTestRunnerInfo",
"apple_provider",
)

Expand Down Expand Up @@ -56,12 +57,16 @@ def _ios_test_runner_impl(ctx):
)
return [
apple_provider.make_apple_test_runner_info(
test_runner_template = ctx.outputs.test_runner_template,
execution_requirements = ctx.attr.execution_requirements,
execution_environment = _get_execution_environment(
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
),
test_environment = ctx.attr.test_environment,
test_runner_template = ctx.outputs.test_runner_template,
),
AppleDeviceTestRunnerInfo(
device_type = device_type,
os_version = os_version,
),
DefaultInfo(
runfiles = ctx.attr._simulator_creator[DefaultInfo].default_runfiles
Expand Down
7 changes: 6 additions & 1 deletion apple/testing/default_runner/ios_xctestrun_runner.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ simulators. This rule currently doesn't support UI tests or running on device.

load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleDeviceTestRunnerInfo",
"apple_provider",
)

Expand Down Expand Up @@ -81,6 +82,10 @@ def _ios_xctestrun_runner_impl(ctx):
execution_requirements = {"requires-darwin": ""},
test_runner_template = ctx.outputs.test_runner_template,
),
AppleDeviceTestRunnerInfo(
device_type = device_type,
os_version = os_version,
),
DefaultInfo(
runfiles = ctx.runfiles(
files = [
Expand Down Expand Up @@ -141,7 +146,7 @@ will always use `xcodebuild test-without-building` to run the test bundle.
default = "keepNever",
doc = """
Attachment lifetime to set in the xctestrun file when running the test bundle - `"keepNever"` (default), `"keepAlways"`
or `"deleteOnSuccess"`. This affects presence of attachments in the XCResult output. This does not force using
or `"deleteOnSuccess"`. This affects presence of attachments in the XCResult output. This does not force using
`xcodebuild` or an XCTestRun file but the value will be used in that case.
""",
),
Expand Down
12 changes: 10 additions & 2 deletions apple/testing/default_runner/tvos_test_runner.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleDeviceTestRunnerInfo",
"apple_provider",
)

Expand All @@ -39,12 +40,15 @@ def _get_execution_environment(*, xcode_config):

def _tvos_test_runner_impl(ctx):
"""Implementation for the tvos_test_runner rule."""
device_type = ctx.attr.device_type
os_version = ctx.attr.os_version

ctx.actions.expand_template(
template = ctx.file._test_template,
output = ctx.outputs.test_runner_template,
substitutions = _get_template_substitutions(
device_type = ctx.attr.device_type,
os_version = ctx.attr.os_version,
device_type = device_type,
os_version = os_version,
testrunner = ctx.executable._testrunner.short_path,
),
)
Expand All @@ -56,6 +60,10 @@ def _tvos_test_runner_impl(ctx):
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
),
),
AppleDeviceTestRunnerInfo(
device_type = device_type,
os_version = os_version,
),
DefaultInfo(
runfiles = ctx.attr._testrunner[DefaultInfo].default_runfiles,
),
Expand Down
12 changes: 10 additions & 2 deletions apple/testing/default_runner/visionos_test_runner.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleDeviceTestRunnerInfo",
"apple_provider",
)

Expand All @@ -39,12 +40,15 @@ def _get_execution_environment(*, xcode_config):

def _visionos_test_runner_impl(ctx):
"""Implementation for the visionos_test_runner rule."""
device_type = ctx.attr.device_type
os_version = ctx.attr.os_version

ctx.actions.expand_template(
template = ctx.file._test_template,
output = ctx.outputs.test_runner_template,
substitutions = _get_template_substitutions(
device_type = ctx.attr.device_type,
os_version = ctx.attr.os_version,
device_type = device_type,
os_version = os_version,
testrunner = ctx.executable._testrunner.short_path,
),
)
Expand All @@ -56,6 +60,10 @@ def _visionos_test_runner_impl(ctx):
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
),
),
AppleDeviceTestRunnerInfo(
device_type = device_type,
os_version = os_version,
),
DefaultInfo(
runfiles = ctx.attr._testrunner[DefaultInfo].default_runfiles,
),
Expand Down
12 changes: 10 additions & 2 deletions apple/testing/default_runner/watchos_test_runner.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleDeviceTestRunnerInfo",
"apple_provider",
)

Expand All @@ -39,12 +40,15 @@ def _get_execution_environment(*, xcode_config):

def _watchos_test_runner_impl(ctx):
"""Implementation for the watchos_test_runner rule."""
device_type = ctx.attr.device_type
os_version = ctx.attr.os_version

ctx.actions.expand_template(
template = ctx.file._test_template,
output = ctx.outputs.test_runner_template,
substitutions = _get_template_substitutions(
device_type = ctx.attr.device_type,
os_version = ctx.attr.os_version,
device_type = device_type,
os_version = os_version,
testrunner = ctx.executable._testrunner.short_path,
),
)
Expand All @@ -56,6 +60,10 @@ def _watchos_test_runner_impl(ctx):
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
),
),
AppleDeviceTestRunnerInfo(
device_type = device_type,
os_version = os_version,
),
DefaultInfo(
runfiles = ctx.attr._testrunner[DefaultInfo].default_runfiles,
),
Expand Down

0 comments on commit f2cc7a5

Please sign in to comment.