Resolve relative manifest targets like the runfiles directory does - #69
Open
fmeum wants to merge 1 commit into
Open
Resolve relative manifest targets like the runfiles directory does#69fmeum wants to merge 1 commit into
fmeum wants to merge 1 commit into
Conversation
fmeum
force-pushed
the
manifest-relative-symlink-targets
branch
2 times, most recently
from
August 13, 2026 10:32
86e8a1e to
84ac013
Compare
The target of a runfiles manifest entry is an absolute path, except for unresolved symlinks (`ctx.actions.declare_symlink`), whose target Bazel copies into the manifest verbatim: `SourceManifestAction` writes `metadata.getUnresolvedSymlinkTarget()`, which may be relative. In a runfiles directory, `SymlinkTreeHelper#createRunfilesSymlinks` creates such an entry textually, so the file system resolves it relative to the directory containing the symlink. A manifest-based lookup returned that raw target instead, i.e. a path relative to the current working directory. `rlocation` thus either failed or, worse, returned an unrelated file that happened to exist relative to the working directory. Interpret a relative target as an rlocation path relative to the directory of its entry and look that up in the manifest again, which is what resolving the symlink in a materialized runfiles directory amounts to. Targets that escape the runfiles root cannot be resolved this way and are reported as missing, as are cycles, which are broken after 32 levels. Claude-Session: https://claude.ai/code/session_013o72rMrpgYKD9wYYQ2Nr98
fmeum
force-pushed
the
manifest-relative-symlink-targets
branch
from
August 13, 2026 10:36
84ac013 to
998621d
Compare
fmeum
marked this pull request as ready for review
August 13, 2026 10:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The target of a runfiles manifest entry is an absolute path, except for unresolved symlinks (
ctx.actions.declare_symlink), whose target Bazel copies into the manifest verbatim:SourceManifestAction#writeFilewritesmetadata.getUnresolvedSymlinkTarget(), which may be relative. In a runfiles directory, sandboxes andSymlinkTreeHelper#createRunfilesSymlinkscreate such an entry textually ("Unresolved symlinks are created textually"), so the file system resolves it relative to the directory containing the symlink.A manifest-based lookup returned that raw target instead, i.e. a path relative to the current working directory.
rlocationthus either failed or, worse, returned an unrelated file that happened to exist relative to the working directory.This change makes it so that a relative target resolves as an rlocation path relative to the directory of its entry and looks that up in the manifest again, which is what resolving the symlink in a materialized runfiles directory amounts to. Targets that escape the runfiles root cannot be resolved this way and are reported as missing, as are cycles, which are broken after 32 levels.
The test runs the same lookups against both backends:
write_relative_symlink_target_layoutemits the same set of unresolved symlinks as a manifest and as a materialized runfiles directory, andassert_relative_symlink_target_lookupsasserts that each resolves to the same file. Before this change, the directory-backed half passes and the manifest-backed one fails on its first assertion. The only case in which the two cannot agree is a relative target that leaves the runfiles tree, which the file system resolves against the directory's parent; the manifest offers no way to reach it, so it is reported as missing.