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)",
)
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With