Skip to content

Commit 07d6585

Browse files
authored
Expand "Make" variables inside of values in the env dictionary on test rules (#3088)
Fixes #3056 This PR implements a gap introduced when bazelbuild/rules_apple#2476 was introduced, where expandable env settings on test rules would not be expanded into the xcscheme during generation. There are a couple of things that reviewers should be aware of before proceeding with this change: - This change is not considerate of the rules_apple being used, meaning that it assumes the developer is using at least version [3.6.0](https://github.com/bazelbuild/rules_apple/releases/tag/3.6.0) (when the breaking changes in #2476 were introduced). This is not good and should be considered a blocker, but I don't know how to address this with the tools offered by the ruleset or Bazel. - This change as-implemented requires regeneration of the xcschemes if the configured value of the "Make" variable ever changes. Signed-off-by: Aaron Sky <[email protected]>
1 parent f4fa898 commit 07d6585

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ bazel_dep(name = "bazel_features", version = "1.3.0")
1010
bazel_dep(name = "bazel_skylib", version = "1.3.0")
1111
bazel_dep(
1212
name = "rules_swift",
13-
version = "1.6.0",
13+
version = "1.18.0",
1414
max_compatibility_level = 2,
1515
repo_name = "build_bazel_rules_swift",
1616
)
1717
bazel_dep(
1818
name = "rules_apple",
19-
version = "2.0.0",
19+
version = "3.6.0",
2020
repo_name = "build_bazel_rules_apple",
2121
)
2222
bazel_dep(name = "rules_python", version = "0.27.1")

xcodeproj/internal/incremental_xcodeprojinfos.bzl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def _target_info_fields(
258258

259259
def _make_skipped_target_xcodeprojinfo(
260260
*,
261+
ctx,
261262
automatic_target_info,
262263
rule_attr,
263264
skip_type,
@@ -269,6 +270,7 @@ def _make_skipped_target_xcodeprojinfo(
269270
forwards them on, not collecting any information for the current target.
270271
271272
Args:
273+
ctx: The aspect context.
272274
automatic_target_info: The `XcodeProjAutomaticTargetProcessingInfo` for
273275
`the target.
274276
rule_attr: `ctx.rule.attr`.
@@ -360,6 +362,22 @@ def _make_skipped_target_xcodeprojinfo(
360362
],
361363
)
362364

365+
if automatic_target_info.env:
366+
direct_envs = []
367+
for info in deps_transitive_infos:
368+
if not info.xcode_target:
369+
continue
370+
371+
info_env = getattr(rule_attr, automatic_target_info.env, {})
372+
info_env = {
373+
k: ctx.expand_make_variables("env", v, {})
374+
for k, v in info_env.items()
375+
}
376+
env = dicts.add(info_env, test_env)
377+
direct_envs.append(struct(id = info.xcode_target.id, env = tuple([(k, v) for k, v in env.items()])))
378+
else:
379+
direct_envs = None
380+
363381
return _target_info_fields(
364382
args = memory_efficient_depset(
365383
[
@@ -380,24 +398,7 @@ def _make_skipped_target_xcodeprojinfo(
380398
compilation_providers = provider_compilation_providers,
381399
direct_dependencies = direct_dependencies,
382400
envs = memory_efficient_depset(
383-
[
384-
struct(
385-
id = info.xcode_target.id,
386-
env = tuple([
387-
(k, v)
388-
for k, v in dicts.add(
389-
getattr(
390-
rule_attr,
391-
automatic_target_info.env,
392-
{},
393-
),
394-
test_env,
395-
).items()
396-
]),
397-
)
398-
for info in deps_transitive_infos
399-
if info.xcode_target
400-
] if automatic_target_info.env else None,
401+
direct_envs,
401402
transitive = [
402403
info.envs
403404
for info in valid_transitive_infos
@@ -797,6 +798,7 @@ def _make_xcodeprojinfo(
797798
)
798799
if target_skip_type:
799800
info_fields = _make_skipped_target_xcodeprojinfo(
801+
ctx = ctx,
800802
automatic_target_info = automatic_target_info,
801803
rule_attr = rule_attr,
802804
skip_type = target_skip_type,

xcodeproj/internal/legacy_xcodeprojinfos.bzl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,19 @@ def _make_skipped_target_xcodeprojinfo(
352352
"{}:{}".format(package_label_str, label_name),
353353
)
354354

355+
if automatic_target_info.env:
356+
direct_envs = []
357+
for info in deps_transitive_infos:
358+
info_env = getattr(rule_attr, automatic_target_info.env, {})
359+
info_env = {
360+
k: ctx.expand_make_variables("env", v, {})
361+
for k, v in info_env.items()
362+
}
363+
env = dicts.add(info_env, ctx.configuration.test_env)
364+
direct_envs.append(struct(id = info.xcode_target.id, env = struct(**env)))
365+
else:
366+
direct_envs = None
367+
355368
return _target_info_fields(
356369
args = memory_efficient_depset(
357370
[
@@ -371,22 +384,7 @@ def _make_skipped_target_xcodeprojinfo(
371384
compilation_providers = provider_compilation_providers,
372385
direct_dependencies = direct_dependencies,
373386
envs = memory_efficient_depset(
374-
[
375-
struct(
376-
id = info.xcode_target.id,
377-
env = struct(
378-
**dicts.add(
379-
getattr(
380-
rule_attr,
381-
automatic_target_info.env,
382-
{},
383-
),
384-
ctx.configuration.test_env,
385-
)
386-
),
387-
)
388-
for info in deps_transitive_infos
389-
] if automatic_target_info.env else None,
387+
direct_envs,
390388
transitive = [
391389
info.envs
392390
for info in valid_transitive_infos

0 commit comments

Comments
 (0)