diff --git a/apple/providers.bzl b/apple/providers.bzl index 6c787dea55..c74a916751 100644 --- a/apple/providers.bzl +++ b/apple/providers.bzl @@ -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 = { diff --git a/apple/testing/default_runner/ios_test_runner.bzl b/apple/testing/default_runner/ios_test_runner.bzl index 67adbf042b..0e80792e9d 100644 --- a/apple/testing/default_runner/ios_test_runner.bzl +++ b/apple/testing/default_runner/ios_test_runner.bzl @@ -16,6 +16,7 @@ load( "@build_bazel_rules_apple//apple:providers.bzl", + "AppleDeviceTestRunnerInfo", "apple_provider", ) @@ -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 diff --git a/apple/testing/default_runner/ios_xctestrun_runner.bzl b/apple/testing/default_runner/ios_xctestrun_runner.bzl index d4912b32c6..e1fedc45b1 100644 --- a/apple/testing/default_runner/ios_xctestrun_runner.bzl +++ b/apple/testing/default_runner/ios_xctestrun_runner.bzl @@ -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", ) @@ -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 = [ @@ -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. """, ), diff --git a/apple/testing/default_runner/tvos_test_runner.bzl b/apple/testing/default_runner/tvos_test_runner.bzl index 9759e19519..f80fe05508 100644 --- a/apple/testing/default_runner/tvos_test_runner.bzl +++ b/apple/testing/default_runner/tvos_test_runner.bzl @@ -16,6 +16,7 @@ load( "@build_bazel_rules_apple//apple:providers.bzl", + "AppleDeviceTestRunnerInfo", "apple_provider", ) @@ -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, ), ) @@ -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, ), diff --git a/apple/testing/default_runner/visionos_test_runner.bzl b/apple/testing/default_runner/visionos_test_runner.bzl index 0355bf9252..0475bcc950 100644 --- a/apple/testing/default_runner/visionos_test_runner.bzl +++ b/apple/testing/default_runner/visionos_test_runner.bzl @@ -16,6 +16,7 @@ load( "@build_bazel_rules_apple//apple:providers.bzl", + "AppleDeviceTestRunnerInfo", "apple_provider", ) @@ -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, ), ) @@ -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, ), diff --git a/apple/testing/default_runner/watchos_test_runner.bzl b/apple/testing/default_runner/watchos_test_runner.bzl index a216e2d64a..0405e8985b 100644 --- a/apple/testing/default_runner/watchos_test_runner.bzl +++ b/apple/testing/default_runner/watchos_test_runner.bzl @@ -16,6 +16,7 @@ load( "@build_bazel_rules_apple//apple:providers.bzl", + "AppleDeviceTestRunnerInfo", "apple_provider", ) @@ -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, ), ) @@ -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, ),