General-purpose rule to create tar archives.
Unlike pkg_tar from rules_pkg this:
We also provide full control for tar'ring binaries including their runfiles.
The mtree_spec rule can be used to create an mtree manifest for the tar file. Then you can mutate that spec, as it's just a simple text file, and feed the result as the mtree attribute of the tar rule.
For example, to set the uid property, you could:
mtree_spec( name = "mtree", srcs = ["//some:files"], ) genrule( name = "change_owner", srcs = ["mtree"], outs = ["mtree.mutated"], cmd = "sed 's/uid=0/uid=1000/' <$< >$@", ) tar( name = "tar", srcs = ["//some:files"], mtree = "change_owner", )
Note: We intend to contribute mutation features to https://github.com/vbatts/go-mtree to provide a richer API for things like strip_prefix. In the meantime, see the lib/tests/tar/BUILD.bazel file in this repo for examples.
TODO:
mtree_spec(<a href="#mtree_spec-name">name</a>, <a href="#mtree_spec-out">out</a>, <a href="#mtree_spec-srcs">srcs</a>)
Create an mtree specification to map a directory hierarchy. See https://man.freebsd.org/cgi/man.cgi?mtree(8)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| out | Resulting specification file to write | Label | optional | |
| srcs | Files that are placed into the tar | List of labels | required |
tar_rule(<a href="#tar_rule-name">name</a>, <a href="#tar_rule-args">args</a>, <a href="#tar_rule-compress">compress</a>, <a href="#tar_rule-mode">mode</a>, <a href="#tar_rule-mtree">mtree</a>, <a href="#tar_rule-out">out</a>, <a href="#tar_rule-srcs">srcs</a>)
Rule that executes BSD tar. Most users should use the tar macro, rather than load this directly.
ATTRIBUTES
tar(<a href="#tar-name">name</a>, <a href="#tar-mtree">mtree</a>, <a href="#tar-stamp">stamp</a>, <a href="#tar-kwargs">kwargs</a>)
Wrapper macro around tar_rule.
mtree provides the “specification” or manifest of a tar file. See https://man.freebsd.org/cgi/man.cgi?mtree(8) Because BSD tar doesn't have a flag to set modification times to a constant, we must always supply an mtree input to get reproducible builds. See https://reproducible-builds.org/docs/archives/ for more explanation.
By default, mtree is “auto” which causes the macro to create an mtree_spec rule.
mtree may be supplied as an array literal of lines, e.g.
mtree =[
"usr/bin uid=0 gid=0 mode=0755 type=dir",
"usr/bin/ls uid=0 gid=0 mode=0755 time=0 type=file content={}/a".format(package_name()),
],
For the format of a line, see “There are four types of lines in a specification” on the man page for BSD mtree, https://man.freebsd.org/cgi/man.cgi?mtree(8)
mtree may be a label of a file containing the specification lines.PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | name of resulting tar_rule | none |
| mtree | “auto”, or an array of specification lines, or a label of a file that contains the lines. Subject to $(location) and “Make variable” substitution. | “auto” |
| stamp | should mtree attribute be stamped | 0 |
| kwargs | additional named parameters to pass to tar_rule | none |
tar_lib.implementation(<a href="#tar_lib.implementation-ctx">ctx</a>)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| ctx | - | none |
tar_lib.mtree_implementation(<a href="#tar_lib.mtree_implementation-ctx">ctx</a>)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| ctx | - | none |
tar_lib.common.add_compression_args(<a href="#tar_lib.common.add_compression_args-compress">compress</a>, <a href="#tar_lib.common.add_compression_args-args">args</a>)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| compress | - | none |
| args | - | none |