Skip to content

fix(targethasher): only hash local FILE lines in bzlmod repo markers - #330

Merged
yushan8 merged 5 commits into
mainfrom
yushan/marker-hash-local-files
Oct 9, 2026
Merged

yushan8 merged 5 commits into
mainfrom
yushan/marker-hash-local-files

Conversation

@yushan8

@yushan8 yushan8 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Why?
Some of the skipped FILE: lines are generated during the fetch (gazelle's go.env and the gazelle and fetch_repo binaries) and contain the Bazel output_base path, which depends on the workspace location. The same commit computed in two different workspaces got different hashes, so the whole repo and everything depending on it showed up as changed.

What?
Now it only hashes the first line of the marker (the repo rule's inputs) plus the inputs that live in the main repo (FILE:, DIRTREE:, DIRENTS: with an @@// path, which covers patches). Everything else is skipped: ENV:, REPO_MAPPING:, inputs from other repos, and absolute paths. Patch edits and version, URL or integrity changes still change the hash.

The marker file hashing is only supported since bazel doesn't support bazel mod show_repo --all_repos until later versions, and internally the repo is on bazel 8.1.1 with bzlmod.

On Bazel below 8.6.0, markers are how we hash these repos, one hash per repo rather than per file. Hashing external repos via bazel mod show_repo --all_repos will be supported in follow up PRs.

Test Plan
New markers_test.go covers the cases above, bazel test //core/targethasher:targethasher_test passes, and on two checkouts of the same commit in different directories none of the 28 real markers differ anymore.

Test Plan

Unit test
Tested on internal monorepo to ensure the external hash did not differ across revisions

Issues

readMarkerHash hashed every non-ENV marker line. Some FILE: lines point at
files generated during a repo's fetch (e.g. go_repository_cache's go.env and
the binaries built by go_repository_tools) and embed the Bazel output_base
path. The output_base is derived from the workspace path, so the collapsed
hash of every file in such a repo differed between two computes done in
different workspaces, flagging the repo and all of its reverse dependencies
as changed even though no dependency changed.

Hash only the first line (the repo rule's declarative inputs) and FILE:
lines for main-repo files (@@// labels, which cover patches). ENV:,
REPO_MAPPING: and FILE: lines for other repos are skipped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@yushan8
yushan8 requested review from a team as code owners October 8, 2026 23:13
@yushan8
yushan8 marked this pull request as draft October 8, 2026 23:16
Bazel records a repo rule's file-system inputs as KIND:@@<repo>//<path>, with
FILE, DIRTREE and DIRENTS kinds. Only FILE:@@// lines were treated as local to
the main repo, so a checked-in directory input (e.g. a patches directory)
would not have affected the marker hash. Treat all three kinds with an @@//
path as local. Inputs in other repos and absolute-path inputs stay excluded.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@yushan8
yushan8 marked this pull request as ready for review October 9, 2026 00:13
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@yushan8
yushan8 marked this pull request as draft October 9, 2026 00:23
@yushan8
yushan8 marked this pull request as ready for review October 9, 2026 03:14
@yushan8
yushan8 merged commit 3c4ad8d into main Oct 9, 2026
10 checks passed
@yushan8
yushan8 deleted the yushan/marker-hash-local-files branch October 9, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants