我为了使用像这样的 clang 工具clang-format,clang-tidy或者生成这样的编译数据库,我需要知道 .bzl 文件中的 WORKSPACE 目录。我怎样才能获得它?考虑以下示例,我只想打印工作区中所有 src 文件的完整路径:
# simple_example.bzl
def _impl(ctx):
workspace_dir = // ---> what comes here? <---
command = "\n".join([echo %s/%s" % (workspace_dir, f.short_path)
for f in ctx.files.srcs])
ctx.actions.write(
output=ctx.outputs.executable,
content=command,
is_executable=True)
echo_full_path = rule(
implementation=_impl,
executable=True,
attrs={
"srcs": attr.label_list(allow_files=True),
}
)
Run Code Online (Sandbox Code Playgroud)
# BUILD
echo_full_path(
name = "echo",
srcs = glob(["src/**/*.cc"])
)
Run Code Online (Sandbox Code Playgroud)
有没有更干净/更好的方法来做到这一点?
bazel ×1