Skip to content

genrule fails with non-existent path using --build_tests_only on Windows #24546

@avdv

Description

@avdv

Description of the bug:

In a genrule, trying to run a command which gets expanded from a template variable results in an error when using Bazel >= 7.3.0:

C:/b/bk-windows-j20f/bazel-org-repo-root/output/rules_sh-0.5.0/tests/sh_binaries/BUILD.bazel:3:23: Executing genrule //sh_binaries:genrule failed: (Exit 127): bash.exe failed: error executing Genrule command (from target //sh_binaries:genrule)
...
/usr/bin/bash: line 1: c:\\b\\3mrahdhj\\execroot\\_main\\bazel-out\\x64_windows-fastbuild\\bin\\sh_binaries\\hello_world.exe.runfiles/_main/sh_binaries/hello_world: No such file or directory

Note the path looks fishy: c:\\b\\3mrahdhj\\execroot\\_main\\bazel-out\\x64_windows-fastbuild\\bin\\sh_binaries\\hello_world.exe.runfiles/_main/sh_binaries/hello_world

Removing the --build_tests_only flag makes this work.

cc @fmeum

Which category does this issue belong to?

Local Execution

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

You can use rules_sh as reproducer (I'll try to give a minimal example later):

  1. gh repo clone tweag/rules_sh
  2. cd rules_sh/tests
  3. bazel test --build_tests_only ...

Which operating system are you running Bazel on?

Windows

What is the output of bazel info release?

7.3.0 - 7.4.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

Bisecting this points to 282ac62 610fe7b

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

I ran into this error for bazelbuild/bazel-central-registry#3288, see https://buildkite.com/bazel/bcr-presubmit/builds/9106.

Metadata

Metadata

Assignees

Labels

P1I'll work on this now. (Assignee required)team-Local-ExecIssues and PRs for the Execution (Local) teamtype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions