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..1ef359556 100644 --- a/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD +++ b/examples/integration/iOSApp/Test/ObjCUnitTests/BUILD @@ -14,10 +14,12 @@ 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"], test_host = "//iOSApp", + toolchains = ["//:flag_with_make_variable"], visibility = [ "//iOSApp:__subpackages__", "@rules_xcodeproj//xcodeproj:generated", diff --git a/xcodeproj/internal/xcodeproj_aspect.bzl b/xcodeproj/internal/xcodeproj_aspect.bzl index 1ef3bd309..24e4e0e58 100644 --- a/xcodeproj/internal/xcodeproj_aspect.bzl +++ b/xcodeproj/internal/xcodeproj_aspect.bzl @@ -116,6 +116,9 @@ def _xcodeproj_aspect_impl(target, ctx): # 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( ctx = ctx, @@ -127,6 +130,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(