bazel-contrib / bazel-contrib/bazel-lib
[FR]: Better support for external directory files in copy_to_directory
- Dominant language
- Starlark
- Stars
- 182
- Forks
- 134
- Avg merge
- 1d 46m
- Merged PRs (30d)
- 1
Description
### What is the current behavior?
Here's a simple use case where I would like to copy an external folder from our `node_modules`:
`/dist/fonts` => `/material-design-icons-iconfont`.
Currently, I seem to be unable to figure out which combinations of props will give me the desired result. Let's say I use the package `material-design-icons-iconfont@6.7.0` the prefix would need to be hardcoded:
Currently:
```py
copy_to_directory(
name = "material-design-icons",
srcs = [
"//:node_modules/material-design-icons-iconfont/dir",
],
out = "material-design-icons-iconfont",
replace_prefixes = {
# copies an empty `node_modules` folder, not sure where this comes from
"node_modules": "",
# would expect to use $(location ...) here
"node_modules/.aspect_rules_js/material-design-icons-iconfont@6.7.0/node_modules/material-design-icons-iconfont/dist/fonts": "",
},
)
```
Expected:
```py
copy_to_directory(
name = "material-design-icons",
srcs = [
"//:node_modules/material-design-icons-iconfont/dir",
],
out = "material-design-icons-iconfont",
replace_prefixes = {
"$(location //:node_modules/material-design-icons-iconfont/dir)/dist/fonts": "",
},
)
# or
copy_to_directory(
name = "material-design-icons",
srcs = [
"//:node_modules/material-design-icons-iconfont/dir",
],
out = "material-design-icons-iconfont",
root_paths = [
"$(location //:node_modules/material-design-icons-iconfont/dir)",
],
replace_prefixes = {
"dist/fonts": "",
},
)
```
### Describe the feature
I would like to avoid having to compute the path to strip or hardcoding the value. Possibly there is a better way to approach this copy operation? I have tried using `root_paths` as well with no success, either way, it would be great to have a convenient way of performing this operation.
### Fund our work
- [ ] Sponsor our open source work by donating a [feature bounty](https://opencollective.com/aspect-build/)
Contributor guide
Research direction
Start at the copy_to_directory entry point and trace how root_paths and replace_prefixes handle external directories and location-expanded paths. Reproduce the material-design-icons example, then verify that the desired directory can be copied using a location-derived path without hardcoding the node_modules prefix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100