Skip to content
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

Preserve interpreted options when input to compiler is already-built FileDescriptorProto #217

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

jhump
Copy link
Member

@jhump jhump commented Dec 6, 2023

When a resolver provides an input to the compiler in the form of a *descriptorpb.FileDescriptorProto (instead of as source code, or as a fully-baked protoreflect.FileDescriptor), the step that interprets options could inadvertently clobber field options (thinking it was the case that the options were empty, just because there were no uninterpreted options to process). Also, the linker.Result.CanonicalProto() method would also clobber options, even if it had no canonical serialized bytes to replace them.

These issues were discovered when trying to upgrade github.com/jhump/protoreflect to the latest v0.7.0. This has likely been an issue for a while, but was now noticed because the latest/current google/protobuf/descriptor.proto (which is used in protoreflect's desc/protoparse package) now includes options on some fields. When that file descriptor proto is used as a compiler input, those options were getting stripped from the final, compiled result.

This adds a test to catch this case here, too.

@jhump jhump requested a review from Alfus December 6, 2023 15:35
@jhump jhump changed the title Preserve interpreted options when input to compiler is already-build FileDescriptorProto Preserve interpreted options when input to compiler is already-built FileDescriptorProto Dec 6, 2023
@jhump jhump merged commit d108cc8 into main Dec 6, 2023
10 checks passed
@jhump jhump deleted the jh/fix-compiler-resetting-options branch December 6, 2023 18:17
jhump added a commit that referenced this pull request Dec 7, 2023
…FileDescriptorProto (#217)

When a resolver provides an input to the compiler in the form of a
`*descriptorpb.FileDescriptorProto` (instead of as source code, or as a
fully-baked `protoreflect.FileDescriptor`), the step that interprets
options could inadvertently clobber field options (thinking it was the
case that the options were empty, just because there were no
uninterpreted options to process). Also, the
`linker.Result.CanonicalProto()` method would also clobber options, even
if it had no canonical serialized bytes to replace them. This commit
fixes both of these issues.
kralicky pushed a commit to kralicky/protocompile that referenced this pull request Feb 7, 2024
…FileDescriptorProto (bufbuild#217)

When a resolver provides an input to the compiler in the form of a
`*descriptorpb.FileDescriptorProto` (instead of as source code, or as a
fully-baked `protoreflect.FileDescriptor`), the step that interprets
options could inadvertently clobber field options (thinking it was the
case that the options were empty, just because there were no
uninterpreted options to process). Also, the
`linker.Result.CanonicalProto()` method would also clobber options, even
if it had no canonical serialized bytes to replace them. This commit
fixes both of these issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants