Skip to content

Commit 4189af4

Browse files
committed
better match set api
1 parent e34ac8f commit 4189af4

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

python/private/builders.bzl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,15 @@ def _TransitionBuilder(implementation = None, inputs = None, outputs = None, **k
215215
# buildifier: disable=uninitialized
216216
self = struct(
217217
implementation = _Optional(implementation),
218+
# Bazel requires transition.inputs to have unique values, so use set
219+
# semantics so extenders of a transition can easily add/remove values.
220+
# TODO - Use set builtin instead of custom builder, when available.
221+
# https://bazel.build/rules/lib/core/set
218222
inputs = _SetBuilder(inputs),
223+
# Bazel requires transition.inputs to have unique values, so use set
224+
# semantics so extenders of a transition can easily add/remove values.
225+
# TODO - Use set builtin instead of custom builder, when available.
226+
# https://bazel.build/rules/lib/core/set
219227
outputs = _SetBuilder(outputs),
220228
extra_kwargs = kwargs,
221229
build = lambda *a, **k: _TransitionBuilder_build(self, *a, **k),
@@ -235,19 +243,22 @@ def _SetBuilder(initial = None):
235243

236244
# buildifier: disable=uninitialized
237245
self = struct(
246+
# TODO - Switch this to use set() builtin when available
247+
# https://bazel.build/rules/lib/core/set
238248
_values = initial,
239-
extend = lambda *a, **k: _SetBuilder_extend(self, *a, **k),
249+
update = lambda *a, **k: _SetBuilder_update(self, *a, **k),
240250
build = lambda *a, **k: _SetBuilder_build(self, *a, **k),
241251
)
242252
return self
243253

244254
def _SetBuilder_build(self):
245255
return self._values.keys()
246256

247-
def _SetBuilder_extend(self, values):
248-
for v in values:
249-
if v not in self._values:
250-
self._values[v] = None
257+
def _SetBuilder_update(self, *others):
258+
for other in others:
259+
for value in other:
260+
if value not in self._values:
261+
self._values[value] = None
251262

252263
def _RuleBuilder(implementation = None, **kwargs):
253264
# buildifier: disable=uninitialized
@@ -277,9 +288,7 @@ def _RuleBuilder_build(self, debug = ""):
277288
lines = ["=" * 80, "rule kwargs: {}:".format(debug)]
278289
for k, v in sorted(kwargs.items()):
279290
lines.append(" {}={}".format(k, v))
280-
281-
# buildifier: disable=print
282-
print("\n".join(lines))
291+
print("\n".join(lines)) # buildifier: disable=print
283292
return rule(**kwargs)
284293

285294
def _RuleBuilder_to_kwargs(self):

tests/support/sh_py_run_test.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ def _create_reconfig_rule(builder):
7070

7171
base_cfg_impl = builder.cfg.implementation.get()
7272
builder.cfg.implementation.set(lambda *args: _perform_transition_impl(base_impl = base_cfg_impl, *args))
73-
builder.cfg.inputs.extend(_RECONFIG_INPUTS)
74-
builder.cfg.outputs.extend(_RECONFIG_OUTPUTS)
73+
builder.cfg.inputs.update(_RECONFIG_INPUTS)
74+
builder.cfg.outputs.update(_RECONFIG_OUTPUTS)
75+
7576
return builder.build()
7677

7778
_py_reconfig_binary = _create_reconfig_rule(create_binary_rule_builder())

0 commit comments

Comments
 (0)