Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starlark type checking of select() behaves inconsistently #6643

Closed
clintharrison opened this issue Nov 9, 2018 · 1 comment
Closed

Starlark type checking of select() behaves inconsistently #6643

clintharrison opened this issue Nov 9, 2018 · 1 comment
Labels
team-Configurability platforms, toolchains, cquery, select(), config transitions type: bug

Comments

@clintharrison
Copy link
Contributor

Description of the problem / feature request:

Selectors behave oddly in the type checker: they can be used in place of a string, label, or list, but they cannot be used as a string or label in a list.

Feature requests: what underlying problem are you trying to solve with this feature?

We currently use a requirement() function to map a short name to a more complex py_library() in an external workspace. (This comes from the standard rules_python Pip repository rules.)

py_binary(
    name = "example",
    srcs = ["example.py"],
    deps = [
        "//:dep_a",
        requirement("absl-py")
    ],
)

Changing the underlying implementation of requirement() to support multiple platforms with a select() in place of the simple string it currently returns is not possible. All users of the requirement() function need to be changed, for example as:

py_binary(
    name = "example",
    srcs = ["example.py"],
    deps = [
        "//:dep_a",
    ] + requirement("absl-py"),
)

This is a potentially large undertaking, touching many BUILD files to work around a limitation in type checking.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

py_library(
    name = "lib",
    srcs = [],
)

py_binary(
    name = "example_a",
    srcs = ["example.py"],
    main = "example.py",
    deps = [
        ":lib",
    ],
)

py_binary(
    name = "example_b",
    srcs = ["example.py"],
    main = "example.py",
    deps = select({
        "//conditions:default": [":lib"]
    }),
)

# This is not possible:
# BUILD:26:1: //:example_c: expected value of type 'string' for element 0 of attribute
# 'deps' in 'py_binary' rule, but got select({"//conditions:default": ":lib"}) (select)
py_binary(
    name = "example_c",
    srcs = ["example.py"],
    main = "example.py",
    deps = [
        select({"//conditions:default": ":lib"}),
    ],
)

What operating system are you running Bazel on?

macOS 10.12

What's the output of bazel info release?

release 0.18.0

Have you found anything relevant by searching the web?

All examples of select() seem to assume this behavior, or only use it in a non-list context.

@jin jin added type: bug team-Configurability platforms, toolchains, cquery, select(), config transitions untriaged labels Nov 9, 2018
@gregestren
Copy link
Contributor

Duplicate of #1623

Feel free to unduplicate if you disagree.

The short story is that selects today always bind to the attribute's type. So if the attribute is a label list the select must expand to a label list. #1623
talks about loosening that up some, I think to your satisfaction. There's already a prototype for it but it would take some more (still undone) work to make it production-ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability platforms, toolchains, cquery, select(), config transitions type: bug
Projects
None yet
Development

No branches or pull requests

3 participants