From b6cc4df9ec825fbffe692f13350e60d4eb72d728 Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Sun, 29 Mar 2026 11:10:44 -0400 Subject: [PATCH 1/5] Fix "Make" variable expansion for test rules under Bazel 9 Signed-off-by: Aaron Sky --- xcodeproj/internal/xcodeproj_aspect.bzl | 3 +++ xcodeproj/internal/xcodeprojinfos.bzl | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/xcodeproj/internal/xcodeproj_aspect.bzl b/xcodeproj/internal/xcodeproj_aspect.bzl index 1ef3bd309..cddbec974 100644 --- a/xcodeproj/internal/xcodeproj_aspect.bzl +++ b/xcodeproj/internal/xcodeproj_aspect.bzl @@ -115,6 +115,8 @@ def _xcodeproj_aspect_impl(target, ctx): # Only create a `XcodeProjInfo` if the target hasn't already created # one rule_attr = ctx.rule.attr + # Update when Bazel 8 is dropped + var_attr = getattr(ctx.rule, "var", ctx.var) attrs = dir(rule_attr) info = xcodeprojinfos.make( @@ -127,6 +129,7 @@ def _xcodeproj_aspect_impl(target, ctx): attrs = attrs, rule_attr = rule_attr, ), + var_attr = var_attr, ) if info: providers.append(info) diff --git a/xcodeproj/internal/xcodeprojinfos.bzl b/xcodeproj/internal/xcodeprojinfos.bzl index 538d21df8..cb664a0c0 100644 --- a/xcodeproj/internal/xcodeprojinfos.bzl +++ b/xcodeproj/internal/xcodeprojinfos.bzl @@ -260,7 +260,8 @@ def _make_skipped_target_xcodeprojinfo( rule_attr, skip_type, test_env, - transitive_infos): + transitive_infos, + var_attr): """Passes through existing target info fields, not collecting new ones. Merges `XcodeProjInfo`s for the dependencies of the current target, and @@ -275,6 +276,7 @@ def _make_skipped_target_xcodeprojinfo( test_env: `ctx.configuration.test_env`. transitive_infos: A `list` of `depset`s of `XcodeProjInfo`s from the transitive dependencies of the target. + var_attr: `ctx.rule.var` (or `ctx.var` for Bazel 8 and below). Returns: The return value of `_target_info_fields`, with values merged from @@ -367,7 +369,7 @@ def _make_skipped_target_xcodeprojinfo( info_env = getattr(rule_attr, automatic_target_info.env, {}) info_env = { - k: ctx.expand_make_variables("env", v, {}) + k: ctx.expand_make_variables("env", v, var_attr) for k, v in info_env.items() } env = dicts.add(info_env, test_env) @@ -756,7 +758,8 @@ def _make_xcodeprojinfo( rule_attr, rule_kind, target, - transitive_infos): + transitive_infos, + var_attr): """Creates an `XcodeProjInfo` for the given target. Args: @@ -767,6 +770,7 @@ def _make_xcodeprojinfo( target: The `Target` to process. transitive_infos: A `list` of `XcodeProjInfo`s from the transitive dependencies of `target`. + var_attr: `ctx.rule.var` (or `ctx.var` for Bazel 8 and below). Returns: An `XcodeProjInfo` populated with information from `target` and @@ -799,6 +803,7 @@ def _make_xcodeprojinfo( skip_type = target_skip_type, test_env = ctx.configuration.test_env, transitive_infos = transitive_infos, + var_attr = var_attr, ) else: info_fields = _make_non_skipped_target_xcodeprojinfo( From 19935f69150b0b45742413cb4335ff5a96dadcba Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Sun, 29 Mar 2026 11:14:21 -0400 Subject: [PATCH 2/5] Run buildifier Signed-off-by: Aaron Sky --- xcodeproj/internal/xcodeproj_aspect.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/xcodeproj/internal/xcodeproj_aspect.bzl b/xcodeproj/internal/xcodeproj_aspect.bzl index cddbec974..24e4e0e58 100644 --- a/xcodeproj/internal/xcodeproj_aspect.bzl +++ b/xcodeproj/internal/xcodeproj_aspect.bzl @@ -115,6 +115,7 @@ def _xcodeproj_aspect_impl(target, ctx): # Only create a `XcodeProjInfo` if the target hasn't already created # one rule_attr = ctx.rule.attr + # Update when Bazel 8 is dropped var_attr = getattr(ctx.rule, "var", ctx.var) From edd5f0f1bb6b0e6e6fe8d81e67351f7717d938b7 Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Sun, 29 Mar 2026 11:23:14 -0400 Subject: [PATCH 3/5] Add a test in examples/integration Signed-off-by: Aaron Sky --- examples/integration/BUILD | 7 +++++++ examples/integration/iOSApp/Test/ObjCUnitTests/BUILD | 1 + 2 files changed, 8 insertions(+) diff --git a/examples/integration/BUILD b/examples/integration/BUILD index c9f230600..8ba0e42a8 100644 --- a/examples/integration/BUILD +++ b/examples/integration/BUILD @@ -25,6 +25,13 @@ string_flag( visibility = ["//visibility:public"], ) +string_flag( + name = "flag_with_make_variable", + build_setting_default = "", + make_variable = "FLAG_WITH_MAKE_VARIABLE", + visibility = ["//visibility:public"], +) + # Example of xcodeproj cache warming # # 1. Register a single macOS execution platform in `MODULE.bazel`: diff --git a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD index 41dbba1af..9f75f9770 100644 --- a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD +++ b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD @@ -14,6 +14,7 @@ ios_unit_test( bundle_id = "rules-xcodeproj.example.objctests", env = { "IOS_APP_UNIT_TESTS": "CUSTOM_ENV_VALUE", + "IOS_APP_UNIT_TESTS_MAKE": "$(FLAG_WITH_MAKE_VARIABLE)", }, minimum_os_version = "15.0", tags = ["manual"], From 30449b0004fdbdd1c38f6c06dbcfebc3bbd56024 Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Sun, 29 Mar 2026 11:43:43 -0400 Subject: [PATCH 4/5] Fix test I wrote Signed-off-by: Aaron Sky --- examples/integration/iOSApp/Test/ObjCUnitTests/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD index 9f75f9770..ba31c2380 100644 --- a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD +++ b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD @@ -24,6 +24,7 @@ ios_unit_test( "@rules_xcodeproj//xcodeproj:generated", ], deps = [":iOSAppObjCUnitTests.library"], + toolchains = ["//:flag_with_make_variable"], ) objc_library( From 95b1b01ba74ae0921744bec18784ae6f40a17d9f Mon Sep 17 00:00:00 2001 From: Aaron Sky Date: Sun, 29 Mar 2026 11:44:32 -0400 Subject: [PATCH 5/5] Run buildifier Signed-off-by: Aaron Sky --- examples/integration/iOSApp/Test/ObjCUnitTests/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD index ba31c2380..1ef359556 100644 --- a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD +++ b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD @@ -19,12 +19,12 @@ ios_unit_test( minimum_os_version = "15.0", tags = ["manual"], test_host = "//iOSApp", + toolchains = ["//:flag_with_make_variable"], visibility = [ "//iOSApp:__subpackages__", "@rules_xcodeproj//xcodeproj:generated", ], deps = [":iOSAppObjCUnitTests.library"], - toolchains = ["//:flag_with_make_variable"], ) objc_library(