How to get WORKSPACE directory in bazel rule

后端 未结 3 901
渐次进展
渐次进展 2021-01-15 04:12

I order to use clang tools like clang-format, clang-tidy or generate a compilation database like this, I need to know the WORKSPACE directory withi

3条回答
  •  猫巷女王i
    2021-01-15 04:19

    You can probably get around this by using realpath. Something like:

    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),
        }
    )
    

    Note the execution_requirements to get around the potential issues in my comment above.

提交回复
热议问题