-
Notifications
You must be signed in to change notification settings - Fork 345
Fix bufimageutil issues regarding weak imports #4322
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
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
| // Keep 2: comment on package | ||
| package foo.bar; | ||
| // Keep if NestedFoo: comment on import any.proto | ||
| import "google/protobuf/any.proto"; |
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.
Annoyingly, this should be import weak. The actual filtered descriptor and source code info is correct. The issue turns out to be the way we package up the descriptor protos into protoreflect.FileDescriptor instances: those types no longer have any support for weak imports as of v1.36.5. 🤷
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, noticed that when we did the upgrade here :< #3653
| for i, indexFrom := range weakDependencies { | ||
| weakFrom := int32(i) | ||
| path := append(weakDependencyPath, weakFrom) | ||
| indexTo := dependencyChanges[indexFrom] | ||
| if indexTo == -1 { | ||
| sourcePathsRemap.markDeleted(path) | ||
| } else { | ||
| if indexTo != indexFrom { | ||
| sourcePathsRemap.markMoved(path, indexTo) | ||
| weakTo := int32(len(newWeakDependencies)) | ||
| if weakTo != weakFrom { | ||
| sourcePathsRemap.markMoved(path, weakTo) |
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.
This is the actual fix. Other stuff in this PR is incidental changes/improvement (trying to leave everything in better shape than when I arrived) and the updated test outputs.
| // TODO: Add support for option dependencies when buf CLI supports edition 2024. | ||
| if len(fileDescriptor.GetOptionDependency()) > 0 { | ||
| return nil, nil, nil, false, errors.New("edition 2024 not yet supported: cannot filter a file descriptor with option dependencies") | ||
| } |
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.
This is mostly a note for myself, I appreciate the TODO, I'm porting over the new compiler for edition 2024 support right now, so this is helpful for me when I rebase on this. Thank you!
I was porting a lot of this code to a new stand-alone package (for now, in the bufbuild/extra repo) and when I was comparing test output in those ported tests to the original golden files in this package, there were some discrepancies. I was able to understand all of the discrepancies except ones related to weak imports in the "testdata/sourcecodeinfo" files. It turns out that there was a bug in the logic, that happened to manifest slightly differently between this original code and the ported code in extra.
So this fixes the logic. The issue is that it was using the "from" and "to" indexes in the
dependenciesfield ofFileDescriptorProtowhen updating source code info for theweak_dependenciesfield 😞. So this fixes that.I also updated the "testdata/sourcecodeinfo" golden files to include the actual filtered sources, instead of only the source code info blob, in order to compare the filtered source code info to those filtered sources when debugging. I updated a handful of other small things, too, like fixing stale symbols in doc comments.