bazel - 是否有 Bazel 命令行来确定一个或多个给定标签的输出的绝对路径?
问题描述
我知道有,bazel info <...> bazel-bin
但这只是给出输出路径前缀。我希望有一些花哨cquery
或aquery
获得输出的完整路径。
解决方案
据我所知,没有简单的方法来获得它(请参阅下面的相关讨论),但如果您的目标是可运行的,您可以使用这个好技巧:
bazel run --run_under "echo" //path/to/folder:target
这将在磁盘上打印二进制文件的完整路径(在 bazel 缓存文件夹中)。
获取目标输出路径的更通用方法是通过aquery
,例如
bazel aquery "//path/to/folder:target" --noinclude_commandline --output=text
这将打印与给定目标相关的所有操作的输出(cc_binary
这些操作将包括目标文件、二进制文件、剥离的二进制文件等) - 然后您可以使用 grep 查找Outputs
并提取路径。
这是 a 的示例输出cc_binary
:
> bazel aquery "//path/to/folder:target" --noinclude_commandline --output=text
action 'Compiling path/to/folder/main.cc'
Mnemonic: CppCompile
Target: //path/to/folder:target
Configuration: k8-fastbuild
ActionKey: ...
Inputs: [..., path/to/folder/main.cc]
Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/main.pic.d,
bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/main.pic.o]
...
action 'Linking path/to/folder/target'
Mnemonic: CppLink
Target: //path/to/folder:target
Configuration: k8-fastbuild
ActionKey: ...
Inputs: [..., bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/main.pic.o, ...]
Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/target]
action 'Stripping path/to/folder/target.stripped for //path/to/folder:target'
Mnemonic: CcStrip
Target: //path/to/folder:target
Configuration: k8-fastbuild
ActionKey: ...
Inputs: [..., bazel-out/k8-fastbuild/bin/path/to/folder/target]
Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/target.stripped]
...
...
...
路径是相对的,但您可以通过使用bazel info workspace
.
如果您对特定操作的输出感兴趣,例如链接产生的最终二进制文件,您可以按助记符类型过滤:
> bazel aquery "mnemonic(CppLink, //path/to/folder:target)" --noinclude_commandline --output=text
action 'Linking path/to/folder/target'
Mnemonic: CppLink
Target: //path/to/folder:target
Configuration: k8-fastbuild
ActionKey: ...
Inputs: [..., bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/target.pic.o, ...]
Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/target]
不是一个完整的答案,但希望这会有所帮助。
其他相关讨论:
推荐阅读
- linux - 我需要一个 shell 脚本来响应 json 200 ok 以及正文信息
- sql-server - SQL Server 中的“void”类型是什么?
- python - 如何使用 Python 根据部分值将字典拆分为多个字典
- javascript - 我有一个包含多个对象的数组。我们可以根据条件创建新对象吗?
- moodle - 无法检索外部页面的用户 ID(moodle)
- azure - Azure Bot 返回“加载资源失败:服务器响应状态为 502(错误网关)”错误
- visual-studio - Visual Studio 2017 告诉我现在每次打开 IDE 时都可以使用 Visual Studio 2019 版本
- vba - 使用 VBA PowerPoint 引用幻灯片的字幕以进行格式化
- python - lib/pythonX.Y/no-global-site-packages.txt 的路径
- go - Go 包函数中的模拟函数