Skip to content

pkg_install: make callable from a symbolic macro#1069

Open
matx-sjacob wants to merge 1 commit into
bazelbuild:mainfrom
matx-sjacob:pkg-install-symbolic-macro-compat
Open

pkg_install: make callable from a symbolic macro#1069
matx-sjacob wants to merge 1 commit into
bazelbuild:mainfrom
matx-sjacob:pkg-install-symbolic-macro-compat

Conversation

@matx-sjacob
Copy link
Copy Markdown

Summary

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 <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?)

Fix

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.

Test plan

  • Verified the patch builds locally against a 1.2.0 pin where pkg_install is invoked from inside a symbolic macro (previously failed with the error above).
  • Confirm existing pkg_install-related tests still pass in CI.

`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.
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 27, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants