You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following rule definition fails because the default value is not of type string. I see the same behavior with other attribute types.
def_foo_impl(ctx):
passfoo=rule(
implementation=_foo_impl,
attrs= {
"_target_platform": attr.string(
default=select({
# Definition of //:os_windows omitted for brevity. Does what you'd expect it to do."//:os_windows": "windows",
"//conditions:default": "posix",
}),
)
},
)
ERROR: /.../defs.bzl:??:??: Traceback (most recent call last):
File "/.../defs.bzl", line ??
rule(implementation = _foo_impl, attrs =..."}))})
File "/.../defs.bzl", line ?? in rule
attr.string(default = select({"//:os_windows..."}))
expected value of type 'string' for parameter 'default', for call to method string(default = '', doc = '', mandatory = False, values = []) of 'attr (a language module)'
As a workaround for this issue, it's possible to wrap foo in a macro and set the default value in the macro. However, this requires the attribute to be "public".
Have you found anything relevant by searching the web?
A similar issue that asked to use select as default value in a repository_rule (#2026) was closed as WAI. However, this feature request is about using it in rule.
The text was updated successfully, but these errors were encountered:
Description of the problem / feature request:
Use select as default value.
Feature requests: what underlying problem are you trying to solve with this feature?
Selecting the default value of a rule attribute based on, e.g. the host or target OS.
For example,
protoc
's--proto_path
or--descriptor_set_in
uses a different path separator based on the host OS: https://github.com/protocolbuffers/protobuf/blob/61301f01552dd84d744a05c88af95833c600a1a7/src/google/protobuf/compiler/command_line_interface.cc#L778The following rule definition fails because the default value is not of type
string
. I see the same behavior with other attribute types.As a workaround for this issue, it's possible to wrap
foo
in a macro and set the default value in the macro. However, this requires the attribute to be "public".Have you found anything relevant by searching the web?
A similar issue that asked to use
select
as default value in arepository_rule
(#2026) was closed as WAI. However, this feature request is about using it inrule
.The text was updated successfully, but these errors were encountered: