Skip to content

fix(pkg_install): resolve files against own repository#1016

Open
rdesgroppes wants to merge 1 commit intobazelbuild:mainfrom
rdesgroppes:fix-cross-repo-installs
Open

fix(pkg_install): resolve files against own repository#1016
rdesgroppes wants to merge 1 commit intobazelbuild:mainfrom
rdesgroppes:fix-cross-repo-installs

Conversation

@rdesgroppes
Copy link
Contributor

@rdesgroppes rdesgroppes commented Feb 5, 2026

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) when explicitly valued for the source file,
  • otherwise ctx.workspace_name when no owner or Label.repo_name is empty, denoting the main repository (the default, i.e. _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.

@rdesgroppes rdesgroppes force-pushed the fix-cross-repo-installs branch 2 times, most recently from b32049b to b560c25 Compare February 5, 2026 18:38
@rdesgroppes rdesgroppes marked this pull request as ready for review February 5, 2026 18:40
@rdesgroppes rdesgroppes force-pushed the fix-cross-repo-installs branch 3 times, most recently from 01b9089 to 4e7a79a Compare February 6, 2026 09:13
Copy link
Collaborator

@cgrindel cgrindel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@aiuto Do you want to take a look before we merge?

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.
@rdesgroppes rdesgroppes force-pushed the fix-cross-repo-installs branch from 4e7a79a to ed98f3d Compare February 8, 2026 06:10
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