From 4e77c65ba67312507b4d72f988e90aaecb6fe819 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Fri, 8 Dec 2023 12:28:56 -0800 Subject: [PATCH 1/2] feat: introduce extension compression mapping --- lib/private/tar.bzl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/private/tar.bzl b/lib/private/tar.bzl index e1cc48f64..557857022 100644 --- a/lib/private/tar.bzl +++ b/lib/private/tar.bzl @@ -36,6 +36,18 @@ _ACCEPTED_COMPRESSION_TYPES = [ "zstd", ] +_COMPRESSION_TO_EXTENSION = { + "bzip2": ".tar.bz2", + "compress": ".tar.Z", + "gzip": ".tar.gz", + "lrzip": ".tar.lrz", + "lzma": ".tar.lzma", + "lz4": ".tar.lz4", + "lzop": ".tar.lzo", + "xz": ".tar.xz", + "zstd": ".tar.zst", +} + _tar_attrs = { "args": attr.string_list( doc = "Additional flags permitted by BSD tar; see the man page.", @@ -136,7 +148,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") @@ -238,6 +252,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, ), ) From 9e4f5cf50468336bc95e4fa475c99f2f7dd0a1d2 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Fri, 8 Dec 2023 13:46:58 -0800 Subject: [PATCH 2/2] nit --- lib/private/tar.bzl | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/private/tar.bzl b/lib/private/tar.bzl index 557857022..707d17a2d 100644 --- a/lib/private/tar.bzl +++ b/lib/private/tar.bzl @@ -23,31 +23,21 @@ _ACCEPTED_EXTENSIONS = [ ".tzst", # zstd ] -# https://www.gnu.org/software/tar/manual/html_section/Compression.html -_ACCEPTED_COMPRESSION_TYPES = [ - "bzip2", - "compress", - "gzip", - "lrzip", - "lz4", - "lzma", - "lzop", - "xz", - "zstd", -] - _COMPRESSION_TO_EXTENSION = { "bzip2": ".tar.bz2", "compress": ".tar.Z", "gzip": ".tar.gz", "lrzip": ".tar.lrz", - "lzma": ".tar.lzma", "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 = _COMPRESSION_TO_EXTENSION.keys() + _tar_attrs = { "args": attr.string_list( doc = "Additional flags permitted by BSD tar; see the man page.",