-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add watch
parameter to {module,repo}_ctx.path
#23386
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just
maybeWatch(result, shouldWatch)
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment, this would be backwards incompatible (caught by one of the new tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(sorry for the delay)
You're talking about
testPath_watchAuto_starlarkPathAndAbsolutePathNotWatched
, right? I agree that's a change in behavior, but I don't know if it counts as backwards-incompatible. Didn't we do the same behavior change for repo rules?Plus, we already have the condition where
watch = 'auto'
means that paths outside the workspace aren't watched (https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java;drc=6052ad65e4185f19944e5138e9b70f6a4eaf9e76;l=1457). Isn't that enough?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title was misleading, it adds this parameter to both repo and module context, so we don't have prior art for this function to refer to.
I agree that the change is minor, but I think that it would end up breaking the code in https://github.com/bazelbuild/rules_python/pull/2135/files#diff-ca74c876e894b0bd25547ca666e562281e5c8fb2abc4a51446f410371224aea2 by reintroducing a dependency into the lockfile. Depending on a sibling label, manipulating the path and then obtaining a
StarlarkPath
for it via this method is the kind of existing "pattern" that changing this would break.I'm not in love with that edge case and we could decide to point users to
bazel_features
instead, but it would still be breaking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I see. Could you add some more details in the PR description about the motivation of this change? It got lost in the commotion.
I could see an API where
auto
(or whatever the default value for[mr]ctx.path(watch=)
ends up being) means "don't watch". Or just make it default tono
. Or actually, maybe just make[mr]ctx.watch
return the path?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I remember now -- so
rctx.path(label)
used to watch, andrctx.path(path)
andrctx.path(string)
used to not watch.This PR retains this old
rctx.path(X)
watch behavior (which is based on the type of X, not the actual location of X or whether it'srctx
ormctx
). It just allows the caller to be explicit about watching or not by specifyingwatch='yes'
orwatch='no'
. The awkward part is thatwatch='auto'
means a different thing forrctx.path()
thanrctx.read()
,rctx.extract()
, etc.I wonder if we'd want
rctx.path(X)
to never watch (just userctx.watch()
instead). That's obviously backwards-incompatible because some people rely onrctx.path(label)
watching, but maybe it's worth introducing an incompatible flag flip for? Undecided.Also, the fact that
rctx.read(label, watch='no')
actually still watches is a bit of a subtle hiccup. I'll need to think about that too...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I've thought more about it, I think that I would prefer the following changes:
ctx.path
never watches and doesn't have awatch
parameter. It only ever watched because that was the only way to watch anything at all. It doesn't make much sense that resolving a label to a path is linked to caring about the content at that path.ctx.watch
can replace it.ctx.read(label, watch = "no")
shouldn't watch.The latter clearly violates the intent, I would consider changing that behavior a bug fix and don't think it would break anyone.
The former is more impactful to change as it has been the only way to watch for a long time. rules_go would definitely need to change. Luckily
ctx.watch
can be trivially feature detected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree. Just a bit nervous about not having an incompatible flag for it. (so maybe not so "fully" 😅) Adding an incompatible flag for this one isn't super bad, right? It's just a single
if
inStarlarkBaseExternalContext
so shouldn't be a lot of maintenance burden. And we can make it no-op in Bazel 9.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree the change for
path
should come with a flag. But since it will mostly require fixing in rulesets, not user projects, we would need to look into that regardless.