简体   繁体   English

Bazel存储库规则-在repository_ctx.execute中下载文件

[英]Bazel repository rule- downloading a file in repository_ctx.execute

I have a java test I'm trying to sandbox which does somewhat of a complex download logic. 我有一个Java测试,我正在尝试对某些复杂的下载逻辑进行沙箱测试。
I'm thinking of writing a repository rule which will just start a java app using repository_ctx.execute to run this logic instead of duplicating it in skylark. 我正在考虑编写一个存储库规则,该规则将使用repository_ctx.execute启动一个Java应用程序来运行此逻辑,而不是在云雀中复制它。

How should I get the contents of this call? 我应该如何获得此通话的内容?
I can pass the java app a path/filename to download the file to but then I'm not sure what path to give it. 我可以通过Java应用程序传递路径/文件名来下载文件,但是我不确定该给它什么路径。 I can maybe have that print the bytes to stdout and collect them via the exec_result (sounds horrible). 我也许可以将字节打印到stdout并通过exec_result收集它们(听起来很恐怖)。

You can use repository_ctx.path("path/to/file") that returns a path to get a path relative to the generated workspace, then using path.realpath you can get a canonical name for the output. 您可以使用repository_ctx.path("path/to/file")返回一个路径,以获取相对于所生成工作空间的路径,然后使用path.realpath可以获取输出的规范名称。

Collecting the output of exec_result to use as a file input should work but it was never tried to my knowledge so there might be weird encoding issue happening. 收集exec_result的输出以用作文件输入应该可以,但是据我所知从未尝试过,因此可能发生奇怪的编码问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM