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

痞子三分冷 提交于 2019-12-12 19:59:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!