apple / servicetalk

A networking framework that evolves with your application
https://docs.servicetalk.io
Apache License 2.0
927 stars 181 forks source link

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

Closed mgodave closed 5 days ago

mgodave commented 2 weeks ago

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

Testing

Manually tested:

mgodave commented 1 week ago

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

mgodave commented 6 days ago

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.