FR: allow ctx.which to watch for PATH/ program changes #24864
Labels
team-ExternalDeps
External dependency handling, remote repositiories, WORKSPACE file.
type: feature request
untriaged
Description of the feature request:
In short: Add a
watch=True
arg toctx.which()
. This makes it parsePATH
and watch for$program
to exist/change in a directory before where it first found$program
. Unless that condition is met, the which() result is not invalidated. The pesudo-code for this would be something like:Background:
The
ctx.which()
function is used to find a program by looking for it in the locations specified by thePATH
environment variable. Thus, changing PATH could change the result of which(), depending on how path changed and where a program was found.Today, changes to the PATH environment variable won't invalidate any lookups using which(). This makes some sense because it's pretty context specific as to whether it matters or not. However, this is problematic for cases which do care if the result would have changed. My go-to example is when configuring a language toolchain using the local system (non-ideal, but IMHO, quite reasonable when users intentionally want to use a custom toolchain for whatever reason).
While a repository rule can call
getenv("PATH")
to watch the path environment variable, this ends up being too noisy -- tools like git may modify PATH when running hooks (bazelbuild/rules_python#2551 (comment)) in such a way that wouldn't invalidate most which() calls.Which category does this issue belong to?
External Dependency
What underlying problem are you trying to solve with this feature?
Making a repository rule correctly watch for changes to its inputs while not invalidating when unnecessary.
Which operating system are you running Bazel on?
Linux
What is the output of
bazel info release
?8.0.0
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
Searched all, didn't find a mention of this.
Any other information, logs, or outputs that you want to share?
This feature request originates from discussion in bazelbuild/rules_python#2551
The text was updated successfully, but these errors were encountered: