Skip to content

executing $(location my_tool) in a genrule doesn't work if it's in the same folder #347

@bsilver8192

Description

@bsilver8192

$(location a_tool) in the cmd of a genrule doesn't add a leading ./ if the tool is in the same package, which means it doesn't work. Whether a_tool is a target or a source file doesn't seem to matter.

Example BUILD (test_tool is an empty shell script):

genrule(
  name = 'my_genrule',
  tools = [
    'test_tool',
  ],
  outs = [
    'test_output',
  ],
  cmd = '$(location test_tool) > $(location test_output)',
)

I end up with this error:

$ bazel build ... --verbose_failures
INFO: Found 1 target...
INFO: From Executing genrule //:my_genrule:
/bin/bash: test_tool: command not found
ERROR: /tmp/tool_test_workspace/BUILD:1:1: Executing genrule //:my_genrule failed: bash failed: error executing command 
  (cd /home/brian/.cache/bazel/_bazel_brian/421f2e8b7d7f6adfe83f902fa91a62f0/tool_test_workspace && \
  exec env - \
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games \
  /bin/bash -c 'source tools/genrule/genrule-setup.sh; test_tool > bazel-out/local_linux-fastbuild/genfiles/test_output'): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 127: bash failed: error executing command 
  (cd /home/brian/.cache/bazel/_bazel_brian/421f2e8b7d7f6adfe83f902fa91a62f0/tool_test_workspace && \
  exec env - \
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games \
  /bin/bash -c 'source tools/genrule/genrule-setup.sh; test_tool > bazel-out/local_linux-fastbuild/genfiles/test_output'): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 127.
Target //:my_genrule failed to build
INFO: Elapsed time: 0.096s, Critical Path: 0.01s

Moving the tool to another folder (whether that's another package or not) fixes this example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions