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

[Bug]: py_binary expression expands to more than one file #455

Open
keith opened this issue Dec 2, 2024 · 3 comments · May be fixed by #467
Open

[Bug]: py_binary expression expands to more than one file #455

keith opened this issue Dec 2, 2024 · 3 comments · May be fixed by #467
Labels
bug Something isn't working

Comments

@keith
Copy link
Contributor

keith commented Dec 2, 2024

What happened?

Using rules_python's py_binary like this:

py_binary(
    name = "upstream_py_binary",
    srcs = ["say.py"],
    main = "say.py",
)

py_binary(
    name = "upstream_py_binary2",
    srcs = ["say.py"],
    main = "say.py",
    data = [":upstream_py_binary"],
    env = {"FOO": "$(execpath :upstream_py_binary)"},
)

Works fine, but if you do the same with rules_py's py_binary, you get this error:

ERROR: /home/ubuntu/dev/bazelbuild/rules_py/examples/py_binary/BUILD.bazel:9:10: in py_binary rule //examples/py_binary:py_binary2: label '//examples/py_binary:py_binary' in $(location) expression expands to more than one file, please use $(locations //examples/py_binary:py_binary) instead.  Files (at most 5 shown) are: [bazel-out/aarch64-fastbuild/bin/examples/py_binary/py_binary, bazel-out/aarch64-fastbuild/bin/examples/py_binary/py_binary.venv.pth, examples/py_binary/say.py]

Version

Development (host) and target OS/architectures: ubuntu 22.04

Output of bazel --version: bazel 7.4.0

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: see repro case below

How to reproduce

On this branch: #456

bazel build :upstream_py_binary2 works fine
bazel build :py_binary2 fails with the above error

Any other information?

No response

@keith keith added the bug Something isn't working label Dec 2, 2024
keith added a commit to keith/rules_py that referenced this issue Dec 2, 2024
@mattem
Copy link
Collaborator

mattem commented Dec 5, 2024

The reason this works in rules_python is that they use an exposed internal method to expand the files, rather than the one on ctx, all Bazel built-in rules exhibit this behavior, iirc there's an open issue upstream for it.

That being said, it likely makes sense to remove the other outputs from files on DefaultInfo.

@keith
Copy link
Contributor Author

keith commented Dec 5, 2024

Will removing those extra files not break some other workflow?

keith added a commit to keith/rules_py that referenced this issue Dec 5, 2024
This mirrors rules_python to ensure that users can use `execpath` with a
py_binary target.

Fixes aspect-build#455
@keith keith linked a pull request Dec 5, 2024 that will close this issue
@keith
Copy link
Contributor Author

keith commented Dec 5, 2024

here's that change if not: #467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants