Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce extension compression mapping #683

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions lib/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ _ACCEPTED_EXTENSIONS = [
".tzst", # zstd
]

_COMPRESSION_TO_EXTENSION = {
thesayyn marked this conversation as resolved.
Show resolved Hide resolved
"bzip2": ".tar.bz2",
"compress": ".tar.Z",
"gzip": ".tar.gz",
"lrzip": ".tar.lrz",
"lz4": ".tar.lz4",
"lzma": ".tar.lzma",
"lzop": ".tar.lzo",
"xz": ".tar.xz",
"zstd": ".tar.zst",
}

# https://www.gnu.org/software/tar/manual/html_section/Compression.html
_ACCEPTED_COMPRESSION_TYPES = [
"bzip2",
"compress",
"gzip",
"lrzip",
"lz4",
"lzma",
"lzop",
"xz",
"zstd",
]
_ACCEPTED_COMPRESSION_TYPES = _COMPRESSION_TO_EXTENSION.keys()

_tar_attrs = {
"args": attr.string_list(
Expand Down Expand Up @@ -136,7 +138,9 @@ def _tar_impl(ctx):
# Compression args
_add_compression_args(ctx.attr.compress, args)

out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ".tar")
ext = _COMPRESSION_TO_EXTENSION[ctx.attr.compress] if ctx.attr.compress else ".tar"

out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ext)
args.add("--file", out)

args.add(ctx.file.mtree, format = "@%s")
Expand Down Expand Up @@ -238,6 +242,7 @@ tar_lib = struct(
common = struct(
accepted_tar_extensions = _ACCEPTED_EXTENSIONS,
accepted_compression_types = _ACCEPTED_COMPRESSION_TYPES,
compression_to_extension = _COMPRESSION_TO_EXTENSION,
add_compression_args = _add_compression_args,
),
)
Expand Down