bazelbuild/bazel

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

Open

#26,107 opened on May 20, 2025

View on GitHub
 (10 comments) (0 reactions) (1 assignee)Java (25,384 stars) (4,465 forks)batch import
P3help wantedteam-ExternalDepstype: bug

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 ?

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