bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.23k stars 4.07k forks source link

git receives SIGABRT when trying to fetch a repository with `git_override` in MODULE.bazel #24306

Open jaqx0r opened 1 day ago

jaqx0r commented 1 day ago

Description of the bug:

bazel cannot fetch a bazel_dep with a git_override.

slab% bazel version
Bazelisk version: v1.19.0
Build label: 7.4.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Nov 11 21:24:53 2024 (1731360293)
Build timestamp: 1731360293
Build timestamp as int: 1731360293

Which category does this issue belong to?

Core

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

Install bazel 7.4.1 with bazelisk 1.19.0, per the version above.

Create a new directory, e.g. mkdir -p ~/src/test

Copy the text below into ~/src/test/MODULE.bazel:

# To rebuild `compile_commands.json` for clangd:
#   bazel run @hedron_compile_commands//:refresh_all
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
    module_name = "hedron_compile_commands",
    commit = "4689147cf4b1c2d507fd8bbb8eb748a7bbaad4ef",
    remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

Run bazel info and observe:

slab% bazel info
Starting local Bazel server and connecting to it...
INFO: Repository hedron_compile_commands~ instantiated at:
  <builtin>: in <toplevel>
Repository rule git_repository defined at:
  /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git.bzl:189:33: in <toplevel>
ERROR: /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl:210:9: An error occurred during the fetch of repository 'hedron_compile_commands~':
   Traceback (most recent call last):
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git.bzl", line 180, column 35, in _git_repository_implementation
        update = _clone_or_update_repo(ctx)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git.bzl", line 43, column 20, in _clone_or_update_repo
        git_ = git_repo(ctx, directory)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 98, column 12, in git_repo
        _update(ctx, git_repo)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 114, column 9, in _update
        init(ctx, git_repo)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 131, column 15, in init
        _error(ctx.name, cl, st.return_code, st.stderr)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 210, column 9, in _error
        fail("error %d running '%s' while working with @%s:\n%s" % (return_code, command_text, name, stderr))
Error in fail: error 134 running 'git init /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands~' while working with @hedron_compile_commands~:
ERROR: error 134 running 'git init /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands~' while working with @hedron_compile_commands~:

I have patched git_worker.bzl locally to emit the status code, relevant lines copied here:

def init(ctx, git_repo):
    cl = ["git", "init", str(git_repo.directory)]
    st = ctx.execute(cl, environment = ctx.os.environ)
    if st.return_code != 0:
        _error(ctx.name, cl, st.return_code, st.stderr)

def _error(name, command, return_code, stderr):
    command_text = " ".join([str(item).strip() for item in command])
    fail("error %d running '%s' while working with @%s:\n%s" % (return_code, command_text, name, stderr))

Which operating system are you running Bazel on?

Debian GNU/Linux "sid"

What is the output of bazel info release?

release 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.

No response

Have you found anything relevant by searching the web?

Yes, but no-one else seems to have encountered this error.

I am trying to figure out how to get the process environment that ctx.execute runs in so I can try to reproduce this outside of bazel, to understand why git is receiving a SIGABRT.

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

No response

jaqx0r commented 1 day ago

Running git init /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands~ from a shell doesn't trigger a SIGABRT, and succeeds as expected:

slab% git init "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands~"
Initialized empty Git repository in /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands~/.git/
jaqx0r commented 1 day ago

This might be the same as https://github.com/bazelbuild/bazel/issues/24199 but unlike that bug I don't have GIT_DIR set anywhere in the environment, at least that I can tell; also the reported error is different.

jaqx0r commented 1 day ago

I set a .bazeliskrc in the top level with the following content:

USE_BAZEL_VERSION=8.0.0-pre.20240925.4

and received the same error:

slab% bazel info
2024/11/13 10:57:36 Downloading https://releases.bazel.build/8.0.0/rolling/8.0.0-pre.20240925.4/bazel-8.0.0-pre.20240925.4-linux-x86_64...
2024/11/13 10:57:36 Skipping basic authentication for releases.bazel.build because no credentials found in /home/jaq/.netrc
Downloading: 57 MB out of 57 MB (100%)
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Repository hedron_compile_commands+ instantiated at:
  <builtin>: in <toplevel>
Repository rule git_repository defined at:
  /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git.bzl:189:33: in <toplevel>
ERROR: /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl:210:9: An error occurred during the fetch of repository 'hedron_compile_commands+':
   Traceback (most recent call last):
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git.bzl", line 180, column 35, in _git_repository_implementation
        update = _clone_or_update_repo(ctx)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git.bzl", line 43, column 20, in _clone_or_update_repo
        git_ = git_repo(ctx, directory)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 98, column 12, in git_repo
        _update(ctx, git_repo)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 114, column 9, in _update
        init(ctx, git_repo)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 131, column 15, in init
        _error(ctx.name, cl, st.stderr)
    File "/home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 210, column 9, in _error
        fail("error running '%s' while working with @%s:\n%s" % (command_text, name, stderr))
Error in fail: error running 'git init /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands+' while working with @hedron_compile_commands+:
ERROR: error running 'git init /home/jaq/.cache/bazel/_bazel_jaq/84edce96f0eb3d1bc9a9c0e9ceeea635/external/hedron_compile_commands+' while working with @hedron_compile_commands+: