bazel-lib icon indicating copy to clipboard operation
bazel-lib copied to clipboard

[FR]: Support Expanding a filegroup via a rule

Open Aghassi opened this issue 1 year ago • 2 comments

What is the current behavior?

There is no rule for this.

Describe the feature

I'm in the unique position where I need to expand an npm package and copy each individual file out of the package from external to another place in my WORKSPACE. If I were to use copy_to_directory, I can move the files around but I lose the granularity of each file and Bazel only sees a directory when I pass to ts_project. This means that I can't use that rule to bulk move files around.

I found this stackoverflow from a few years back that outlines a simple approach where in you can pass a filegroup to this rule and it makes an output for each file in the output group. https://stackoverflow.com/a/57983629

Having this be in bazel-lib would be fairly useful because then I can add a filegroup to the npm package which I then reference and expand anywhere. Going one step further, I expect replace_prefix or similar to exist on the rule such that I can strip out part of the source path and rewrite it for the destination path. e.g. if my source path is external/my_package/package/src I would want to rewrite it to my_package/src

Aghassi avatar Mar 14 '24 22:03 Aghassi

I think you're just looking for https://github.com/bazelbuild/bazel-skylib/blob/main/rules/select_file.bzl ? with some list comprehension to select more than one file.

alexeagle avatar Mar 29 '24 18:03 alexeagle

Maybe? Do you have an example of that doing what I described? That looks like it is just used to select files but not move them around. Maybe I'm misunderstanding the docs.

Aghassi avatar Apr 06 '24 16:04 Aghassi