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

Add option to the protoc code generator to avoid generating deprecated code #3089

Merged

Conversation

mgodave
Copy link
Contributor

@mgodave mgodave commented Nov 6, 2024

Motivation

The generated ServiceTalk gRPC stubs make use of deprecated calls. This causes a problem when -Werror is used to build the code since it will automatically fail the build. We should allow users who have already migrated their code to prevent the protoc compiler from generating and using deprecated references.

Modifications

Add an option, skipDeprecated, as part of the protoc compiler configuration, to tell the generator to leave out deprecated references.

Result

Example: Tester.java before/after (option enabled) https://gist.github.com/mgodave/5772193156ca740ea90ca11bafb3da56
Example: Tester.java before/after (option disabled) https://gist.github.com/mgodave/dcff4574f0b70cb39c3bd97a859565ac

Remove

  • initSerializationProvider, reason: ContentCodec is deprecated
  • isSupportedMessageCodingsEmpty, reason ContentCodec is deprecated
  • Deprecated ServiceFactory constructors
  • ServiceFactory::Builder references to ContentCodec
  • Generated client metadata and associated methods, reason: deprecated

Testing

Manually tested:

  • Add new option to ServiceTalk/examples/grpc/protoc-options and use it to generate test_service.proto which covers all combinations of streaming (or not) services.

@mgodave mgodave marked this pull request as ready for review November 7, 2024 15:10
Copy link
Contributor

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Token approval: this looks fine to me but please wait for a more experienced reviewer before merging.

How was it tested? I presume manually, but it would be good to document it in the PR description.

@mgodave
Copy link
Contributor Author

mgodave commented Nov 14, 2024

New diff from test_service.proto: https://gist.github.com/mgodave/5772193156ca740ea90ca11bafb3da56

mgodave and others added 2 commits November 15, 2024 09:06
…oc/Main.java

Co-authored-by: Idel Pivnitskiy <idel.pivnitskiy@apple.com>
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good progress! New generated code looks much better than without skipDeprecated option.
Just a few adjustments for the final findings and we are ready to ship:

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

The generated code with skipDeprecated=true looks good. I also checked diff for default behavior. Many things changed their order, which is ok. Couldn't spot anything suspicious, but would be great if someone can have another look at the diff @bryce-anderson. We need to make sure current users won't be affected.

@mgodave
Copy link
Contributor Author

mgodave commented Nov 18, 2024

Great work!

The generated code with skipDeprecated=true looks good. I also checked diff for default behavior. Many things changed their order, which is ok. Couldn't spot anything suspicious, but would be great if someone can have another look at the diff @bryce-anderson. We need to make sure current users won't be affected.

The ordering is probably based on me trying to keep the blocks of skipDeprecated code together so that, at some point, we can more easily identify which sections can just be deleted. It should be fine, javapoet appears to at least do basic stuff like keep fields on top, etc... The only way current users would be affected would be if we changed anything else without the option. I didn't do a diff of a before and after. Let me do that as a quick check.

Copy link
Contributor

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also looked at a diff of the generated code and didn't see anything suspicious. That said, it's a lot of generated code. 😅

@idelpivnitskiy idelpivnitskiy merged commit f8abe11 into apple:main Nov 19, 2024
11 checks passed
@mgodave mgodave deleted the drusek/skip-generating-deprecated-calls branch November 19, 2024 16:09
mgodave added a commit to mgodave/servicetalk that referenced this pull request Nov 19, 2024
…d code (apple#3089)

### Motivation

The generated ServiceTalk gRPC stubs make use of deprecated calls. This causes a problem when `-Werror` is used to build the code since it will automatically fail the build. We should allow users who have already migrated their code to prevent the protoc compiler from generating and using deprecated references.

### Modifications

Add an option, `skipDeprecated`, as part of the protoc compiler configuration, to tell the generator to leave out deprecated references.

Remove
- initSerializationProvider, reason: ContentCodec is deprecated
- isSupportedMessageCodingsEmpty, reason ContentCodec is deprecated
- Deprecated ServiceFactory constructors
- ServiceFactory::Builder references to ContentCodec
- Generated client metadata and associated methods, reason: deprecated

### Result

Users can generate gRPC stubs without deprecated code.

### Testing

Manually tested:
- Add new option to ServiceTalk/examples/grpc/protoc-options and use it to generate test_service.proto which covers all combinations of streaming (or not) services.
mgodave added a commit to mgodave/servicetalk that referenced this pull request Nov 19, 2024
…d code (apple#3089)

### Motivation

The generated ServiceTalk gRPC stubs make use of deprecated calls. This causes a problem when `-Werror` is used to build the code since it will automatically fail the build. We should allow users who have already migrated their code to prevent the protoc compiler from generating and using deprecated references.

### Modifications

Add an option, `skipDeprecated`, as part of the protoc compiler configuration, to tell the generator to leave out deprecated references.

Remove
- initSerializationProvider, reason: ContentCodec is deprecated
- isSupportedMessageCodingsEmpty, reason ContentCodec is deprecated
- Deprecated ServiceFactory constructors
- ServiceFactory::Builder references to ContentCodec
- Generated client metadata and associated methods, reason: deprecated

### Result

Users can generate gRPC stubs without deprecated code.

### Testing

Manually tested:
- Add new option to ServiceTalk/examples/grpc/protoc-options and use it to generate test_service.proto which covers all combinations of streaming (or not) services.
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.

3 participants