Skip to content

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

Merged
aiuto merged 1 commit intobazelbuild:mainfrom
rdesgroppes:fix-cross-repo-installs
Feb 10, 2026
Merged

fix(pkg_install): resolve files against own repository#1016
aiuto merged 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
Copy link
Collaborator

@aiuto aiuto left a comment

Choose a reason for hiding this comment

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

no time to look. I presume Chuck did.

@aiuto aiuto merged commit 42b7e61 into bazelbuild:main Feb 10, 2026
6 checks passed
@rdesgroppes rdesgroppes deleted the fix-cross-repo-installs branch February 10, 2026 06:19
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Feb 10, 2026
### What does this PR do?
Remove `copy_file` workaround for cross-repo file references from
`nghttp2` build by updating `rules_pkg` to the latest main that
includes our fix:
- bazelbuild/rules_pkg#1016.

### Motivation
The workaround was needed because `rules_pkg` was incorrectly
calculating paths for cross-repo references.

### Describe how you validated your changes
```
bazel run @nghttp2//:install -- --destdir=/tmp/xxx
```
Output files are identical before and after changes.
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Feb 10, 2026
### What does this PR do?
Remove `copy_file` workaround for cross-repo file references from
`nghttp2` build by updating `rules_pkg` to the latest main that
includes our fix:
- bazelbuild/rules_pkg#1016.

### Motivation
The workaround was needed because `rules_pkg` was incorrectly
calculating paths for cross-repo references.

### Describe how you validated your changes
```
bazel run @nghttp2//:install -- --destdir=/tmp/xxx
```
Output files are identical before and after changes.
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Feb 10, 2026
### What does this PR do?
Remove `copy_file` workaround for cross-repo file references from
`nghttp2` build by updating `rules_pkg` to the latest main that
includes our fix:
- bazelbuild/rules_pkg#1016.

### Motivation
The workaround was needed because `rules_pkg` was incorrectly
calculating paths for cross-repo references.

### Describe how you validated your changes
```
bazel run @nghttp2//:install -- --destdir=/tmp/xxx
```
Output files are identical before and after changes.
gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/datadog-agent that referenced this pull request Feb 11, 2026
### What does this PR do?
Remove `copy_file` workaround for cross-repo file references from `nghttp2` build by updating `rules_pkg` to the latest main that includes our fix:
- bazelbuild/rules_pkg#1016.

### Motivation
The workaround was needed because `rules_pkg` was incorrectly calculating paths for cross-repo references.

### Describe how you validated your changes
```
bazel run @nghttp2//:install -- --destdir=/tmp/xxx
```
Output files are identical before and after changes.

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
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.

3 participants