bazel-contrib / bazel-lib

Common useful functions for writing BUILD files and Starlark macros/rules
Apache License 2.0
141 stars 91 forks source link

[FR]: Add `add_package_dirs` option to `mtree_mutate` #902

Open maxitg opened 3 months ago

maxitg commented 3 months ago

What is the current behavior?

Currently, mtree_mutate wouldn't add new directories specified by package_dir, as it only appends it to existing lines.

However, if, e.g., package_dir is /opt/app, there will be no entries for opt or opt/app. As a result, in some cases, e.g., if the tar archive is used for a DEB package, the package installation would fail with an error like this:

error creating directory 'opt/app/app_data': No such file or directory

This is different from the behavior of pkg_tar from rules_pkg.

Describe the feature

I suggest to add an add_package_dirs option to mtree_mutate, which would add lines such as

opt uid=0 gid=0 time=1672560000 mode=0755 type=dir
opt/app uid=0 gid=0 time=1672560000 mode=0755 type=dir

to the beginning of the mtree, using custom mtree, owner, and ownername if specified.

I can make a PR if there are no objections.

thesayyn commented 4 weeks ago

That sounds reasonable, go for it.

thesayyn commented 4 weeks ago

We don't even need an attribute IMO, it should just create the directory just in case.