fix: _which_unchecked: don't watch PATH if binary exists. #2552
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.
Currently, the _which_unchecked helper unconditionally watches the
PATH
env var via repository_ctx.getenv. getenv is documented https://bazel.build/rules/lib/builtins/repository_ctx#getenv:Thus, any change to
PATH
will cause any repository rule that transitively calls _which_unchecked to be re-fetched. This includes python_repository and whl_library.There are reasonable development workflows that modify
PATH
. In particular, when git runs a hook, it adds the value ofGIT_EXEC_PATH
toPATH
before invoking the hook. If the hook invokes bazel (for example, a pre-commit hook runningbazel build ...
), it will cause the Python repository rules to be re-fetched.This commit lowers the repository_ctx.getenv("PATH") call to its only use site in _which_unchecked, which happens to be a failure case (when the binary is not found). This allows the success case to not watch
PATH
, and therefore not to re-fetch the repository rule when it changes.Fixes #2551.