Skip to content

Commit a3de364

Browse files
luispadronnglevin
andauthored
Replace the use of dicts.add(...) with the native operator to union dictionaries (#496)
Cherry-pick: a849ab4 + more changes to remove references to `dicts.add` --------- Co-authored-by: Nicholas Levin <nglevin@google.com>
1 parent edab93d commit a3de364

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

doc/apple_support.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ maintainers to use:
4646
Bazel flag. The most common way to retrieve this provider is:
4747
`ctx.attr._xcode_config[apple_common.XcodeVersionConfig]`.
4848

49-
The returned `dict` can be added to the rule's attributes using Skylib's `dicts.add()` method.
49+
The returned `dict` can be added to the rule's attributes using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
5050

5151

5252

@@ -140,7 +140,7 @@ apple_support.platform_constraint_attrs()
140140

141141
Returns a dictionary of all known Apple platform constraints that can be resolved.
142142

143-
The returned `dict` can be added to the rule's attributes using Skylib's `dicts.add()` method.
143+
The returned `dict` can be added to the rule's attributes using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
144144

145145

146146

@@ -166,7 +166,7 @@ following:
166166

167167
* `fragments = ["apple"]`
168168
* Add the `apple_support.action_required_attrs()` attributes to the `attrs` dictionary. This
169-
can be done using the `dicts.add()` method from Skylib.
169+
can be done using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict)
170170

171171
This method registers an action to run on an Apple machine, configuring it to ensure that the
172172
`DEVELOPER_DIR` and `SDKROOT` environment variables are set.
@@ -226,7 +226,7 @@ the following:
226226

227227
* `fragments = ["apple"]`
228228
* Add the `apple_support.action_required_attrs()` attributes to the `attrs` dictionary. This
229-
can be done using the `dicts.add()` method from Skylib.
229+
can be done using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
230230

231231
This method registers an action to run on an Apple machine, configuring it to ensure that the
232232
`DEVELOPER_DIR` and `SDKROOT` environment variables are set.
@@ -264,7 +264,7 @@ In order to use `apple_support.target_arch_from_rule_ctx()`, you'll need to modi
264264
definition to add the following:
265265

266266
* Add the `apple_support.platform_constraint_attrs()` attributes to the `attrs` dictionary.
267-
This can be done using the `dicts.add()` method from Skylib.
267+
This can be done using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
268268

269269

270270
**PARAMETERS**
@@ -301,7 +301,7 @@ In order to use `apple_support.target_environment_from_rule_ctx()`, you'll need
301301
rule definition to add the following:
302302

303303
* Add the `apple_support.platform_constraint_attrs()` attributes to the `attrs` dictionary.
304-
This can be done using the `dicts.add()` method from Skylib.
304+
This can be done using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
305305

306306

307307
**PARAMETERS**
@@ -337,7 +337,7 @@ In order to use `apple_support.target_os_from_rule_ctx()`, you'll need to modify
337337
definition to add the following:
338338

339339
* Add the `apple_support.platform_constraint_attrs()` attributes to the `attrs` dictionary.
340-
This can be done using the `dicts.add()` method from Skylib.
340+
This can be done using a [Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
341341

342342

343343
**PARAMETERS**

lib/apple_support.bzl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def _action_required_attrs():
224224
Bazel flag. The most common way to retrieve this provider is:
225225
`ctx.attr._xcode_config[apple_common.XcodeVersionConfig]`.
226226
227-
The returned `dict` can be added to the rule's attributes using Skylib's `dicts.add()` method.
227+
The returned `dict` can be added to the rule's attributes using a \
228+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
228229
229230
Returns:
230231
A `dict` object containing attributes to be added to rule implementations.
@@ -241,7 +242,8 @@ def _action_required_attrs():
241242
def _platform_constraint_attrs():
242243
"""Returns a dictionary of all known Apple platform constraints that can be resolved.
243244
244-
The returned `dict` can be added to the rule's attributes using Skylib's `dicts.add()` method.
245+
The returned `dict` can be added to the rule's attributes using a \
246+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
245247
246248
Returns:
247249
A `dict` object containing attributes to be added to rule implementations.
@@ -299,7 +301,8 @@ def _run(
299301
300302
* `fragments = ["apple"]`
301303
* Add the `apple_support.action_required_attrs()` attributes to the `attrs` dictionary. This
302-
can be done using the `dicts.add()` method from Skylib.
304+
can be done using a \
305+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict)
303306
304307
This method registers an action to run on an Apple machine, configuring it to ensure that the
305308
`DEVELOPER_DIR` and `SDKROOT` environment variables are set.
@@ -426,7 +429,8 @@ def _run_shell(
426429
427430
* `fragments = ["apple"]`
428431
* Add the `apple_support.action_required_attrs()` attributes to the `attrs` dictionary. This
429-
can be done using the `dicts.add()` method from Skylib.
432+
can be done using a \
433+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
430434
431435
This method registers an action to run on an Apple machine, configuring it to ensure that the
432436
`DEVELOPER_DIR` and `SDKROOT` environment variables are set.
@@ -460,7 +464,8 @@ def _target_arch_from_rule_ctx(
460464
definition to add the following:
461465
462466
* Add the `apple_support.platform_constraint_attrs()` attributes to the `attrs` dictionary.
463-
This can be done using the `dicts.add()` method from Skylib.
467+
This can be done using a \
468+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
464469
465470
Args:
466471
ctx: The context of the rule that has Apple platform constraint attributes.
@@ -504,7 +509,8 @@ def _target_environment_from_rule_ctx(
504509
rule definition to add the following:
505510
506511
* Add the `apple_support.platform_constraint_attrs()` attributes to the `attrs` dictionary.
507-
This can be done using the `dicts.add()` method from Skylib.
512+
This can be done using a \
513+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
508514
509515
Args:
510516
ctx: The context of the rule that has Apple platform constraint attributes.
@@ -539,7 +545,8 @@ def _target_os_from_rule_ctx(
539545
definition to add the following:
540546
541547
* Add the `apple_support.platform_constraint_attrs()` attributes to the `attrs` dictionary.
542-
This can be done using the `dicts.add()` method from Skylib.
548+
This can be done using a \
549+
[Starlark dictionary union expression: `|`](https://bazel.build/rules/lib/core/dict).
543550
544551
Args:
545552
ctx: The context of the rule that has Apple platform constraint attributes.

rules/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ bzl_library(
2929
"//lib:apple_support",
3030
"//lib:lipo",
3131
"//lib:transitions",
32-
"@bazel_skylib//lib:dicts",
3332
],
3433
)
3534

rules/private/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ bzl_library(
1111
],
1212
deps = [
1313
"//lib:apple_support",
14-
"@bazel_skylib//lib:dicts",
1514
],
1615
)
1716

rules/private/apple_genrule.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
"""Genrule which provides Apple's Xcode environment."""
1616

17-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
1817
load("//lib:apple_support.bzl", "apple_support")
1918

2019
def _compute_make_variables(
@@ -102,7 +101,7 @@ def _apple_genrule_impl(ctx):
102101

103102
apple_genrule = rule(
104103
implementation = _apple_genrule_impl,
105-
attrs = dicts.add(apple_support.action_required_attrs(), {
104+
attrs = apple_support.action_required_attrs() | {
106105
"cmd": attr.string(
107106
mandatory = True,
108107
doc = "The command to run. Subject the variable substitution.",
@@ -141,7 +140,7 @@ action is run.
141140
"no_sandbox": attr.bool(
142141
doc = "If the sandbox should be disabled when the action is run.",
143142
),
144-
}),
143+
},
145144
doc = """\
146145
Genrule which provides Apple specific environment and make variables.
147146

rules/universal_binary.bzl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
"""Implementation for macOS universal binary rule."""
1616

17-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
1817
load("//lib:apple_support.bzl", "apple_support")
1918
load("//lib:lipo.bzl", "lipo")
2019
load("//lib:transitions.bzl", "macos_universal_transition")
@@ -61,19 +60,17 @@ def _universal_binary_impl(ctx):
6160
]
6261

6362
universal_binary = rule(
64-
attrs = dicts.add(
65-
apple_support.action_required_attrs(),
66-
{
67-
"binary": attr.label(
68-
cfg = macos_universal_transition,
69-
doc = "Target to generate a 'fat' binary from.",
70-
mandatory = True,
71-
),
72-
"_allowlist_function_transition": attr.label(
73-
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
74-
),
75-
},
76-
),
63+
attrs = apple_support.action_required_attrs() |
64+
{
65+
"binary": attr.label(
66+
cfg = macos_universal_transition,
67+
doc = "Target to generate a 'fat' binary from.",
68+
mandatory = True,
69+
),
70+
"_allowlist_function_transition": attr.label(
71+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
72+
),
73+
},
7774
doc = """
7875
This rule produces a multi-architecture ("fat") binary targeting Apple macOS
7976
platforms *regardless* of the architecture of the macOS host platform. The

test/rules/apple_verification_test.bzl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
"""Test rule to perform generic bundle verification tests."""
1616

17-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
18-
1917
_supports_visionos = hasattr(apple_common.platform_type, "visionos")
2018

2119
def _transition_impl(_, attr):
@@ -97,10 +95,10 @@ def _apple_verification_test_impl(ctx):
9795

9896
return [
9997
testing.ExecutionInfo(xcode_config.execution_info()),
100-
testing.TestEnvironment(dicts.add(
101-
apple_common.apple_host_system_env(xcode_config),
98+
testing.TestEnvironment(
99+
apple_common.apple_host_system_env(xcode_config) |
102100
test_env,
103-
)),
101+
),
104102
DefaultInfo(
105103
executable = output_script,
106104
runfiles = ctx.runfiles(

0 commit comments

Comments
 (0)