Skip to content

Fix and consolidate repo env handling#28168

Closed
fmeum wants to merge 4 commits intobazelbuild:masterfrom
fmeum:fix-env-invalidation
Closed

Fix and consolidate repo env handling#28168
fmeum wants to merge 4 commits intobazelbuild:masterfrom
fmeum:fix-env-invalidation

Conversation

@fmeum
Copy link
Copy Markdown
Collaborator

@fmeum fmeum commented Jan 6, 2026

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 RepositoryEnvironmentFunction 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
  • modifiedClientEnv, 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.

@fmeum fmeum force-pushed the fix-env-invalidation branch 2 times, most recently from 80c58ce to d102cd0 Compare January 6, 2026 16:17
@fmeum fmeum changed the title WIP: Fix repo rule env variable invalidation Fix and consolidate repo env handling Jan 6, 2026
@fmeum fmeum force-pushed the fix-env-invalidation branch from a1cb580 to f8d127e Compare January 6, 2026 18:00
lastRegistryInvalidation = now;
}
return ImmutableList.of(
PrecomputedValue.injected(PrecomputedValue.REPO_ENV, repoEnvSupplier.get()),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to be injected in the appropriate place in Blaze, presumably as an empty map.

@fmeum fmeum force-pushed the fix-env-invalidation branch 2 times, most recently from 94cda6d to 61a843a Compare January 6, 2026 18:03
@fmeum fmeum marked this pull request as ready for review January 6, 2026 18:03
@github-actions github-actions bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Jan 6, 2026
@fmeum fmeum force-pushed the fix-env-invalidation branch from 61a843a to b5a4d2f Compare January 6, 2026 18:07
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Jan 6, 2026

@bazel-io fork 9.0.0

Copy link
Copy Markdown
Member

@Wyverald Wyverald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is a very nice cleanup. Thanks for doing this! I don't think I've ever fully understood all the weirdly named repoEnv/repoEnvFromOptions/clientEnvironment stuff, and if I ever thought I understood them, I was probably lying to myself.

@fmeum fmeum force-pushed the fix-env-invalidation branch from b5a4d2f to d86e686 Compare January 8, 2026 06:52
@fmeum fmeum requested a review from Wyverald January 8, 2026 07:07
@Wyverald
Copy link
Copy Markdown
Member

Wyverald commented Jan 8, 2026

I'll import this one myself (due to #28168)

EDIT: due to https://github.com/bazelbuild/bazel/pull/28168/#discussion_r2665774750 is what I wrote, but github is making me look stupid :P

@copybara-service copybara-service bot closed this in 01407ce Jan 9, 2026
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jan 9, 2026
Wyverald pushed a commit that referenced this pull request Jan 9, 2026
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 #28168.

PiperOrigin-RevId: 854228202
Change-Id: I900f260dd5d0c6e20dcc32eaee0821567e60d5d1
Wyverald pushed a commit that referenced this pull request Jan 9, 2026
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 #28168.

PiperOrigin-RevId: 854228202
Change-Id: I900f260dd5d0c6e20dcc32eaee0821567e60d5d1
github-merge-queue bot pushed a commit that referenced this pull request Jan 9, 2026
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 #28168.

PiperOrigin-RevId: 854228202
Change-Id: I900f260dd5d0c6e20dcc32eaee0821567e60d5d1

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants