Skip to content

Commit

Permalink
Only generate services described in files in the codegen request
Browse files Browse the repository at this point in the history
Motivation:

Code should only be generated for files listed in the codegen request.
This regressed in grpc#889.

Modifications:

- Drive code generation from files to generate

Result:

Resolves grpc#1057
  • Loading branch information
glbrntt committed Nov 27, 2020
1 parent 452a284 commit b238983
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Sources/protoc-gen-grpc-swift/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,20 @@ func main() throws {
let descriptorSet = DescriptorSet(protos: request.protoFile)

// Only generate output for services.
for fileDescriptor in descriptorSet.files where !fileDescriptor.services.isEmpty {
let grpcFileName = uniqueOutputFileName(
component: "grpc",
fileDescriptor: fileDescriptor,
fileNamingOption: options.fileNaming
)
let grpcGenerator = Generator(fileDescriptor, options: options)
var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
grpcFile.name = grpcFileName
grpcFile.content = grpcGenerator.code
response.file.append(grpcFile)
for name in request.fileToGenerate {
let fileDescriptor = descriptorSet.lookupFileDescriptor(protoName: name)
if !fileDescriptor.services.isEmpty {
let grpcFileName = uniqueOutputFileName(
component: "grpc",
fileDescriptor: fileDescriptor,
fileNamingOption: options.fileNaming
)
let grpcGenerator = Generator(fileDescriptor, options: options)
var grpcFile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
grpcFile.name = grpcFileName
grpcFile.content = grpcGenerator.code
response.file.append(grpcFile)
}
}

// return everything to the caller
Expand Down

0 comments on commit b238983

Please sign in to comment.