Skip to content

Add package_variables support to pkg_files and pkg_filegroup prefix#1052

Open
aiuto wants to merge 1 commit intobazelbuild:mainfrom
aiuto:vars_in_prefix
Open

Add package_variables support to pkg_files and pkg_filegroup prefix#1052
aiuto wants to merge 1 commit intobazelbuild:mainfrom
aiuto:vars_in_prefix

Conversation

@aiuto
Copy link
Copy Markdown
Collaborator

@aiuto aiuto commented Apr 16, 2026

Closes #781.

pkg_files and pkg_filegroup now accept a package_variables attribute, enabling make-variable substitution in their prefix attribute. For example:

my_platform_vars(name = "platform_vars", os = "linux", arch = "x86_64")

pkg_filegroup(
name = "platform_libs",
srcs = [":my_libs"],
prefix = "usr/lib/$(os)_$(arch)",
package_variables = ":platform_vars",
)

Previously the only workaround was select() on prefix, while package_file_name already supported variable substitution via package_variables. This closes the inconsistency: the same mechanism now works for destination paths in the mapping rules.

The implementation follows the same pattern as pkg_deb and pkg_tar, reusing substitute_package_variables() from //pkg/private:util.bzl.

Used Claude for the coding.

  • Admittedly this feature was too small (about 10 LoC) to use an agent, but it saved me time writing the tests.
  • I dropped in a CLAUDE.md for the next time. With reminders to do things like keep it linty and update the docs.

Closes bazelbuild#781.

pkg_files and pkg_filegroup now accept a package_variables attribute, enabling
make-variable substitution in their prefix attribute. For example:

my_platform_vars(name = "platform_vars", os = "linux", arch = "x86_64")

pkg_filegroup(
    name = "platform_libs",
    srcs = [":my_libs"],
    prefix = "usr/lib/$(os)_$(arch)",
    package_variables = ":platform_vars",
)

Previously the only workaround was select() on prefix, while package_file_name already supported variable substitution via package_variables. This closes the inconsistency: the same mechanism now works for destination paths in the mapping rules.

The implementation follows the same pattern as pkg_deb and pkg_tar, reusing substitute_package_variables() from //pkg/private:util.bzl.

- Admittedly this was too small to use an agent, but it saved me time writing the tests.
- I created a hints file for the next time.
@aiuto aiuto requested a review from cgrindel as a code owner April 16, 2026 04:32
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.

Support make variable substitution in prefix

1 participant