bazelbuild / bazelbuild/rules_pkg
pkg_files(strip_prefix) behavior is confusing w.r.t. flattening a tree of files
- Dominant language
- Starlark
- Stars
- 253
- Forks
- 221
- Avg merge
- 10h 33m
- Merged PRs (30d)
- 1
Description
Example file tree
```
BUILD
docs/BUILD
docs/index.md
docs/reference/index.md
```
**docs/BUILD**
`filegroup(name = "docs", srcs = glob(["**/*"]))`
**BUILD**
```
pkg_files(
name = "share_doc",
srcs = [
"//docs",
],
strip_prefix = strip_prefix.from_pkg(),
prefix = "usr/share/doc/foo",
)
```
This gives the output I expect - that the directory tree is preserved.
```
usr/share/doc/foo/index.md
usr/share/doc/foo/reference/
usr/share/doc/foo/reference/index.md
```
But.... if I do not have `strip_prefix`, `pkg_files` flattens the tree and I get the error. `Error in fail: After renames, multiple sources (at least docs/index.md, docs/reference/index.md) map to the same destination. Consider adjusting strip_prefix and/or renames`
This might be a carry over from legacy behavior, but it is strange and confusing.
# Proposal
- `pkg_files` adds an attribute `squash_tree` bool, default=False which controls squashing the tree.
- strip prefix and any name filtering are applied first, then the results are squashed if squash_tree=False.
Contributor guide
Assessment
This issue has not been assessed yet.