diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl
index 0f404667fd..c3294e9cb9 100644
--- a/apple/internal/rule_factory.bzl
+++ b/apple/internal/rule_factory.bzl
@@ -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(
diff --git a/apple/internal/testing/apple_test_rule_support.bzl b/apple/internal/testing/apple_test_rule_support.bzl
index b27f934988..2f3200283f 100644
--- a/apple/internal/testing/apple_test_rule_support.bzl
+++ b/apple/internal/testing/apple_test_rule_support.bzl
@@ -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
@@ -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", {}),
)
diff --git a/doc/rules-ios.md b/doc/rules-ios.md
index 67534bfe1f..b9fd0ff770 100644
--- a/doc/rules-ios.md
+++ b/doc/rules-ios.md
@@ -591,7 +591,7 @@ of the attributes inherited by all test rules, please check the
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"ios"` |
@@ -643,7 +643,7 @@ of the attributes inherited by all test rules, please check the
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"ios"` |
diff --git a/doc/rules-macos.md b/doc/rules-macos.md
index 7d6484aae2..fc6cd72ecf 100644
--- a/doc/rules-macos.md
+++ b/doc/rules-macos.md
@@ -638,7 +638,7 @@ Note: macOS UI tests are not currently supported in the default test runner.
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"macos"` |
@@ -681,7 +681,7 @@ find more information about testing for Apple platforms
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"macos"` |
diff --git a/doc/rules-tvos.md b/doc/rules-tvos.md
index 0d8936c921..c347b3495c 100644
--- a/doc/rules-tvos.md
+++ b/doc/rules-tvos.md
@@ -350,7 +350,7 @@ the attributes inherited by all test rules, please check the
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"tvos"` |
@@ -399,7 +399,7 @@ of the attributes inherited by all test rules, please check the
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"tvos"` |
diff --git a/doc/rules-visionos.md b/doc/rules-visionos.md
index 87e232d2ce..6000403a61 100755
--- a/doc/rules-visionos.md
+++ b/doc/rules-visionos.md
@@ -298,7 +298,7 @@ the attributes inherited by all test rules, please check the
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"visionos"` |
@@ -347,7 +347,7 @@ of the attributes inherited by all test rules, please check the
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"visionos"` |
diff --git a/doc/rules-watchos.md b/doc/rules-watchos.md
index 20470e2cbc..80e315ff82 100644
--- a/doc/rules-watchos.md
+++ b/doc/rules-watchos.md
@@ -308,7 +308,7 @@ watchOS UI Test rule.
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"watchos"` |
@@ -340,7 +340,7 @@ watchOS Unit Test rule.
| deps | - | List of labels | required | |
| data | Files to be made available to the test during its execution. | List of labels | optional | `[]` |
| 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 | `""` |
-| env | Dictionary of environment variables that should be set during the test execution. | Dictionary: String -> String | optional | `{}` |
+| env | Dictionary of environment variables that should be set during the test execution. The values of the dictionary are subject to "Make" variable expansion. | Dictionary: String -> String | optional | `{}` |
| 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 | `""` |
| 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 | |
| platform_type | - | String | optional | `"watchos"` |
diff --git a/test/ios_test_runner_unit_test.sh b/test/ios_test_runner_unit_test.sh
index 39bb01e15c..7685d8958b 100755
--- a/test/ios_test_runner_unit_test.sh
+++ b/test/ios_test_runner_unit_test.sh
@@ -323,6 +323,79 @@ ios_unit_test(
EOF
}
+function create_ios_unit_make_var_test() {
+ if [[ ! -f ios/BUILD ]]; then
+ fail "create_sim_runners must be called first."
+ fi
+
+ cat > ios/make_var_unit_test.m <
+#include
+#include
+
+@interface MakeVarUnitTest : XCTestCase
+
+@end
+
+@implementation MakeVarUnitTest
+
+- (void)testMakeVar {
+ XCTAssertEqualObjects([NSProcessInfo processInfo].environment[@"MY_MAKE_VAR"], @"$1", @"should pass");
+}
+
+@end
+EOF
+
+ cat >ios/MakeVarUnitTest-Info.plist <
+
+ CFBundleExecutable
+ MakeVarUnitTest
+
+
+EOF
+
+ cat >> ios/BUILD < ios/make_var_unit_test.m <
+#include
+#include
+
+@interface MakeVarUnitTest : XCTestCase
+
+@end
+
+@implementation MakeVarUnitTest
+
+- (void)testMakeVar {
+ XCTAssertEqualObjects([NSProcessInfo processInfo].environment[@"MY_MAKE_VAR"], @"$1", @"should pass");
+}
+
+@end
+EOF
+
+ cat >ios/MakeVarUnitTest-Info.plist <
+
+ CFBundleExecutable
+ MakeVarUnitTest
+
+
+EOF
+
+ cat >> ios/BUILD <