[8.8.0] Fix and consolidate repo env handling (partial)#29069
Merged
Conversation
|
Thank you for contributing to the Bazel repository! This pull request has been marked as stale since it has not had any activity in the last 30 days. It will be closed in the next 30 days unless any other activity occurs. If you think this PR is still relevant and should stay open, please post any comment here and the PR will no longer be marked as stale. |
c09912b to
be7884e
Compare
…nv handling Manual port of only the essential API changes from 01407ce needed by later feature commits, since the full `CommandEnvironment` repo-env consolidation does not apply to 8.x: - Add `EnvironmentVariableValue` record type - Add `RepoEnvironmentFunction` with `--repo_env` + client env fallback - Register `REPOSITORY_ENVIRONMENT_VARIABLE` in `SkyFunctions` and `SkyframeExecutor` - Update `EnvVar.getSkyKey()` to use `RepoEnvironmentFunction` - Update `EnvVar.isOutdated()` to use `EnvironmentVariableValue` On 8.7.0, `RepoEnvironmentFunction` checks `--repo_env` first, then falls back to the client environment via `ClientEnvironmentFunction`, since the consolidated repo env computation from `CommandEnvironment` is not present. Additionally includes the regression test from bazelbuild#29946 (`test_unrelated_env_var_does_not_invalidate_repo`): changing an unrelated environment variable via an interleaved `bazel mod` command must not refetch a repository that doesn't depend on it. bazelbuild#29946's production fix is not needed here because this narrow port injects only `repoEnvFromOptions` into `REPO_ENV` and falls back to the already per-variable `ClientEnvironmentFunction` for everything else, so an unrelated client variable never mutates the whole-map node. Original commit message follows: The current invalidation logic didn't take `--incompatible_repo_env_ignores_action_env` and `--experimental_strict_repo_env` into account, which resulted in incorrect invalidation of repo rules and module extensions. This is addressed by a larger refactoring that consolidates the logic that computes the effective environment for repository rules and module extensions in `CommandEnvironment`. This environment is then read and sliced by a new `RepoEnvironmentFunction` that operates analogously to `ClientEnvironmentFunction`. Along the way, the variety of terminology in `CommandEnvironment` and various `SkyFunction`s is cleaned up to consistently use: * `repoEnv` to refer to the environment seen by repo rules and module extensions, which may or may not see the full client env based on the value of `--experimental_strict_repo_env` and * `nonstrictRepoEnv`, which refers to same environment with, conceptually, `--experimental_strict_repo_env` forced to `false`. This is used for certain non-hermetic operations such as downloader and credential helper logic. Closes bazelbuild#28168. PiperOrigin-RevId: 854228202 Change-Id: I900f260dd5d0c6e20dcc32eaee0821567e60d5d1 (cherry picked from commit 01407ce)
Wyverald
approved these changes
Jun 24, 2026
Merged
via the queue into
bazelbuild:release-8.8.0
with commit Jun 24, 2026
249bfc1
47 checks passed
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.
Manual port of only the essential API changes from 01407ce needed by later feature commits, since the full
CommandEnvironmentrepo-env consolidation does not apply to 8.x:EnvironmentVariableValuerecord typeRepoEnvironmentFunctionwith--repo_env+ client env fallbackREPOSITORY_ENVIRONMENT_VARIABLEinSkyFunctionsandSkyframeExecutorEnvVar.getSkyKey()to useRepoEnvironmentFunctionEnvVar.isOutdated()to useEnvironmentVariableValueOn 8.7.0,
RepoEnvironmentFunctionchecks--repo_envfirst, then falls back to the client environment viaClientEnvironmentFunction, since the consolidated repo env computation fromCommandEnvironmentis not present.Additionally includes the regression test from #29946 (
test_unrelated_env_var_does_not_invalidate_repo): changing an unrelated environment variable via an interleavedbazel modcommand must not refetch a repository that doesn't depend on it. #29946's production fix is not needed here because this narrow port injects onlyrepoEnvFromOptionsintoREPO_ENVand falls back to the already per-variableClientEnvironmentFunctionfor everything else, so an unrelated client variable never mutates the whole-map node.Original commit message follows:
The current invalidation logic didn't take
--incompatible_repo_env_ignores_action_envand--experimental_strict_repo_envinto account, which resulted in incorrect invalidation of repo rules and module extensions.This is addressed by a larger refactoring that consolidates the logic that computes the effective environment for repository rules and module extensions in
CommandEnvironment. This environment is then read and sliced by a newRepoEnvironmentFunctionthat operates analogously toClientEnvironmentFunction.Along the way, the variety of terminology in
CommandEnvironmentand variousSkyFunctions is cleaned up to consistently use:repoEnvto refer to the environment seen by repo rules and module extensions, which may or may not see the full client env based on the value of--experimental_strict_repo_envandnonstrictRepoEnv, which refers to same environment with, conceptually,--experimental_strict_repo_envforced tofalse. This is used for certain non-hermetic operations such as downloader and credential helper logic.Closes #28168.
PiperOrigin-RevId: 854228202
Change-Id: I900f260dd5d0c6e20dcc32eaee0821567e60d5d1
(cherry picked from commit 01407ce)