Skip to content

Commit

Permalink
Respectful language: whitelist -> allowlist (bazelbuild#197)
Browse files Browse the repository at this point in the history
* Respectful language: whitelist -> allowlist

* Missed one!

* And another.
  • Loading branch information
gregestren authored Feb 10, 2021
1 parent 4183fc7 commit b1c5b85
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ red_transition = transition(
def _impl(ctx):
# Access the value of //starlark_configurations/attaching_transitions_to_rules:color for the target (blue).
print("shirt color: " + ctx.attr._color[BuildSettingInfo].value)

# Access the value of //starlark_configurations/attaching_transitions_to_rules:color for the transitioned dep (red).
# Note that you have to index by [0] here for the transitioned dep and you don't need to
# do so below - this is because attribute-attached transitions can transition to multiple
# new configurations so you must specify which one you want.
print("sleeve color: " + ctx.attr.sleeve[0][BuildSettingInfo].value)

# Access the value of //starlark_configurations/attaching_transitions_to_rules:color for the non-transitioned dep (blue).
print("back color: " + ctx.attr.back[BuildSettingInfo].value)
return []
Expand All @@ -53,10 +55,10 @@ shirt = rule(
# can't override the value.
"_color": attr.label(default = ":color"),
# This attribute is required to use starlark transitions. It allows
# whitelisting usage of this rule. For more information, see
# allowlisting usage of this rule. For more information, see
# https://docs.bazel.build/versions/master/skylark/config.html#user-defined-transitions
"_whitelist_function_transition": attr.label(
default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
)
Expand All @@ -70,6 +72,6 @@ piece = rule(
# Depend on the build setting so that we can access it in the rule implementation.
# Use a private attribute (one that is prefixed with "_") so that target writers
# can't override the value.
"_color": attr.label(default = ":color")
}
"_color": attr.label(default = ":color"),
},
)
30 changes: 15 additions & 15 deletions rules/starlark_configurations/cc_binary_selectable_copts/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def _copt_transition_impl(settings, attr):
_ignore = settings

# settings provides read access to existing flags. But
# this transition doesn't need to read any flags.
return {"//starlark_configurations/cc_binary_selectable_copts/custom_settings:mycopts": attr.set_features}
Expand Down Expand Up @@ -49,22 +49,22 @@ def _transition_rule_impl(ctx):
transition_rule = rule(
implementation = _transition_rule_impl,
attrs = {
# This is where the user can set the feature they want.
# This is where the user can set the feature they want.
"set_features": attr.string(default = "unset"),
# This is the cc_binary whose deps will select() on that feature.
# Note specificaly how it's configured with _copt_transition, which
# ensures that setting propagates down the graph.
# This is the cc_binary whose deps will select() on that feature.
# Note specificaly how it's configured with _copt_transition, which
# ensures that setting propagates down the graph.
"actual_binary": attr.label(cfg = _copt_transition),
# This is a stock Bazel requirement for any rule that uses Starlark
# transitions. It's okay to copy the below verbatim for all such rules.
#
# The purpose of this requirement is to give the ability to restrict
# which packages can invoke these rules, since Starlark transitions
# make much larger graphs possible that can have memory and performance
# consequences for your build. The whitelist defaults to "everything".
# But you can redefine it more strictly if you feel that's prudent.
"_whitelist_function_transition": attr.label(
default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
# This is a stock Bazel requirement for any rule that uses Starlark
# transitions. It's okay to copy the below verbatim for all such rules.
#
# The purpose of this requirement is to give the ability to restrict
# which packages can invoke these rules, since Starlark transitions
# make much larger graphs possible that can have memory and performance
# consequences for your build. The allowlist defaults to "everything".
# But you can redefine it more strictly if you feel that's prudent.
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
# Making this executable means it works with "$ bazel run".
Expand Down
8 changes: 4 additions & 4 deletions rules/starlark_configurations/cc_test/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# We can transition on native options using this
# We can transition on native options using this
# //command_line_option:<option-name> syntax
_BUILD_SETTING = "//command_line_option:test_arg"

Expand Down Expand Up @@ -30,8 +30,8 @@ transition_rule_test = rule(
implementation = _test_transition_rule_impl,
attrs = {
"actual_test": attr.label(cfg = _test_arg_transition, executable = True),
"_whitelist_function_transition": attr.label(
default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
test = True,
Expand All @@ -43,4 +43,4 @@ def test_arg_cc_test(name, **kwargs):
name = name,
actual_test = ":%s" % cc_test_name,
)
native.cc_test(name = cc_test_name, **kwargs)
native.cc_test(name = cc_test_name, **kwargs)
36 changes: 18 additions & 18 deletions rules/starlark_configurations/multi_arch_binary/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,45 @@ def _transition_impl(settings, attr):
# https://docs.bazel.build/versions/master/skylark/config.html#defining-12-transitions
return {
"x86-platform": {"//command_line_option:cpu": "x86"},
"armeabi-v7a-platform": {"//command_line_option:cpu": "armeabi-v7a"}
}

"armeabi-v7a-platform": {"//command_line_option:cpu": "armeabi-v7a"},
}

fat_transition = transition(
implementation = _transition_impl,
inputs = [],
outputs = ["//command_line_option:cpu"]
outputs = ["//command_line_option:cpu"],
)

def _rule_impl(ctx):
# Access the split dependencies via `ctx.split_attr.<split-attr-name>`
tools = ctx.split_attr.tool

# The values of `x86_dep` and `armeabi-v7a_dep` here are regular
# dependencies with providers. These keys are pulled from the dict
# returned by the transition above.
x86_dep = tools['x86-platform']
armeabi_v7a_dep = tools['armeabi-v7a-platform']
# returned by the transition above.
x86_dep = tools["x86-platform"]
armeabi_v7a_dep = tools["armeabi-v7a-platform"]
print("tool 'x86-platform' dep: " + x86_dep[CpuInfo].value)
print("tool 'armeabi-v7a-platform' dep: " + armeabi_v7a_dep[CpuInfo].value)
return []

foo_binary = rule(
implementation = _rule_impl,
attrs = {
"tool": attr.label(cfg = fat_transition),
# This attribute is required to use starlark transitions. It allows
# whitelisting usage of this rule. For more information, see
# https://docs.bazel.build/versions/master/skylark/config.html#user-defined-transitions
'_whitelist_function_transition': attr.label(
default = '@bazel_tools//tools/whitelists/function_transition_whitelist',
)
}
implementation = _rule_impl,
attrs = {
"tool": attr.label(cfg = fat_transition),
# This attribute is required to use starlark transitions. It allows
# allowlisting usage of this rule. For more information, see
# https://docs.bazel.build/versions/master/skylark/config.html#user-defined-transitions
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
)

CpuInfo = provider(fields = ["value"])

def _impl(ctx):
# Get the current cpu using `ctx.var` which contains a
# Get the current cpu using `ctx.var` which contains a
# dict of configuration variable
# https://docs.bazel.build/versions/master/skylark/lib/ctx.html#var
return CpuInfo(value = "--cpu=" + ctx.var["TARGET_CPU"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ my_rule = rule(
attrs = {
"do_transition": attr.bool(),
"_some_string": attr.label(default = Label("//starlark_configurations/read_attr_in_transition:some-string")),
"_whitelist_function_transition": attr.label(
default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}
},
)
14 changes: 7 additions & 7 deletions rules/starlark_configurations/transition_on_native_flag/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def _transition_impl(settings, attr):
# flag makes the flag available to transition on. The result of this transition
# is to set --cpu
# We read the value from the attr also named `cpu` which allows target writers
# to modify how the transition works. This could also just be a hardcoded
# to modify how the transition works. This could also just be a hardcoded
# string like "x86" if you didn't want to give target writers that power.
return {"//command_line_option:cpu": attr.cpu }
return {"//command_line_option:cpu": attr.cpu}

# Define a transition.
cpu_transition = transition(
Expand All @@ -19,7 +19,7 @@ cpu_transition = transition(
)

def _impl(ctx):
# Print the current cpu using `ctx.var` which contains a
# Print the current cpu using `ctx.var` which contains a
# dict of configuration variable
# https://docs.bazel.build/versions/master/skylark/lib/ctx.html#var
print("--cpu=" + ctx.var["TARGET_CPU"])
Expand All @@ -33,11 +33,11 @@ cpu_rule = rule(
cfg = cpu_transition,
attrs = {
# This attribute is required to use starlark transitions. It allows
# whitelisting usage of this rule. For more information, see
# allowlisting usage of this rule. For more information, see
# https://docs.bazel.build/versions/master/skylark/config.html#user-defined-transitions
"_whitelist_function_transition": attr.label(
default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"cpu": attr.string(default = "x86"),
},
)
)

0 comments on commit b1c5b85

Please sign in to comment.