rules_pkg icon indicating copy to clipboard operation
rules_pkg copied to clipboard

Suggestion: Option to give a dictionary of srcs for easier folder arrangement

Open njlr opened this issue 3 years ago • 1 comments

I think the ergonomics of these rules could be greatly improved by allowing srcs to be a dictionary, where the keys are paths in the package (zip, tar, etc.) and the values are labels.

The behavior when a list is given as srcs would be unchanged.

For example, given this source-tree:

.
├── a
│   └── apple.txt
├── banana.txt
└── c
    └── h
        └── cherry.txt

And this rule:

pkg_zip(
  name = "test",
  srcs = {
    "apple/apple.txt": "a/apple.txt",
    "banana/banana.txt": "banana.txt",
    "cherry/cherry.txt": "c/h/cherry.txt",
  }
)

The tree in the zip would be:

.
├── apple
│   └── apple.txt
├── banana
│   └── banana.txt
└── cherry
    └── cherry.txt

Advantages

  • A very natural way to create complex folder structures
  • Not a breaking change (can test if a dictionary or list is provided)
  • This approach is already used successfully in Buck for C/C++ headers

Related: https://github.com/bazelbuild/rules_pkg/issues/354

njlr avatar Jul 05 '22 19:07 njlr

You can build complex structures with pkg_file rules. That gives more capability. This intermediate step does not thill me at all.

What is more interesting is if you could specify path remapping and ACL changes inline - something like

pkg_tar(...
  srcs = [
     files(path="apple/apple.txt", src="a/apple.txt", mode=0x755),
     files(path='bananna/bananna.txt', srcs= .....),
    ...
  ]
)

I think that could be much more expressive, and easier to read. Alas, that is not the direction bazel is moving towards. It is what we have in Blaze in Google, and are trying to move away from.

aiuto avatar Jul 17 '22 04:07 aiuto