bazelbuild / bazelbuild/bazel

Vendoring incorrectly evaluates what to vendor when `test --build_tests_only` is set

Open
#26,107 10 comments 0 reactions 1 assignee Claimed by @Wyverald View on GitHub
help wanted P3 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 16h
Merged PRs (30d)
72

Description

### Description of the bug:

Trying to vendor dependencies for a specific target in our bazel project, I noticed a certain repository was not vendored. It turns out disabling the following setting in our .bazelrc fixed it:
`test --build_tests_only`

### Which category does this issue belong to?

External Dependency

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

```
#MODULE.bazel
module(
name = "vendoring",
)

http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

http_file(
name = "bazel.MODULE",
downloaded_file_path = "bazel.MODULE",
urls = [
"https://raw.githubusercontent.com/bazelbuild/bazel/refs/heads/master/MODULE.bazel",
],
)

#BUILD.bazel
genrule(
name = "fake_target",
srcs = [
"@bazel.MODULE//file:bazel.MODULE",
],
outs = [
"out.txt",
],
cmd = "cat $(location @bazel.MODULE//file:bazel.MODULE) > $@",
)

#.bazelrc
test --build_tests_only

```

### Which operating system are you running Bazel on?

Linux

### What is the output of `bazel info release`?

release 8.2.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` ?

```text

```

### 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?

Discussed on bazel slack: https://bazelbuild.slack.com/archives/C014RARENH0/p1747728318774869

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

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.