Bazel 将 py_binary 输出复制到本地

发布于 2025-01-20 18:49:45 字数 543 浏览 1 评论 0原文

如何将 bazel run 中生成的文件复制到 Bazel 中的本地目录?该文件在 ~/sample_repo/bazel-out/local-fastbuild/bin/gen_file.runfiles/sample_repo/some_dir/output.txt 中生成。我想将该文件复制到与本地构建文件相同的目录(例如 ~/sample_repo/output.txt)以签入 VCS。下面是我的 BUILD 文件和 python 脚本。

构建

py_binary(
    name = "gen_file",
    srcs = ["gen_file.py"],
)

gen_file.py

with open('some_dir/output.txt', 'w+') as f:
    f.write('some text')

How do I copy files generated in bazel run to my local directory in Bazel? The file is generated in ~/sample_repo/bazel-out/local-fastbuild/bin/gen_file.runfiles/sample_repo/some_dir/output.txt. I want to copy that file to the same directory as my BUILD file in local (eg. ~/sample_repo/output.txt) for check in to VCS. Below are my BUILD file and the python script.

BUILD

py_binary(
    name = "gen_file",
    srcs = ["gen_file.py"],
)

gen_file.py

with open('some_dir/output.txt', 'w+') as f:
    f.write('some text')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文