-
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
Fix watching paths in undefined repos in repo rules #21562
Conversation
Watching a path in an undefined repo (eg. `$output_base/external/i_am_undefined/blah`) currently causes an NPE because we expect it to need a skyframe restart when it actually doesn't. The underlying reason is rather convoluted, but the gist is that we request `RepositoryDirectoryValue.Key(@@i_am_undefined)` explicitly, when we don't actually have to -- we can simply use `FileValue.Key($output_base/external/i_am_undefined/blah` directly, and rely on the fact that `FileFunction` knows to request the corresponding `RepositoryDirectoryValue` and behave appropriately when the repo is undefined. (This is due to logic in `ExternalFilesHelper.maybeHandleExternalFile`.) Additionally, this PR removes the `rctx.symlink(watch_target=)` parameter. The symlink target's existence and its contents should not affect the creation of the symlink at all, so there's no reason to ever watch it. Fixes #21483.
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.
... currently causes an NPE because we expect it to need a skyframe restart when it actually doesn't.
The changes look good to me, but couldn't this NPE still show up if something is available in Skyframe that we didn't expect to be ready? I would sleep better with logic preventing that entirely.
Not sure what you mean here -- I was referring to the case where |
Ah, I see, then I agree we don't need to do anything more. |
The code looks reasonable as far as I can tell (although I managed to code myself silly today), but do we want to allow repositories to depend on files in non-existent other repositories? Until now, depending on non-existent repositories caused an error and you are breaking this invariant. I'd rather not because, well, it's another avenue for creativity. |
I don't think any invariant is being broken because until now there was no way to "depend on non-existent repositories" at all -- |
Watching a path in an undefined repo (eg. `$output_base/external/i_am_undefined/blah`) currently causes an NPE because we expect it to need a skyframe restart when it actually doesn't. The underlying reason is rather convoluted, but the gist is that we request `RepositoryDirectoryValue.Key(@@i_am_undefined)` explicitly, when we don't actually have to -- we can simply use `FileValue.Key($output_base/external/i_am_undefined/blah` directly, and rely on the fact that `FileFunction` knows to request the corresponding `RepositoryDirectoryValue` and behave appropriately when the repo is undefined. (This is due to logic in `ExternalFilesHelper.maybeHandleExternalFile`.) Additionally, this PR removes the `rctx.symlink(watch_target=)` parameter. The symlink target's existence and its contents should not affect the creation of the symlink at all, so there's no reason to ever watch it. Fixes bazelbuild#21483. Closes bazelbuild#21562. PiperOrigin-RevId: 612898526 Change-Id: I30deb9d9b2d19e0869517f4b6b126078446745b4
Before this change, you couldn't say "please inform me if this non-existent repo springs into existence", now you can, if I understand correctly. I haven't gamed out all the ways this could go wrong, but it looks like a lot of rope to me. I might be overly cautious here, but is there any reason to allow this functionality as opposed to just bailing out if one tries to watch a file in another repository, which does not exist? |
I see... I don't think there's any explicit reason to allow it; it just happened naturally because that's what FileFunction does. Presumably the same could happen through any other FileFunction dependency on something in |
Watching a path in an undefined repo (eg. `$output_base/external/i_am_undefined/blah`) currently causes an NPE because we expect it to need a skyframe restart when it actually doesn't. The underlying reason is rather convoluted, but the gist is that we request `RepositoryDirectoryValue.Key(@@i_am_undefined)` explicitly, when we don't actually have to -- we can simply use `FileValue.Key($output_base/external/i_am_undefined/blah` directly, and rely on the fact that `FileFunction` knows to request the corresponding `RepositoryDirectoryValue` and behave appropriately when the repo is undefined. (This is due to logic in `ExternalFilesHelper.maybeHandleExternalFile`.) Additionally, this PR removes the `rctx.symlink(watch_target=)` parameter. The symlink target's existence and its contents should not affect the creation of the symlink at all, so there's no reason to ever watch it. Fixes #21483. Closes #21562. Commit aba1186 PiperOrigin-RevId: 612898526 Change-Id: I30deb9d9b2d19e0869517f4b6b126078446745b4 Co-authored-by: Xdng Yng <[email protected]>
I'm afraid it's too late here for me to think through all the ramifications, but in general, we should either think through the consequences of behavior we allow or disallow it. The latter seems to be much simpler. re: making |
ah, indeed -- so it's already possible today. IMO that lowers the priority of this drastically. Depending on the existence of a repo name through |
SGTM. I'd be worried if it was a regression, but it's not. |
Watching a path in an undefined repo (eg.
$output_base/external/i_am_undefined/blah
) currently causes an NPE because we expect it to need a skyframe restart when it actually doesn't. The underlying reason is rather convoluted, but the gist is that we requestRepositoryDirectoryValue.Key(@@i_am_undefined)
explicitly, when we don't actually have to -- we can simply useFileValue.Key($output_base/external/i_am_undefined/blah
directly, and rely on the fact thatFileFunction
knows to request the correspondingRepositoryDirectoryValue
and behave appropriately when the repo is undefined. (This is due to logic inExternalFilesHelper.maybeHandleExternalFile
.)Additionally, this PR removes the
rctx.symlink(watch_target=)
parameter. The symlink target's existence and its contents should not affect the creation of the symlink at all, so there's no reason to ever watch it.Fixes #21483.