Skip to content

Allow File values in env of ctx.actions.run[_shell] - #29875

Open
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:env-file-values
Open

Allow File values in env of ctx.actions.run[_shell]#29875
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:env-file-values

Conversation

@fmeum

@fmeum fmeum commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Adds support for path mappable environment variables by generalizing the existing custom support for C++ actions. ActionEnvironment is extended to allow Artifact values in addition to String and the change is largely contained to that class, with getEffectiveEnvironment retaining its Map<String, String> return value.

RELNOTES: The values of the env dict of ctx.actions.run and ctx.actions.run_shell can now be Files in addition to strings to support path mapping environment variables (see #22658).

@fmeum
fmeum force-pushed the env-file-values branch 5 times, most recently from e713016 to bf1f420 Compare June 19, 2026 11:50
The values of the `env` dict of `ctx.actions.run` and
`ctx.actions.run_shell` can now be `File`s in addition to strings. Such
values are expanded to the file's exec path at execution time, after
path mapping has been applied. Compared to expanding the path during
analysis, this allows environment variables referencing input or output
paths to benefit from cross-configuration cache hits with
`--experimental_output_paths=strip`.

`ActionEnvironment` stores fixed variables in a single
`ImmutableMap<String, /* String | Artifact */ Object>`. Since
`Action#getEffectiveEnvironment` now receives a `PathMapper`, artifact
values are resolved to their (possibly mapped) exec paths directly
during resolution, so the method keeps returning `ImmutableMap<String,
String>` and no caller needs to change. Analysis-time views
(`getFixedEnv()`, the two-argument `resolve()`, aquery, `Action.env` in
Starlark) resolve artifact values with `PathMapper.NOOP`, so their
behavior is unchanged. The action key fingerprints artifact values with
`PathMapper.forActionKey`, mirroring how command lines are
fingerprinted; environments without artifact values produce
byte-identical fingerprints as before.
@fmeum
fmeum force-pushed the env-file-values branch from bf1f420 to e263ffb Compare June 19, 2026 12:11
@fmeum
fmeum marked this pull request as ready for review June 19, 2026 13:20
@fmeum
fmeum requested review from a team and lberki as code owners June 19, 2026 13:20
@fmeum
fmeum requested review from dabanki and mai93 and removed request for a team and mai93 June 19, 2026 13:20
@github-actions github-actions Bot added team-Performance Issues for Performance teams team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-Java Issues for Java rules team-Rules-CPP Issues for C++ rules team-Starlark-Integration Issues involving Bazel's integration with Starlark, excluding builtin symbols awaiting-review PR is awaiting review from an assigned reviewer team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts labels Jun 19, 2026
@fmeum

fmeum commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

FYI @keith

@fmeum

fmeum commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

@lberki Could you review this for the potential wider impact on ActionEnvironment consumers?
@dabanki Could you review this from the path mapping perspective?

@fmeum

fmeum commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

@dabanki @lberki Friendly ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Configurability platforms, toolchains, cquery, select(), config transitions team-Performance Issues for Performance teams team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts team-Rules-CPP Issues for C++ rules team-Rules-Java Issues for Java rules team-Starlark-Integration Issues involving Bazel's integration with Starlark, excluding builtin symbols

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant