|
@@ -90,7 +90,6 @@ func uniqueOutputFileName(component: String, fileDescriptor: FileDescriptor, fil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func main() throws {
|
|
func main() throws {
|
|
|
-
|
|
|
|
|
// initialize responses
|
|
// initialize responses
|
|
|
var response = Google_Protobuf_Compiler_CodeGeneratorResponse()
|
|
var response = Google_Protobuf_Compiler_CodeGeneratorResponse()
|
|
|
|
|
|
|
@@ -103,15 +102,21 @@ func main() throws {
|
|
|
// Build the SwiftProtobufPluginLibrary model of the plugin input
|
|
// Build the SwiftProtobufPluginLibrary model of the plugin input
|
|
|
let descriptorSet = DescriptorSet(protos: request.protoFile)
|
|
let descriptorSet = DescriptorSet(protos: request.protoFile)
|
|
|
|
|
|
|
|
- // process each .proto file separately
|
|
|
|
|
- for fileDescriptor in descriptorSet.files {
|
|
|
|
|
|
|
+ // We need to generate conformance to `GRPCPayload` for request/response types. Track which
|
|
|
|
|
+ // types we've seen to avoid generating the conformance multiple times.
|
|
|
|
|
+ var observedMessages = Set<String>()
|
|
|
|
|
+
|
|
|
|
|
+ // process each .proto file in filename order in an attempt to stabilise the output (i.e. where
|
|
|
|
|
+ // conformance to `GRPCPayload` is generated)
|
|
|
|
|
+ for fileDescriptor in descriptorSet.files.sorted(by: { $0.name < $1.name }) {
|
|
|
if fileDescriptor.services.count > 0 {
|
|
if fileDescriptor.services.count > 0 {
|
|
|
let grpcFileName = uniqueOutputFileName(component: "grpc", fileDescriptor: fileDescriptor, fileNamingOption: options.fileNaming)
|
|
let grpcFileName = uniqueOutputFileName(component: "grpc", fileDescriptor: fileDescriptor, fileNamingOption: options.fileNaming)
|
|
|
- let grpcGenerator = Generator(fileDescriptor, options: options)
|
|
|
|
|
|
|
+ let grpcGenerator = Generator(fileDescriptor, options: options, observedMessages: observedMessages)
|
|
|
var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
|
|
var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
|
|
|
grpcFile.name = grpcFileName
|
|
grpcFile.name = grpcFileName
|
|
|
grpcFile.content = grpcGenerator.code
|
|
grpcFile.content = grpcGenerator.code
|
|
|
response.file.append(grpcFile)
|
|
response.file.append(grpcFile)
|
|
|
|
|
+ observedMessages.formUnion(grpcGenerator.observedMessages)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|