Skip to content

config.string with allow_multiple=True should use list for build_setting_default #13817

@Yannic

Description

@Yannic

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.

Metadata

Metadata

Assignees

Labels

P2We'll consider working on this in future. (Assignee optional)team-Configurabilityplatforms, toolchains, cquery, select(), config transitionstype: support / not a bug (process)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions