bazelbuild / bazelbuild/bazel

Starlark rules should allow selectable attribute defaults

Open
#287 10 comments 11 reactions 0 assignees View on GitHub
P3 team-Rules-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

Given simple.bzl:

def simple_impl(ctx):
ctx.file_action(
output = ctx.outputs.out,
content = ctx.attr.foo)

simple = rule(
simple_impl,
attrs = {
'foo': select({ '//conditions:default': 'bard' }),
},
outputs = {'out': '%{name}.out' },
)

and BUILD:

simple(name = 'foo')

building ':foo' produces the error:
Illegal argument: expected type for 'attrs' but got instead.

This is an attempt at a "configurable attribute default", which should be able to work just fine. This failure may come from Skylark or it may come from Bazel's underlying rule machinery, which currently doesn't have any intelligent concept of selectable values not explicitly set in BUILD files.

Originally noticed in https://groups.google.com/d/msg/bazel-discuss/5VR2rVfak-8/dMxXDW1DnZ4J

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.