bazel: git_repository does not always work on Windows

Description of the problem / feature request:

git_repository seems to sometimes have issues on Windows. Specifically, this instantiation from bazel-integration-testing is giving me issues (please disregard the fact that bazel-integration-testing doesn’t yet support Windows:)

git_repository(
    name = "bazel_skylib",
    commit = "ff23a62c57d2912c3073a69c12f42c3d6e58a957",
    remote = "https://github.com/bazelbuild/bazel-skylib",
)

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

PS > git clone git@github.com:bazelbuild/bazel-integration-testing.git
PS > cd bazel-integration-testing
PS > bazel test ...
ERROR: error loading package '': Encountered error while reading extension file 'lib.bzl': no such package '@bazel_skylib//': Traceback (most recent call last):
        File "C:/bazel/6dd6b3zb/external/bazel_tools/tools/build_defs/repo/git.bzl", line 166
                _clone_or_update(ctx)
        File "C:/bazel/6dd6b3zb/external/bazel_tools/tools/build_defs/repo/git.bzl", line 72, in _clone_or_update
                fail(("error cloning %s:\n%s" % (ctx....)))
error cloning bazel_skylib:
+ cd C:/bazel/6dd6b3zb/external
+ rm -rf C:/bazel/6dd6b3zb/external/bazel_skylib C:/bazel/6dd6b3zb/external/bazel_skylib
/usr/bin/bash: line 4: rm: command not found

What operating system are you running Bazel on?

Windows 10 Pro 1803, MSys2 with Bash 4.4.19.

What’s the output of bazel info release?

release 0.17.2

Have you found anything relevant by searching the web?

Searched, for example, “bazel windows git_repository rm command not found” and was unable to find anything relevant.

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

If I had to guess, my guess would be that the way MSys bash is being invoked does not set up the environment properly, so only shell built-ins are available. It is not obvious to me what the best way to resolve this issue is.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (12 by maintainers)

Most upvoted comments

This should have been fixed by https://github.com/bazelbuild/bazel/pull/8677, it is going to be released in 0.28.

Hope this isn’t a useless question, but at that point would it not make more sense to just build a binary to replace the existing inline bash script instead?

/cc @laurentlb : WDYT about this:

  • implement common Bash functionality (rm, cp) in the repository_ctx object and do those operations as Starlark calls

I understand this has implications for local vs. remote execution (in case repo rules must run remotely too) and may require implementing these small utilities as standalone binaries that we ship with Bazel.

I think the correct solution would be to update the Git repo rule not to depend on Bash:

  • obtain the git binary’s path from the PATH
  • use ctx.execute directly with the git binary, instead of with the bash binary
  • implement common Bash functionality (rm, cp) in the repository_ctx object and do those operations as Starlark calls

Yes, this means every git command would need a separate ctx.execute invocation, bloating the code. But currently I’m not aware of a better platform-independent way to run commands in repository rules (without depending on Bash).