I'm trying to migrate a native flag (--protocopt) to a Starlark flag. For this, we need a flag that a) can be supplied multiple times (like with allow_multiple=True - config.string_list doesn't allow this) and b) has an empty default.
Today, it's impossible to get an empty list or a list with multiple elements as ctx.build_setting_value when using config.string with allow_multiple=True.
# foo.bzl
def _impl(ctx):
pass
foo = rule(
implementation = _impl,
build_setting = config.string(flag = True, allow_multiple = True),
)
# BUILD
load(":foo.bzl", "foo")
foo(name="foo", build_setting_default="") # <-- `ctx.build_setting_value` becomes `[""]`.
There are ways to work around this (i.e. setting build_setting_default to a nonsensical value and checking for ctx.build_setting_value with one element that is the specified default value), but that seems unnecessarily complex.
From a technical perspective, changing the allowed type for build_setting_default when allow_multiple=True looks pretty straight forward to me.
allow_multiple was added in https://cs.opensource.google/bazel/bazel/+/a13f590b69bcbcaa10b1a49bfd9a4607dfbd8f47 after cutting Bazel 4.0.0, so its usage in the wild should be low.
I'm trying to migrate a native flag (
--protocopt) to a Starlark flag. For this, we need a flag that a) can be supplied multiple times (like withallow_multiple=True-config.string_listdoesn't allow this) and b) has an empty default.Today, it's impossible to get an empty list or a list with multiple elements as
ctx.build_setting_valuewhen usingconfig.stringwithallow_multiple=True.There are ways to work around this (i.e. setting
build_setting_defaultto a nonsensical value and checking forctx.build_setting_valuewith one element that is the specified default value), but that seems unnecessarily complex.From a technical perspective, changing the allowed type for
build_setting_defaultwhenallow_multiple=Truelooks pretty straight forward to me.allow_multiplewas added in https://cs.opensource.google/bazel/bazel/+/a13f590b69bcbcaa10b1a49bfd9a4607dfbd8f47 after cutting Bazel 4.0.0, so its usage in the wild should be low.