pkg_install: make callable from a symbolic macro#1069
Open
matx-sjacob wants to merge 1 commit into
Open
Conversation
`pkg_install` wires its internal `_pkg_install_script` rule to a
`py_binary` via the script's *output filename*:
py_binary(
name = name,
srcs = [":" + name + "_install_script"],
main = name + "_install_script.py", # <-- file-name-as-label
...
)
`_pkg_install_script` declared that file at analysis time via
`ctx.actions.declare_file(...)`, so the file `<name>_install_script.py`
existed only as an artifact in the rule's `DefaultInfo` — no
loading-time package label was ever registered for it. Legacy macros
tolerated the file-name-as-label shortcut, but in a symbolic macro,
label references must resolve to real loading-time targets in scope.
Bazel errors with:
no such target '//pkg:<name>_install_script.py': target
'<name>_install_script.py' not declared in package '<pkg>'
(did you mean <name>_install_script?)
Promote the script file to a predeclared output via `attr.output()`.
The caller passes `out = <name>_install_script.py`, which registers
`//pkg:<name>_install_script.py` as a real package label at loading
time. `py_binary.main` can then resolve that label in any macro
scope, and the rule impl reads the file through `ctx.outputs.out`
instead of `ctx.actions.declare_file`. No change to the user-facing
`pkg_install` API.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
cgrindel
approved these changes
May 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pkg_installwires its internal_pkg_install_scriptrule to apy_binaryvia the script's output filename:_pkg_install_scriptdeclared that file at analysis time viactx.actions.declare_file(...), so<name>_install_script.pyexisted only as an artifact in the rule'sDefaultInfo— no loading-time package label was ever registered for it. Legacy macros tolerated the file-name-as-label shortcut, but in a symbolic macro, label references must resolve to real loading-time targets in scope. Bazel errors with:Fix
Promote the script file to a predeclared output via
attr.output(). The caller passesout = <name>_install_script.py, which registers//pkg:<name>_install_script.pyas a real package label at loading time.py_binary.maincan then resolve that label in any macro scope, and the rule impl reads the file throughctx.outputs.outinstead ofctx.actions.declare_file. No change to the user-facingpkg_installAPI.Test plan
pkg_installis invoked from inside a symbolic macro (previously failed with the error above).pkg_install-related tests still pass in CI.