fix(pkg_install): resolve files against own repository (#1016) tl;dr: this change builds on #984 which introduced the `locate()` helper and the `runfiles` infrastructure. That PR fixed Windows compatibility by enabling runfiles-less operation; this change extends it to support cross-repository files. When a `pkg_install` rule in an external repository references files from another repository, the installer would fail at runtime by attempting to resolve all files relative to its repository rather than each file's own repository. Example failure (`extrepo`: external repository installing file from main repository): ``` bazel run @extrepo//:install -- --destdir=/tmp/test [...] FileNotFoundError: [Errno 2] No such file or directory: '.../runfiles/+_repo_rules+extrepo/some-path/extrepo/file-in-main-repo' ``` The file should be resolved against the main repository (`_main`) but is incorrectly looked up from the installer's repository (`+_repo_rules+extrepo`). The solution proposed here consists in extending the manifest to track each file's own repository and use this information during installation to resolve files against the correct repository. It adds a `repository` field to manifest entries using: - `Label.repo_name` ([canonical](https://bazel.build/rules/lib/builtins/Label#repo_name)) when explicitly valued for the source file, - otherwise `ctx.workspace_name` when no [owner](https://bazel.build/rules/lib/builtins/File#owner) or `Label.repo_name` is [empty](https://rules-python.readthedocs.io/en/latest/api/py/runfiles/runfiles.runfiles.html#runfiles.runfiles.Runfiles.CurrentRepository), denoting the main repository (`_main`, as before). Testing: - `//tests/install:install_test` includes new `CrossRepoInstallTest`, - `bazel run @extrepo//:install -- --destdir=/tmp/test` case works, - verified the above on Ubuntu Linux and Windows as well.
Bazel rules for building tar, zip, deb, and rpm for packages.
For the latest version, see Releases (with WORKSPACE setup) / Documentation
Use rules-pkg-discuss@googlegroups.com for discussion.
As of Bazel 4.x, Bazel uses this rule set for packaging its distribution. Bazel still contains a limited version of pkg_tar but its feature set is frozen. Any new capabilities will be added here.
Sample, but see releases for the current release.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_pkg", urls = [ "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", ], sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", ) load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies()
To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild( name = "rules_pkg_rpmbuild", verbose = False, )
bazel_dep(name = "rules_pkg", version = "0.0.10")
To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.
find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod") use_repo(find_rpm, "rules_pkg_rpmbuild") register_toolchains("@rules_pkg_rpmbuild//:all")
We hold an engineering status meeting on the first Monday of every month at 10am USA East coast time. Add to calendar / meeting notes