-
Notifications
You must be signed in to change notification settings - Fork 6
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
Generate code file for protos with no definitions #27
Conversation
Motivation To prepare for use in a SwiftPM build plugin which requires deterministic output files and to match the behavior of `proto-gen-swift` we should generate a source file even if no definitions are found. Modifications: We no longer return early in the case of no definitions being found. Result: We will generate a Swift source file even if no definitions are found.
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.
Can you add a test for this?
Obviously it'd make more sense to get grpc/grpc-swift#2151 merged first so we don't need to update the test afterwards.
You can modify dev/protos/generate.sh
so that a descriptor set is generated for foo-messages.proto
, once you have that it should be straightforward to add one by following other examples in GRPCProtobufCodeGenTests
.
* Add empty proto file test * Add a preamble to `foo-messages.proto` * Don't unconditionally add a dependency on `GRPCProtobuf` if there are no services * Add the new test case code generation to `dev/protos/generate.sh` * depend on `grpc-swift` `main` to pick up empty file generation changes.
f3164b2
to
5731604
Compare
@@ -31,7 +31,7 @@ let products: [Product] = [ | |||
let dependencies: [Package.Dependency] = [ | |||
.package( | |||
url: "https://github.com/grpc/grpc-swift.git", | |||
exact: "2.0.0-beta.2" | |||
branch: "main" |
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.
@glbrntt note this change. I'm happy to take a different approach than this if you'd rather.
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.
Nope, this is good. We only switched to exact
for the tagged releases, main
is fine between releases.
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.
One edge case bug but looks good otherwise
@@ -31,7 +31,7 @@ let products: [Product] = [ | |||
let dependencies: [Package.Dependency] = [ | |||
.package( | |||
url: "https://github.com/grpc/grpc-swift.git", | |||
exact: "2.0.0-beta.2" | |||
branch: "main" |
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.
Nope, this is good. We only switched to exact
for the tagged releases, main
is fine between releases.
if file.services.count > 0 { | ||
codeDependencies.append(Dependency(module: "GRPCProtobuf", accessLevel: .internal)) | ||
} |
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 isn't quite right: we'll still generate some imports in some cases unnecessarily (i.e. if the file defines a message which depends on a type which is bundled with SwiftProtobuf). We should return the empty array if there are no services.
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.
Ah, good point
This change is broken out of #26
Motivation
To prepare for use in a SwiftPM build plugin which requires deterministic output files and to match the behavior of
proto-gen-swift
we should generate a source file even if no definitions are found.Modifications:
foo-messages.proto
GRPCProtobuf
if there are no servicesdev/protos/generate.sh
grpc-swift
main
to pick up empty file generation changes.Result:
We will generate a Swift source file even if no definitions are found.