Skip to content

[8.8.0] Fix and consolidate repo env handling (partial)#29069

Merged
iancha1992 merged 1 commit into
bazelbuild:release-8.8.0from
fmeum:rrcc-8.7.0-03
Jun 24, 2026
Merged

[8.8.0] Fix and consolidate repo env handling (partial)#29069
iancha1992 merged 1 commit into
bazelbuild:release-8.8.0from
fmeum:rrcc-8.7.0-03

Conversation

@fmeum

@fmeum fmeum commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

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 #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. #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 SkyFunctions 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 #28168.

PiperOrigin-RevId: 854228202
Change-Id: I900f260dd5d0c6e20dcc32eaee0821567e60d5d1
(cherry picked from commit 01407ce)

@iancha1992 iancha1992 added this to the 8.7.0 release blockers milestone Mar 27, 2026
@iancha1992 iancha1992 added the soft-release-blocker Soft release blockers that are nice to have, but shouldn't block the release if it's the last one. label Apr 24, 2026
@iancha1992 iancha1992 changed the title [8.7.0] 03/23: Manual port of essential parts of: Fix and consolidate repo env handling [8.8.0] 03/23: Manual port of essential parts of: Fix and consolidate repo env handling May 7, 2026
@iancha1992 iancha1992 changed the base branch from release-8.7.0 to release-8.8.0 May 7, 2026 18:01
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 7, 2026
@github-actions github-actions Bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Jun 17, 2026
@fmeum fmeum force-pushed the rrcc-8.7.0-03 branch 3 times, most recently from c09912b to be7884e Compare June 23, 2026 14:57
@fmeum fmeum changed the title [8.8.0] 03/23: Manual port of essential parts of: Fix and consolidate repo env handling [8.8.0] Fix and consolidate repo env handling (partial) Jun 23, 2026
…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)
@fmeum fmeum marked this pull request as ready for review June 24, 2026 07:39
@fmeum fmeum requested a review from a team as a code owner June 24, 2026 07:39
@github-actions github-actions Bot added team-Core Skyframe, bazel query, BEP, options parsing, bazelrc awaiting-review PR is awaiting review from an assigned reviewer labels Jun 24, 2026
@iancha1992 iancha1992 added this pull request to the merge queue Jun 24, 2026
Merged via the queue into bazelbuild:release-8.8.0 with commit 249bfc1 Jun 24, 2026
47 checks passed
@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jun 24, 2026
@fmeum fmeum deleted the rrcc-8.7.0-03 branch June 24, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

soft-release-blocker Soft release blockers that are nice to have, but shouldn't block the release if it's the last one. team-Core Skyframe, bazel query, BEP, options parsing, bazelrc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants