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 (#2581)

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 authored Nov 11, 2024
1 parent 1477ccf commit 35f9b94
Show file tree
Hide file tree
Showing 7 changed files with 77 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
19 changes: 19 additions & 0 deletions doc/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ Provides information around the use of a code signing dossier.
| <a id="AppleCodesigningDossierInfo-dossier"></a>dossier | A `File` reference to the code signing dossier zip that acts as a direct dependency of the given target if one was generated. |


<a id="AppleDeviceTestRunnerInfo"></a>

## AppleDeviceTestRunnerInfo

<pre>
AppleDeviceTestRunnerInfo(<a href="#AppleDeviceTestRunnerInfo-device_type">device_type</a>, <a href="#AppleDeviceTestRunnerInfo-os_version">os_version</a>)
</pre>

Provider that device-based runner targets must propagate.

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="AppleDeviceTestRunnerInfo-device_type"></a>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. |
| <a id="AppleDeviceTestRunnerInfo-os_version"></a>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. |


<a id="AppleDsymBundleInfo"></a>

## AppleDsymBundleInfo
Expand Down

0 comments on commit 35f9b94

Please sign in to comment.