Skip to content

pkg_files(strip_prefix) behavior is confusing w.r.t. flattening a tree of files #354

@aiuto

Description

@aiuto

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.

Metadata

Metadata

Assignees

Labels

P1An issue that must be resolved. Must have an assigneebreaking change

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions