[8.6.0] Add --experimental_strict_repo_env option
#28189
Merged
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.
This PR introduces a new flag
--experimental_strict_repo_envwhich stops repository rules and module extensions from inheriting the client environment (making--repo_env=NAMEmore than just an advisory notice).When enabled up to 2 environment variables will still be forwarded (unless overridden or explicitly removed via
--repo_env==VARNAME, seePATH- All platformsPATHEXT- WindowsSee
test_execute_environment_strict_varsinsrc/test/shell/bazel/starlark_repository_test.shfor a demonstration.Note that the behavior is different to the similarly named
--incompatible_strict_action_env, which stops all environment variables (--action_envaffects actions withuse_default_shell_env = True) except those specified within the defining rule. This is by design as repository rules operate in an inherently non-hermetic domain, covering roles such as integrating with the C/C++ toolchain installed on the host. It does not make sense to lock down environment variables by default, this is best left up to individual projects and users.This flag is marked experimental to allow for testing and requirement discovery (e.g. env vars other than
PATHthat should be included).Closes #10996
Closes #28188.