fix(pkg_install): resolve files against own repository#1016
Open
rdesgroppes wants to merge 1 commit intobazelbuild:mainfrom
Open
fix(pkg_install): resolve files against own repository#1016rdesgroppes wants to merge 1 commit intobazelbuild:mainfrom
rdesgroppes wants to merge 1 commit intobazelbuild:mainfrom
Conversation
b32049b to
b560c25
Compare
01b9089 to
4e7a79a
Compare
tl;dr: this change builds on bazelbuild#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.
4e7a79a to
ed98f3d
Compare
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.
tl;dr: this change builds on #984 which introduced the
locate()helper and therunfilesinfrastructure. That PR fixed Windows compatibility by enabling runfiles-less operation; this change extends it to support cross-repository files.When a
pkg_installrule 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):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
repositoryfield to manifest entries using:Label.repo_name(canonical) when explicitly valued for the source file,ctx.workspace_namewhen no owner orLabel.repo_nameis empty, denoting the main repository (the default, i.e._main, as before).Testing:
//tests/install:install_testincludes newCrossRepoInstallTest,bazel run @extrepo//:install -- --destdir=/tmp/testcase works,