Skip to content

Commit 005910c

Browse files
authored
Fix "Make" variable expansion for test rules under Bazel 9 (#3297)
Fixes #3296 --------- Signed-off-by: Aaron Sky <aaronsky@skyaaron.com>
1 parent 40bab89 commit 005910c

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

examples/integration/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ string_flag(
2525
visibility = ["//visibility:public"],
2626
)
2727

28+
string_flag(
29+
name = "flag_with_make_variable",
30+
build_setting_default = "",
31+
make_variable = "FLAG_WITH_MAKE_VARIABLE",
32+
visibility = ["//visibility:public"],
33+
)
34+
2835
# Example of xcodeproj cache warming
2936
#
3037
# 1. Register a single macOS execution platform in `MODULE.bazel`:

examples/integration/iOSApp/Test/ObjCUnitTests/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ ios_unit_test(
1414
bundle_id = "rules-xcodeproj.example.objctests",
1515
env = {
1616
"IOS_APP_UNIT_TESTS": "CUSTOM_ENV_VALUE",
17+
"IOS_APP_UNIT_TESTS_MAKE": "$(FLAG_WITH_MAKE_VARIABLE)",
1718
},
1819
minimum_os_version = "15.0",
1920
tags = ["manual"],
2021
test_host = "//iOSApp",
22+
toolchains = ["//:flag_with_make_variable"],
2123
visibility = [
2224
"//iOSApp:__subpackages__",
2325
"@rules_xcodeproj//xcodeproj:generated",

xcodeproj/internal/xcodeproj_aspect.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def _xcodeproj_aspect_impl(target, ctx):
116116
# one
117117
rule_attr = ctx.rule.attr
118118

119+
# Update when Bazel 8 is dropped
120+
var_attr = getattr(ctx.rule, "var", ctx.var)
121+
119122
attrs = dir(rule_attr)
120123
info = xcodeprojinfos.make(
121124
ctx = ctx,
@@ -127,6 +130,7 @@ def _xcodeproj_aspect_impl(target, ctx):
127130
attrs = attrs,
128131
rule_attr = rule_attr,
129132
),
133+
var_attr = var_attr,
130134
)
131135
if info:
132136
providers.append(info)

xcodeproj/internal/xcodeprojinfos.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ def _make_skipped_target_xcodeprojinfo(
260260
rule_attr,
261261
skip_type,
262262
test_env,
263-
transitive_infos):
263+
transitive_infos,
264+
var_attr):
264265
"""Passes through existing target info fields, not collecting new ones.
265266
266267
Merges `XcodeProjInfo`s for the dependencies of the current target, and
@@ -275,6 +276,7 @@ def _make_skipped_target_xcodeprojinfo(
275276
test_env: `ctx.configuration.test_env`.
276277
transitive_infos: A `list` of `depset`s of `XcodeProjInfo`s from the
277278
transitive dependencies of the target.
279+
var_attr: `ctx.rule.var` (or `ctx.var` for Bazel 8 and below).
278280
279281
Returns:
280282
The return value of `_target_info_fields`, with values merged from
@@ -367,7 +369,7 @@ def _make_skipped_target_xcodeprojinfo(
367369

368370
info_env = getattr(rule_attr, automatic_target_info.env, {})
369371
info_env = {
370-
k: ctx.expand_make_variables("env", v, {})
372+
k: ctx.expand_make_variables("env", v, var_attr)
371373
for k, v in info_env.items()
372374
}
373375
env = dicts.add(info_env, test_env)
@@ -756,7 +758,8 @@ def _make_xcodeprojinfo(
756758
rule_attr,
757759
rule_kind,
758760
target,
759-
transitive_infos):
761+
transitive_infos,
762+
var_attr):
760763
"""Creates an `XcodeProjInfo` for the given target.
761764
762765
Args:
@@ -767,6 +770,7 @@ def _make_xcodeprojinfo(
767770
target: The `Target` to process.
768771
transitive_infos: A `list` of `XcodeProjInfo`s from the transitive
769772
dependencies of `target`.
773+
var_attr: `ctx.rule.var` (or `ctx.var` for Bazel 8 and below).
770774
771775
Returns:
772776
An `XcodeProjInfo` populated with information from `target` and
@@ -799,6 +803,7 @@ def _make_xcodeprojinfo(
799803
skip_type = target_skip_type,
800804
test_env = ctx.configuration.test_env,
801805
transitive_infos = transitive_infos,
806+
var_attr = var_attr,
802807
)
803808
else:
804809
info_fields = _make_non_skipped_target_xcodeprojinfo(

0 commit comments

Comments
 (0)