如果我不知道zip的内容,如何在bazel中正确解压缩文件? [英] How do I unzip a file in bazel properly if I don't know the contents of the zip?
问题描述
我要定义一个规则来解压缩给定的zip文件.但是,我不知道zip的内容,因此,例如,我不能在genrule中指定outs
.这似乎是一个常见的问题,并且四处搜寻会导致我遇到类似情况的人,但是我还没有看到解决该问题的具体示例.
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.
我想要类似的东西:
genrule(
name="unzip",
src="file.zip",
outs=glob(["**"]), # except you're not allowed to use glob here
cmd = "unzip $(location file)",
)
推荐答案
您可以使用工作区规则,用于为所有内容压缩的zip文件创建一个BUILD
文件.
You could use a Workspace Rule to create a BUILD
file for the zip that globs everything.
WORKSPACE
文件中的类似内容
new_http_archive(
name = "my_zip",
url = "http://example.com/my_zip.zip",
build_file_content = """
filegroup(
name = "srcs",
srcs = glob(["*"]),
visibility = ["//visibility:public"]
)
"""
)
然后从BUILD
文件中,您可以使用@my_zip//:srcs
Then from a BUILD
file you can reference this as an input using @my_zip//:srcs
这篇关于如果我不知道zip的内容,如何在bazel中正确解压缩文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!