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

cquery --output=files returns _both_ src _and_ output file for py_binary #17703

Open
illicitonion opened this issue Mar 9, 2023 · 3 comments
Labels

Comments

@illicitonion
Copy link
Contributor

Description of the bug:

For this BUILD file:

py_binary(
    name = "pyb",
    srcs = ["pyb.py"],
)

This query produces both the source file and the output file:

% bazel cquery --output=files :pyb 2>/dev/null
pyb.py
bazel-out/darwin-fastbuild/bin/pyb

In this case, it feels like just the generated file should be output, not the source file?

(This was the behaviour in Bazel 5, and I'm aware it was changed at my request in #16602)

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

% touch WORKSPACE
% echo 6.1.0 > .bazelversion
% cat <<EOF >BUILD.bazel
py_binary(
    name = "pyb",
    srcs = ["pyb.py"],
)
EOF
% cat <<EOF >pyb.py
print("Hello")
EOF
% bazel cquery --output=files :pyb 2>/dev/null
pyb.py
bazel-out/darwin-fastbuild/bin/pyb

Expect that last command to instead act like this:

% bazel cquery --output=files :pyb 2>/dev/null
bazel-out/darwin-fastbuild/bin/pyb

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 6.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@illicitonion
Copy link
Contributor Author

cc @fmeum - sorry for not testing that PR thoroughly enough before...

@sgowroji sgowroji added type: bug team-Configurability platforms, toolchains, cquery, select(), config transitions untriaged labels Mar 9, 2023
@fmeum
Copy link
Collaborator

fmeum commented Mar 9, 2023

I think that this is a quirk in the Python rules rather than in the implementation of --output=files:

$ bazel cquery --output=starlark :pyb '--starlark:expr=providers(target)["FileProvider"].files_to_build' 2>/dev/null
depset([<source file pyb.py>, <generated file pyb>])

# TODO(b/208657718): Remove output_sources from the default outputs
# once the depot is cleaned up.
return executable, depset([executable] + output_sources)
seems related. @rickeylev, can you say more about this?

@rickeylev
Copy link
Contributor

Yeah, it's a undesirable quirk. It's been there a long time. I was never able to track down when it came about or why; my best guess is it is some holdover from a much earlier phase in Bazel's life when what a rule produced wasn't as well defined or controllable.

@gregestren gregestren added team-Rules-Python Native rules for Python and removed team-Configurability platforms, toolchains, cquery, select(), config transitions labels Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants