Skip to content

Look up runfiles in the runfiles directory if it is materialized - #70

Open
fmeum wants to merge 1 commit into
bazel-contrib:mainfrom
fmeum:prefer-materialized-runfiles-directory
Open

Look up runfiles in the runfiles directory if it is materialized#70
fmeum wants to merge 1 commit into
bazel-contrib:mainfrom
fmeum:prefer-materialized-runfiles-directory

Conversation

@fmeum

@fmeum fmeum commented Aug 13, 2026

Copy link
Copy Markdown
Member

runfiles_rlocation_checked and runfiles_current_repository have to agree on where they look up runfiles: the output of the former is the input of the latter, and a path resolved against the runfiles directory is never the target of a manifest entry. #68 made them agree on the manifest, at the cost of scanning it on every lookup and of returning paths outside the runfiles tree.

Both now use the runfiles directory if it has been materialized and the manifest otherwise, never falling back from one to the other.

Whether the directory is materialized is a property of the execution rather than of the build: --noenable_runfiles leaves behind only the MANIFEST file and the main repository's subdirectory, while the sandbox and remote execution materialize the directory in full and don't stage the manifest at all. The presence of this library in the directory distinguishes the two cases as any other runfile would.

runfiles_export_envvars no longer passes on a RUNFILES_DIR that fails the same check.

runfiles_current_repository now consistently returns 0 when it falls back to parsing the caller's execroot path; it used to do so only in directory mode.

@fmeum
fmeum force-pushed the prefer-materialized-runfiles-directory branch 10 times, most recently from 19ea6e7 to 9331a27 Compare August 13, 2026 14:23
`runfiles_rlocation_checked` and `runfiles_current_repository` have to
agree on where they look up runfiles: the output of the former is the
input of the latter, and the manifest maps rlocation paths to the
locations of the *original* files, so a path resolved against the
runfiles directory is never the target of a manifest entry. bazel-contrib#68 made
them agree on the manifest, at the cost of scanning it on every lookup
and of returning paths outside the runfiles tree.

Instead, have both use the runfiles directory whenever it has been
materialized and the manifest otherwise, without ever falling back from
one to the other. Whether the directory has been materialized is a
property of how the action or test is executed rather than of the build:
`--noenable_runfiles` leaves behind a directory that contains only the
`MANIFEST` file and the subdirectory of the main repository, but the
sandbox and remote execution materialize it in full regardless (they
don't stage the manifest at all). The presence of this library in the
directory distinguishes the two cases: it is an ordinary runfile, so it
is materialized by exactly the mechanisms that also materialize every
other runfile, and it is in the runfiles of every user of the library,
which all load it via the initialization snippet that looks it up at
this very path. The snippet therefore already made this determination
when it sourced the library, so the library records it once on load
rather than repeating it per lookup.

`runfiles_export_envvars` in turn no longer passes on a runfiles
directory it hasn't verified. It used to export any `RUNFILES_DIR` it
could derive from the manifest path as long as that directory existed,
which with `--noenable_runfiles` is the near-empty one, leaving a
subprocess to resolve runfiles paths that don't exist. With both
exported variables usable on their own, a subprocess needs no knowledge
of which one this process picked, so that choice stays private to it.

`runfiles_current_repository` now consistently returns 0 when it has to
fall back to parsing the caller's execroot path; it used to do so only
if the runfiles directory was used.
@fmeum
fmeum force-pushed the prefer-materialized-runfiles-directory branch from 9331a27 to 5adb6de Compare August 13, 2026 15:11
@fmeum
fmeum marked this pull request as ready for review August 13, 2026 15:11
@fmeum
fmeum requested review from Wyverald and meteorcloudy August 13, 2026 15:11
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.

1 participant