From a538f35e25d2e19f670152e4878cadef8f2ca399 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 27 Jun 2024 09:21:35 +0100 Subject: [PATCH 1/2] feat: added compression level support --- bzip2/compress/rule.bzl | 8 ++++++++ e2e/MODULE.bazel.lock | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bzip2/compress/rule.bzl b/bzip2/compress/rule.bzl index f14fef7..06a00ee 100644 --- a/bzip2/compress/rule.bzl +++ b/bzip2/compress/rule.bzl @@ -6,6 +6,7 @@ DOC = """Compresses a file with the Burrows-Wheeler (`bzip2`) algorithm. bzip2_compress( name = "compress", src = "some/file.txt", + level = 1-9, ) ``` """ @@ -16,6 +17,12 @@ ATTRS = { mandatory = True, allow_single_file = True, ), + "level": attr.int( + doc = "The compression level.", + mandatory = False, + default = 5, + values = [l for l in range(1, 10)], + ), "_template": attr.label( default = "@rules_coreutils//coreutils/redirect:stdout", allow_single_file = True, @@ -40,6 +47,7 @@ def implementation(ctx): args = ctx.actions.args() args.add(bzip2.executable.path) args.add("-czfk").add(ctx.file.src) + args.add("-{}".format(ctx.attr.level)) ctx.actions.run( outputs = [output], diff --git a/e2e/MODULE.bazel.lock b/e2e/MODULE.bazel.lock index 8ac1745..f763372 100644 --- a/e2e/MODULE.bazel.lock +++ b/e2e/MODULE.bazel.lock @@ -10714,7 +10714,7 @@ "moduleExtensions": { "@@ape~1.0.0-beta.6//:MODULE.bazel%_repo_rules": { "general": { - "bzlTransitiveDigest": "7dmOqqm4azSAaOhBklUWLfQ6Db4qFiDpOgYBZF3yvig=", + "bzlTransitiveDigest": "WUdXC90lZZSXHYtKyCMn3+hL9HDr0CmF+mN296XUkf4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { -- GitLab From 25cd302f96b47f0339e0541c8c8c6198efff6a3c Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 27 Jun 2024 11:14:55 +0100 Subject: [PATCH 2/2] chore: added tests for compression level --- e2e/bzip2/level/BUILD.bazel | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 e2e/bzip2/level/BUILD.bazel diff --git a/e2e/bzip2/level/BUILD.bazel b/e2e/bzip2/level/BUILD.bazel new file mode 100644 index 0000000..8e2a57c --- /dev/null +++ b/e2e/bzip2/level/BUILD.bazel @@ -0,0 +1,21 @@ +load("@rules_bzip2//bzip2/compress:defs.bzl", "bzip2_compress") +load("@rules_bzip2//bzip2/decompress:defs.bzl", "bzip2_decompress") +load("@rules_diff//diff/file/test:defs.bzl", "diff_file_test") + +bzip2_compress( + name = "compress", + src = "//fixture:hello-world.txt", + level = 1, +) + +bzip2_decompress( + name = "decompress", + src = ":compress", +) + +diff_file_test( + name = "bzip2", + size = "small", + a = "//fixture:hello-world.txt", + b = ":decompress", +) -- GitLab