feat(pkg_files): preserve external package paths by default#1004
feat(pkg_files): preserve external package paths by default#1004rdesgroppes wants to merge 1 commit intobazelbuild:mainfrom
Conversation
ce924b0 to
7c12bd3
Compare
cgrindel
left a comment
There was a problem hiding this comment.
LGTM. It looks like there is a pre-commit failure. Please ping us when it is addressed.
a57cbf2 to
4a5fabb
Compare
Indeed, I saw https://github.com/bazelbuild/rules_pkg/actions/runs/21136051279/job/61362936971#step:3:156 Done. I think the reason why I had to add a docstring to |
4a5fabb to
d4de47b
Compare
|
Had to document |
|
@aiuto Do you want to review before we merge? |
|
I don't understand the behavior diff for the same workspace, inter package thing. |
c9b8282 to
b64bcc8
Compare
I've done my best to exemplify the change with further tests and added the following note to the commit message/PR description:
|
When no explicit `strip_prefix` is specified, `pkg_files` now automatically
preserves package-relative paths for cross-package and cross-repository
references.
This eliminates the need for manual `strip_prefix` configurations in these
common scenarios.
**Cross-repository example:**
`@external//pkg` → `@//tests:my_files` (contains `tests/testdata/file.txt`)
| `strip_prefix` | Result |
|-----------------------------------|---------------------|
| `strip_prefix.from_root("tests")` | `testdata/file.txt` |
| `strip_prefix.from_pkg()` | `testdata/file.txt` |
| `None` (earlier default behavior) | `file.txt` |
| `None` (new default behavior) | testdata/file.txt` |
**Cross-package example:**
`//pkg_a` → `//pkg_b:my_files` (contains `pkg_b/subdir/file.txt`)
| `strip_prefix` | Result |
|-----------------------------------|-------------------|
| `strip_prefix.from_root("pkg_b")` | `subdir/file.txt` |
| `strip_prefix.from_pkg()` | `subdir/file.txt` |
| `None` (earlier default behavior) | `file.txt` |
| `None` (new default behavior) | `subdir/file.txt` |
Backward compatibility: since direct cross-package target references now
preserve package paths instead of basename only, referencing files in a
local `filegroup` aggregating cross-package files would bring back
basename-only paths.
b64bcc8 to
8bbb77d
Compare
|
I think I'm going to abandon this PR because I realize there's quite a number of issues reported on the current API:
... so my change would probably lead to more confusion. Sorry, but thanks for having taken the time to consider it. |
When no explicit
strip_prefixis specified,pkg_filesnow automatically preserves package-relative paths for cross-package and cross-repository references.This eliminates the need for manual
strip_prefixconfigurations in these common scenarios.Cross-repository example:
@external//pkg→@//tests:my_files(containstests/testdata/file.txt)strip_prefixstrip_prefix.from_root("tests")testdata/file.txtstrip_prefix.from_pkg()testdata/file.txtNone(earlier default behavior)file.txtNone(new default behavior)testdata/file.txtCross-package example:
//pkg_a→//pkg_b:my_files(containspkg_b/subdir/file.txt)strip_prefixstrip_prefix.from_root("pkg_b")subdir/file.txtstrip_prefix.from_pkg()subdir/file.txtNone(earlier default behavior)file.txtNone(new default behavior)subdir/file.txtBackward compatibility: since direct cross-package target references now preserve package paths instead of basename only, referencing files in a local
filegroupaggregating cross-package files would bring back basename-only paths.