问题
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)",
)
回答1:
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
来源:https://stackoverflow.com/questions/46326749/how-do-i-unzip-a-file-in-bazel-properly-if-i-dont-know-the-contents-of-the-zip