我命令使用 clang 工具,例如clang-format
, clang-tidy
或生成一个编译数据库 like this,我需要知道 .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),
}
)
# BUILD
echo_full_path(
name = "echo",
srcs = glob(["src/**/*.cc"])
)
有没有更干净/更好的方法来做到这一点?
您可能可以通过使用来解决这个问题realpath
。就像是:
def _impl(ctx):
ctx.actions.run_shell(
inputs = ctx.files.srcs,
outputs = [ctx.outputs.executable],
command = "\n".join(["echo echo $(realpath \"%s\") >> %s" % (f.path,
ctx.outputs.executable.path) for f in ctx.files.srcs]),
execution_requirements = {
"no-sandbox": "1",
"no-cache": "1",
"no-remote": "1",
"local": "1",
},
)
echo_full_path = rule(
implementation=_impl,
executable=True,
attrs={
"srcs": attr.label_list(allow_files=True),
}
)
请注意execution_requirements
解决我上面评论中的潜在问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)