native.bazel_version not tracked as repo rule input

Open
#33,071 2 comments 3 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
44/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
build-system

Research direction

Start by reproducing the supplied example: it shows that a repository rule reading native.bazel_version keeps the old value across a Bazel upgrade unless the rule is local. Trace how repository rules record inputs in the marker file and how those inputs trigger refetches; the issue names no source files or tests. Done when a change to the Bazel version causes the non-local repository to be refetched, without making every MODULE file edit refetch it.

Written by the indexing model from the issue text.

Description

help wanted P2 team-ExternalDeps type: bug
Description of the bug:

A repo rule can read native.bazel_version, but Bazel does not record it as an input. After a Bazel upgrade, the repo is not refetched and keeps the old version. The only workaround is local = True. But local repos are also refetched after every MODULE file edit, so every package that loads from them is reloaded.

"Low level" rulesets use this workaround, for e.g.

and almost every workspace loads them -- so this has a pretty big impact on analysis time esp. when a full workspace reload is required on every MODULE file change.


Ideally, when a repo rule reads native.bazel_version, Bazel records the value in the marker file, and refetch the repo when it changes.

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.

Version is not tracked (Bazel 9.3.2 -> 9.3.3)

#!/usr/bin/env bash
set -euo pipefail
cd "$(mktemp -d)"

cat > MODULE.bazel <<'EOF'
v = use_repo_rule("//:v.bzl", "v")
v(name = "v")
v_local = use_repo_rule("//:v.bzl", "v_local")
v_local(name = "v_local")
EOF

cat > v.bzl <<'EOF'
def _impl(rctx):
    rctx.file("BUILD", "")
    rctx.file("version.bzl", "VERSION = '%s'" % native.bazel_version)
v = repository_rule(_impl)
v_local = repository_rule(_impl, local = True)
EOF

printf 'load("@v//:version.bzl", "VERSION")\nload("@v_local//:version.bzl", V = "VERSION")\n' > BUILD

for version in 9.3.2 9.3.3; do
  echo "$version" > .bazelversion
  bazel query //:all >/dev/null 2>&1
  ext="$(bazel info output_base 2>/dev/null)/external"
  echo "Bazel $version: @v says $(cut -d"'" -f2 "$ext/+v+v/version.bzl"), @v_local says $(cut -d"'" -f2 "$ext/+v_local+v_local/version.bzl")"
done

Output:

Bazel 9.3.2: @v says 9.3.2, @v_local says 9.3.2
Bazel 9.3.3: @v says 9.3.2, @v_local says 9.3.3
Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 9.3.3

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?

No response

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

No response

Dominant language
Java
Stars
26.2k
Forks
4.7k
Avg merge
3d 11h
Merged PRs (30d)
125

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/bazel

All issues in bazelbuild/bazel

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.