bazel icon indicating copy to clipboard operation
bazel copied to clipboard

@bazel_tools//tools/zip:zipper: allow glob exclusion to prevent files from being extracted from a zip file

Open bendavini opened this issue 1 year ago • 8 comments

Description of the feature request:

unzip (https://infozip.sourceforge.net/) allows users to specify files to exclude while unzipping a file:

unzip file.zip -x $(<excl_file.txt)

In order to use zipper x in a similar way, a user needs to perform some additional shell magic to get the same result (we've a full (currently non-hermetic) unzip.bzl that uses system unzip to achieve this.)

Which category does this issue belong to?

CLI, Core

What underlying problem are you trying to solve with this feature?

Make zipper's extract (x) functionally equivalent to the widely-used unzip utility

Which operating system are you running Bazel on?

Mac(x86/aarch64) / Linux (x86)

What is the output of bazel info release?

7.2.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No. Have scoured slack, github, email threads, and our internal tools

Any other information, logs, or outputs that you want to share?

No response

bendavini avatar Sep 18 '24 16:09 bendavini

AIUI @bazel_tools//tools/zip:zipper is not meant to be a general-purpose zip utility, just one that caters to the needs of build rules built into Bazel. What's the use case for this?

tjgq avatar Sep 18 '24 16:09 tjgq

TL;DR we want to be able to extract (a subset of) files from a zip archive in a way that is consumable by other actions (mostly rules_pkg).

I asked here what is the most proper way to hermetically unzip things; the answer was to use zipper .

The use case is described in the first link. We have a custom rule which is a wrapper around a non-hermetic unzip command that provides an alternative to a genrule that does not require the list of files to be extracted.

If @bazel_tools//tools/zip:zipper is not meant to be a general purpose zip utility, do you know of something that is (and is also hermetic)?

bendavini avatar Sep 18 '24 19:09 bendavini

https://registry.bazel.build/modules/ape has cross-platform binaries for common utilities, including unzip.

fmeum avatar Sep 18 '24 21:09 fmeum

Thanks @fmeum ! Learn about a new module every day :)

I am happy to use a new module, but would prefer to lean on a built-in if possible. If zipper is meant to be exclusive to bazel internals, should I file another ticket to make it be 'advertised' as such? (i.e., something like a readme recommending the APE module for cases like this, reduced visibility of zipper, output of said information in the help, etc.

bendavini avatar Sep 19 '24 13:09 bendavini

@lberki @meteorcloudy Do we have a stance on expanding the scope of @bazel_tools//tools/zip:zipper and/or intentionally supporting its use outside of built-in rules?

tjgq avatar Sep 19 '24 14:09 tjgq

@tjgq @bendavini @ahumesky I'd much, much rather no one use that built-in zipper tool. It was added in support of Android rules, which are in the process of being removed from the Bazel proper and thus ideally, this binary would also vanish from @bazel_tools.

lberki avatar Sep 19 '24 14:09 lberki

team-Core has no involvement or expertise with @bazel_tools//tools/zip:zipper

haxorz avatar Oct 10 '24 21:10 haxorz

Do we have a stance on expanding the scope of @bazel_tools//tools/zip:zipper and/or intentionally supporting its use outside of built-in rules?

Definitely not, we want to shrink the size of @bazel_tools as much as possible. One day, we may want to even remove it from Bazel builtins.

meteorcloudy avatar Oct 11 '24 09:10 meteorcloudy

Since our position is that we don't want to expand scope for @bazel_tools//tools/zip:zipper (and possibly even get rid of it in the future), let's close this. Rulesets needing zip functionality should ship their own tool or import it from elsewhere.

tjgq avatar Oct 22 '24 11:10 tjgq