Allow File values in env of ctx.actions.run[_shell]#29815
Draft
fmeum wants to merge 1 commit into
Draft
Conversation
6d9eb15 to
ba7e934
Compare
a574a16 to
9285526
Compare
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>` and `Action#getEffectiveEnvironment` now returns such a map, with `String` values used as is and `Artifact` values resolved to their (possibly path-mapped) exec paths only when a spawn is created. This also covers shadowed actions: artifact-valued variables contributed by a shadowed action are mapped with the shadowing action's path mapper. Analysis-time consumers (aquery, extra actions, `Action.env` in Starlark) resolve artifact values to their unmapped exec paths via `ActionEnvironment#resolveValues`, so their output 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.
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 values of the
envdict ofctx.actions.runandctx.actions.run_shellcan now beFiles 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.Implementation notes:
ActionEnvironmentstores fixed variables in a singleImmutableMap<String, /* String | Artifact */ Object>. All analysis-time views of the environment (getFixedEnv(),resolve(), aquery, extra actions,Action.envin Starlark) resolveArtifactvalues to their unmapped exec paths, so their types and behavior are unchanged.PathMapper(ActionEnvironment#resolveArtifactValues).PathMapper.forActionKey, mirroring how command lines are fingerprinted. Environments without artifact values produce byte-identical fingerprints as before.use_default_shell_envand--action_envinteract withFile-valued variables exactly as with string-valued ones.Tested via unit tests for
ActionEnvironment, analysis tests for the mapped spawn environment and the Starlark API, and an end-to-end test inpath_mapping_test.shthat verifies a remotely executed action reads its input through the mapped env var and gets a cross-configuration remote cache hit.