Skip to content

Fix loading symlinked .bzl files from the remote repo contents cache - #30031

Closed
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:29656-symlinked-bzl-rrcc
Closed

fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:29656-symlinked-bzl-rrcc

Conversation

@fmeum

@fmeum fmeum commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When a repo is restored from the remote repo contents cache, its files are injected into the in-memory overlay file system and .bzl/REPO.bazel files are additionally prefetched to the native file system as regular files. RemoteExternalFileSystem#getInputStream relies on this by redirecting reads of such files to the native file system, but didn't follow symlinks before doing so.

Motivation

Fixes #29656 (comment)

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: Fixed spurious "No such file" errors with the remote repo contents cache when a repo contains a symlink to a .bzl file.

@fmeum
fmeum requested review from a team, Wyverald and meteorcloudy as code owners June 26, 2026 12:07
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Jun 26, 2026
@fmeum
fmeum force-pushed the 29656-symlinked-bzl-rrcc branch from a723822 to 5453559 Compare June 26, 2026 12:16
When a repo is restored from the remote repo contents cache, its files are
injected into the in-memory overlay file system and `.bzl`/`REPO.bazel` files
are additionally prefetched to the native file system as regular files.
`RemoteExternalFileSystem#getInputStream` relies on this by redirecting reads of
such files to the native file system. However, a `.bzl` (or `REPO.bazel`) file
that is a symlink is only injected into the overlay, never prefetched to disk, so
the redirected read fails with "No such file or directory".

This affects, for example, the hermetic Android SDK repo, whose BUILD file loads
a `helper.bzl` that is symlinked out of `@rules_android`. Resolve symlinks within
the overlay before applying the native-file-system shortcut so the read is served
from the prefetched regular file the symlink points to.
@fmeum
fmeum force-pushed the 29656-symlinked-bzl-rrcc branch from 5453559 to a6fc331 Compare June 26, 2026 12:22
@fmeum

fmeum commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

@bazel-io fork 9.2.0

@fmeum

fmeum commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

@bazel-io fork 8.8.0

@coeuvre coeuvre added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Jun 26, 2026
@github-actions github-actions Bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Jun 26, 2026
bazel-io added a commit to bazel-io/bazel that referenced this pull request Jun 26, 2026
…nts cache (bazelbuild#30031) (bazelbuild#30037)

### Description

When a repo is restored from the remote repo contents cache, its files
are injected into the in-memory overlay file system and
`.bzl`/`REPO.bazel` files are additionally prefetched to the native file
system as regular files. `RemoteExternalFileSystem#getInputStream`
relies on this by redirecting reads of such files to the native file
system, but didn't follow symlinks before doing so.

### Motivation

Fixes
bazelbuild#29656 (comment)
### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: Fixed spurious "No such file" errors with the remote repo
contents cache when a repo contains a symlink to a `.bzl` file.

Closes bazelbuild#30031.

PiperOrigin-RevId: 938614073
Change-Id: I1decc39029a973cf1984d7518242d0ffc56c0711

Commit
bazelbuild@ad1793f

Co-authored-by: Fabian Meumertzheim <[email protected]>
@fmeum
fmeum deleted the 29656-symlinked-bzl-rrcc branch July 1, 2026 08:02
kapunahelewong pushed a commit to kapunahelewong/bazel that referenced this pull request Jul 2, 2026
bazelbuild#30031)

### Description

When a repo is restored from the remote repo contents cache, its files are injected into the in-memory overlay file system and `.bzl`/`REPO.bazel` files are additionally prefetched to the native file system as regular files. `RemoteExternalFileSystem#getInputStream` relies on this by redirecting reads of such files to the native file system, but didn't follow symlinks before doing so.

### Motivation

Fixes bazelbuild#29656 (comment)
### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: Fixed spurious "No such file" errors with the remote repo contents cache when a repo contains a symlink to a `.bzl` file.

Closes bazelbuild#30031.

PiperOrigin-RevId: 938614073
Change-Id: I1decc39029a973cf1984d7518242d0ffc56c0711
fmeum added a commit to fmeum/bazel that referenced this pull request Jul 14, 2026
bazelbuild#30031)

### Description

When a repo is restored from the remote repo contents cache, its files are injected into the in-memory overlay file system and `.bzl`/`REPO.bazel` files are additionally prefetched to the native file system as regular files. `RemoteExternalFileSystem#getInputStream` relies on this by redirecting reads of such files to the native file system, but didn't follow symlinks before doing so.

### Motivation

Fixes bazelbuild#29656 (comment)
### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: Fixed spurious "No such file" errors with the remote repo contents cache when a repo contains a symlink to a `.bzl` file.

Closes bazelbuild#30031.

PiperOrigin-RevId: 938614073
Change-Id: I1decc39029a973cf1984d7518242d0ffc56c0711
(cherry picked from commit ad1793f)
fmeum added a commit to fmeum/bazel that referenced this pull request Jul 14, 2026
…nts cache (bazelbuild#30101)

When a repo is restored from the remote repo contents cache, its files
are injected into the in-memory overlay file system and
`.bzl`/`REPO.bazel` files are additionally prefetched to the native file
system as regular files. `RemoteExternalFileSystem#getInputStream`
relies on this by redirecting reads of such files to the native file
system, but didn't follow symlinks before doing so.

Fixes
bazelbuild#29656 (comment).

RELNOTES: Fixed spurious "No such file" errors with the remote repo
contents cache when a repo contains a symlink to a `.bzl` file.

Closes bazelbuild#30031.

PiperOrigin-RevId: 938614073
Change-Id: I1decc39029a973cf1984d7518242d0ffc56c0711
(cherry picked from commit ad1793f)
copybara-service Bot pushed a commit that referenced this pull request Aug 3, 2026
### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so #30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to #30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes #30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
iancha1992 added a commit to iancha1992/bazel that referenced this pull request Aug 4, 2026
…d#30517)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
fmeum pushed a commit to fmeum/bazel that referenced this pull request Aug 25, 2026
…d#30517)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Sep 2, 2026
…azelbuild#30713)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and
`REPO.bazel` files are prefetched to the native file system and reads of
such paths are redirected there. Symlinks are only injected into the
in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links
first, which serves a symlinked `.bzl` file from the regular file it
points at.

That only helps if the target's own name happens to make it eligible for
prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as
`helper.bzl -> real_helper.txt` resolves to a path that was never
prefetched and thus falls back to a lazy blob download while the package
that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching
during injection and, once the repo has been injected in full and their
targets can be resolved, adds those targets to the set of files to
prefetch. The read side now also considers the path before symlink
resolution, so the prefetched target is used no matter which end of the
chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file
costs a sequential round-trip to the remote cache in the middle of the
loading phase, which is exactly what prefetching `.bzl` files during
injection is meant to avoid: the loads between `.bzl` files form a DAG
that can only be discovered layer by layer, so each such read serializes
with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)


This PR also carries the prerequisite commit
bazelbuild@c37a6a1
("Improve path validation in remote repository contents cache."), which
touches the same injection code path and landed on master first.

Replaces bazelbuild#30579, which bundles the same two commits but does not build
on this branch: it hand-authors a new
`remote_external_overlay_file_system` target in
`src/main/java/com/google/devtools/build/lib/remote/BUILD` that depends
on `//src/main/proto:failure_details_java_proto` (the branch uses
`//src/main/protobuf`), so the target does not even analyze, and its
test uses `EventBusEventHandler`, which does not exist on this branch.

9.3.0 adaptation: The
`src/main/java/com/google/devtools/build/lib/remote/BUILD` split is not
needed because that package still has a single monolithic `remote`
target here, which already covers
`RemoteExternalOverlayFileSystem.java`; the same goes for the
`remote_external_overlay_file_system` entry in
`src/test/java/com/google/devtools/build/lib/remote/BUILD`, where only
the new `//src/main/java/com/google/devtools/build/lib/cmdline` dep is
required. The new test constructs the `Reporter` as `new Reporter(new
EventBus())` since `EventBusEventHandler` was introduced by a
master-only refactoring.

Closes bazelbuild#30520

---------

Co-authored-by: twerth <[email protected]>
Co-authored-by: Ian (Hee) Cha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--experimental_remote_repo_contents_cache: module-extension child repo not materialised on disk; local action fails with 'could not find clang'

2 participants