Skip to content

Conversation

@rdesgroppes
Copy link
Contributor

@rdesgroppes rdesgroppes commented Jan 19, 2026

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.

@rdesgroppes rdesgroppes force-pushed the make-pkg_files-auto-strip-prefix branch 7 times, most recently from ce924b0 to 7c12bd3 Compare January 19, 2026 11:38
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. It looks like there is a pre-commit failure. Please ping us when it is addressed.

@rdesgroppes rdesgroppes force-pushed the make-pkg_files-auto-strip-prefix branch 3 times, most recently from a57cbf2 to 4a5fabb Compare January 25, 2026 00:24
@rdesgroppes
Copy link
Contributor Author

rdesgroppes commented Jan 25, 2026

LGTM. It looks like there is a pre-commit failure. Please ping us when it is addressed.

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 test_referencing_remote_file is because it now has 5+ statements.

@rdesgroppes rdesgroppes force-pushed the make-pkg_files-auto-strip-prefix branch from 4a5fabb to d4de47b Compare January 25, 2026 17:34
@rdesgroppes
Copy link
Contributor Author

rdesgroppes commented Jan 25, 2026

Had to document ǹame as well, sorry...

@cgrindel
Copy link
Collaborator

@aiuto Do you want to review before we merge?

@aiuto
Copy link
Collaborator

aiuto commented Jan 26, 2026

I don't understand the behavior diff for the same workspace, inter package thing.
Is this a potentially breaking change in any way?

@rdesgroppes rdesgroppes force-pushed the make-pkg_files-auto-strip-prefix branch 2 times, most recently from c9b8282 to b64bcc8 Compare January 26, 2026 13:17
@rdesgroppes rdesgroppes changed the title feat(pkg_files): auto-strip external package prefix feat(pkg_files): preserve external package paths by default Jan 26, 2026
@rdesgroppes
Copy link
Contributor Author

I don't understand the behavior diff for the same workspace, inter package thing. Is this a potentially breaking change in any way?

I've done my best to exemplify the change with further tests and added the following note to the commit message/PR description:

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.

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.
@rdesgroppes rdesgroppes force-pushed the make-pkg_files-auto-strip-prefix branch from b64bcc8 to 8bbb77d Compare January 26, 2026 13:22
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