Skip to content

Commit

Permalink
Expand "Make" variables inside of values in the env dictionary on tes…
Browse files Browse the repository at this point in the history
…t rules (#2476)
  • Loading branch information
aaronsky committed Jun 25, 2024
1 parent 85377d7 commit 3c4111a
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 12 deletions.
3 changes: 2 additions & 1 deletion apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ _COMMON_TEST_ATTRS = {
),
"env": attr.string_dict(
doc = """
Dictionary of environment variables that should be set during the test execution.
Dictionary of environment variables that should be set during the test execution. The values of
the dictionary are subject to "Make" variable expansion.
""",
),
"runner": attr.label(
Expand Down
9 changes: 8 additions & 1 deletion apple/internal/testing/apple_test_rule_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ def _apple_test_rule_impl(*, ctx, requires_dossiers, test_type):
runner_info = runner_attr[AppleTestRunnerInfo]
execution_requirements = getattr(runner_info, "execution_requirements", {})

# ctx.expand_make_variables is marked deprecated in the docs but every ruleset uses it. Not
# sure how they're planning on getting rid of it for good.
rule_test_env = {
k: ctx.expand_make_variables("env", v, {})
for k, v in ctx.attr.env.items()
}

test_bundle_target = ctx.attr.deps[0]
test_bundle = test_bundle_target[AppleTestInfo].test_bundle

Expand All @@ -286,7 +293,7 @@ def _apple_test_rule_impl(*, ctx, requires_dossiers, test_type):
test_environment = _get_simulator_test_environment(
command_line_test_env = ctx.configuration.test_env,
features = ctx.features,
rule_test_env = ctx.attr.env,
rule_test_env = rule_test_env,
runner_test_env = getattr(runner_info, "test_environment", {}),
)

Expand Down
4 changes: 2 additions & 2 deletions doc/rules-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ of the attributes inherited by all test rules, please check the
| <a id="ios_ui_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="ios_ui_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="ios_ui_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="ios_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="ios_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="ios_ui_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="ios_ui_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="ios_ui_test-platform_type"></a>platform_type | - | String | optional | `"ios"` |
Expand Down Expand Up @@ -643,7 +643,7 @@ of the attributes inherited by all test rules, please check the
| <a id="ios_unit_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="ios_unit_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="ios_unit_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="ios_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="ios_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="ios_unit_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="ios_unit_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="ios_unit_test-platform_type"></a>platform_type | - | String | optional | `"ios"` |
Expand Down
4 changes: 2 additions & 2 deletions doc/rules-macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ Note: macOS UI tests are not currently supported in the default test runner.
| <a id="macos_ui_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="macos_ui_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="macos_ui_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="macos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="macos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="macos_ui_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="macos_ui_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="macos_ui_test-platform_type"></a>platform_type | - | String | optional | `"macos"` |
Expand Down Expand Up @@ -681,7 +681,7 @@ find more information about testing for Apple platforms
| <a id="macos_unit_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="macos_unit_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="macos_unit_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="macos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="macos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="macos_unit_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="macos_unit_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="macos_unit_test-platform_type"></a>platform_type | - | String | optional | `"macos"` |
Expand Down
4 changes: 2 additions & 2 deletions doc/rules-tvos.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ the attributes inherited by all test rules, please check the
| <a id="tvos_ui_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="tvos_ui_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="tvos_ui_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="tvos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="tvos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="tvos_ui_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="tvos_ui_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="tvos_ui_test-platform_type"></a>platform_type | - | String | optional | `"tvos"` |
Expand Down Expand Up @@ -399,7 +399,7 @@ of the attributes inherited by all test rules, please check the
| <a id="tvos_unit_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="tvos_unit_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="tvos_unit_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="tvos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="tvos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="tvos_unit_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="tvos_unit_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="tvos_unit_test-platform_type"></a>platform_type | - | String | optional | `"tvos"` |
Expand Down
4 changes: 2 additions & 2 deletions doc/rules-visionos.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ the attributes inherited by all test rules, please check the
| <a id="visionos_ui_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="visionos_ui_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="visionos_ui_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="visionos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="visionos_ui_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="visionos_ui_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="visionos_ui_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="visionos_ui_test-platform_type"></a>platform_type | - | String | optional | `"visionos"` |
Expand Down Expand Up @@ -347,7 +347,7 @@ of the attributes inherited by all test rules, please check the
| <a id="visionos_unit_test-deps"></a>deps | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="visionos_unit_test-data"></a>data | Files to be made available to the test during its execution. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="visionos_unit_test-bundle_name"></a>bundle_name | The desired name of the bundle (without the extension). If this attribute is not set, then the name of the target will be used instead. | String | optional | `""` |
| <a id="visionos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="visionos_unit_test-env"></a>env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="visionos_unit_test-minimum_deployment_os_version"></a>minimum_deployment_os_version | A required string indicating the minimum deployment OS version supported by the target, represented as a dotted version number (for example, "9.0"). This is different from `minimum_os_version`, which is effective at compile time. Ensure version specific APIs are guarded with `available` clauses. | String | optional | `""` |
| <a id="visionos_unit_test-minimum_os_version"></a>minimum_os_version | A required string indicating the minimum OS version supported by the target, represented as a dotted version number (for example, "9.0"). | String | required | |
| <a id="visionos_unit_test-platform_type"></a>platform_type | - | String | optional | `"visionos"` |
Expand Down
Loading

0 comments on commit 3c4111a

Please sign in to comment.