fix(runnable): replay the target's env attribute when spawning built binaries#1234
Open
gregmagolan wants to merge 1 commit into
Open
fix(runnable): replay the target's env attribute when spawning built binaries#1234gregmagolan wants to merge 1 commit into
gregmagolan wants to merge 1 commit into
Conversation
…binaries
`runnable.axl` spawned built binaries directly from their runfiles tree but
never applied the target's `env = {...}` attribute, which `bazel run` injects
at run time from `RunEnvironmentInfo`. A `set -u` script reading an env-injected
var (e.g. JQ_BIN) failed with "unbound variable".
A `runenv` aspect reads each target's `RunEnvironmentInfo` and writes the
resolved env to JSON in an `aspect_runenv` output group; the runnable tracker
collects it from BES and `spawn` replays it verbatim before the runfiles/BUILD_*/
ASPECT_* vars. Wired into run, format, gazelle, and delivery phase 3. No-op for
rules without `RunEnvironmentInfo`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✨ Aspect Workflows Tasks📅 Mon Jun 15 20:36:37 UTC 2026
|
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.
aspect run/format/gazelle/deliveryspawn the built binary directly from its runfiles tree rather than shelling out tobazel run. That path never applied the target'senv = {...}attribute — whichbazel runinjects at run time from theRunEnvironmentInfoprovider — so any var declared inenvwas simply absent. Aset -uscript that reads one (e.g.JQ_BIN) failed withJQ_BIN: unbound variable.The resolved
envlives in neither the on-disk wrapper nor BES, so it can only be recovered via the provider. A smallrunenvaspect readsRunEnvironmentInfo.environment/.inherited_environmentand writes them to JSON in anaspect_runenvoutput group. The runnable tracker collects that file from BES andspawnreplays the env —environmentvalues verbatim (already rootpath-expanded relative to the runfiles workspace dir, which is the spawn cwd),inherited_environmentnames copied from the process env. Target env is applied before the runfiles/BUILD_*/ASPECT_*vars so the runfiles plumbing wins on any collision.The aspect is a no-op for rules that don't populate
RunEnvironmentInfo(e.g. legacy nativesh_binary, bazelbuild/bazel#23658), in which case the spawn behaves as before.Changes are visible to end-users: yes
aspect run,format,gazelle, anddeliverynow apply a target'senvattribute when running the built binary, matchingbazel run. Fixesunbound variableerrors for scripts that read env-injected vars underset -u.Test plan
lib/runnable_test.axl: env collection, partial JSON, absent provider, ctx-less, and the aspect-flags helper)aspect dev test-runnable,aspect tests axl)