Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I unzip a file in bazel properly if I don't know the contents of the zip?

Tags:

bazel

I was to define a rule that unzips a given zip file. However, I don't know the contents of the zip, so I cannot specify outs in a genrule, for example. This seems like a common problem, and googling around leads me to people who have encountered similar scenarios, but I haven't yet seen a specific example of how to solve this.

I want something like:

genrule(
  name="unzip",
  src="file.zip",
  outs=glob(["**"]), # except you're not allowed to use glob here
  cmd = "unzip $(location file)",
)
like image 440
mathwiz Avatar asked Sep 20 '17 15:09

mathwiz


People also ask

How do I unzip data in Python?

Python3. # into a specific location. Import the zipfile module Create a zip file object using ZipFile class. Call the extract() method on the zip file object and pass the name of the file to be extracted and the path where the file needed to be extracted and Extracting the specific file present in the zip.


1 Answers

You could use a Workspace Rule to create a BUILD file for the zip that globs everything.

Something like this in your WORKSPACE file:

new_http_archive(
    name = "my_zip",
    url = "http://example.com/my_zip.zip",
    build_file_content = """
        filegroup(
            name = "srcs",
            srcs = glob(["*"]),
            visibility = ["//visibility:public"]
        )
    """
)

Then from a BUILD file you can reference this as an input using @my_zip//:srcs

like image 149
zlalanne Avatar answered Nov 22 '22 08:11

zlalanne