-
Notifications
You must be signed in to change notification settings - Fork 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(build): Prevent duplicated client/server generated code #121
fix(build): Prevent duplicated client/server generated code #121
Conversation
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.
Thanks for this! I think you may need to rebase against master since we are updating our toolchain to stable
.
The tonic-build process collects up RPC services as they are provided by prost, before writing them out as part of the finalization step for a given protocol buffer package. In the case of imported protocol buffer packages, there may be RPC services included by import in addition to those in the top-level package. Therefore it is necessary to make sure each set of client/server services gathered by tonic-build is cleared after the finalization process for a given protocol buffer package, otherwise they will be incorrectly aggregated as the generation process proceeds through the subsequent packages.
A simple test case that will fail to build without a fix to prevent RPC services being duplicated into inappropriate modules (that related to particular protocol buffer packages).
Introduces an additional case that captures making sure services defined before including a package with additional services doesn't incidentially clear such precursor services from the including package.
9b2d659
to
c748fb2
Compare
Should be rebased to master that uses the stable toolchain now |
👍 thanks @LucioFranco! |
Nice work! |
…#121) * fix(build): Prevent duplicated client/server generated code The tonic-build process collects up RPC services as they are provided by prost, before writing them out as part of the finalization step for a given protocol buffer package. In the case of imported protocol buffer packages, there may be RPC services included by import in addition to those in the top-level package. Therefore it is necessary to make sure each set of client/server services gathered by tonic-build is cleared after the finalization process for a given protocol buffer package, otherwise they will be incorrectly aggregated as the generation process proceeds through the subsequent packages. * Test case for duplicated client/server generated code A simple test case that will fail to build without a fix to prevent RPC services being duplicated into inappropriate modules (that related to particular protocol buffer packages). * Additional test case for included_service Introduces an additional case that captures making sure services defined before including a package with additional services doesn't incidentially clear such precursor services from the including package. * Fix unnecessary newline to keep `cargo fmt` happy
Motivation
The tonic-build process collects up RPC services as they are provided by prost, before writing them out as part of the finalization step for a given protocol buffer package.
In the case of imported protocol buffer packages, there may be RPC services included by import in addition to those in the top-level package. Therefore it is necessary to make sure each set of client/server services gathered by tonic-build is cleared after the finalization process for a given protocol buffer package, otherwise they will be incorrectly aggregated as the generation process proceeds through the subsequent packages.
This incorrect behaviour is currently observed in tonic-build.
Solution
Reset the
TokenStream
s that capture the services for client and server use-cases after the finalization process has written out the generated code.