Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions Sources/protoc-gen-grpc-swift/GenerateGRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,10 @@ final class GenerateGRPC: SwiftProtobufPluginLibrary.CodeGenerator {
let options = try GeneratorOptions(parameter: parameter)

for descriptor in fileDescriptors {
if options.generateReflectionData {
try self.generateReflectionData(
descriptor,
options: options,
outputs: outputs
)
}

try self.generateV2Stubs(descriptor, options: options, outputs: outputs)
}
}

private func generateReflectionData(
_ descriptor: FileDescriptor,
options: GeneratorOptions,
outputs: any GeneratorOutputs
) throws {
let fileName = self.uniqueOutputFileName(
fileDescriptor: descriptor,
fileNamingOption: options.fileNaming,
extension: "reflection"
)

var options = ExtractProtoOptions()
options.includeSourceCodeInfo = true
let proto = descriptor.extractProto(options: options)
let serializedProto = try proto.serializedData()
let reflectionData = serializedProto.base64EncodedString()
try outputs.add(fileName: fileName, contents: reflectionData)
}

private func generateV2Stubs(
_ descriptor: FileDescriptor,
options: GeneratorOptions,
Expand Down
18 changes: 11 additions & 7 deletions Sources/protoc-gen-grpc-swift/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ enum GenerationError: Error, CustomStringConvertible {
case invalidParameterValue(name: String, value: String)
/// Raised to wrap another error but provide a context message.
case wrappedError(message: String, error: any Error)
/// The parameter isn't supported.
case unsupportedParameter(name: String, message: String)

var description: String {
switch self {
Expand All @@ -34,6 +36,8 @@ enum GenerationError: Error, CustomStringConvertible {
return "Unknown value for generation parameter '\(name)': '\(value)'"
case let .wrappedError(message, error):
return "\(message): \(error)"
case let .unsupportedParameter(name, message):
return "Unsupported parameter '\(name)': \(message)"
}
}
}
Expand All @@ -49,8 +53,6 @@ struct GeneratorOptions {
private(set) var fileNaming = FileNaming.fullPath
private(set) var extraModuleImports: [String] = []

private(set) var generateReflectionData = false

private(set) var config: ProtobufCodeGenerator.Config = .defaults

init(parameter: any CodeGeneratorParameter) throws {
Expand Down Expand Up @@ -129,11 +131,13 @@ struct GeneratorOptions {
}

case "ReflectionData":
if let value = Bool(pair.value.lowercased()) {
self.generateReflectionData = value
} else {
throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value)
}
throw GenerationError.unsupportedParameter(
name: pair.key,
message: """
The reflection service uses descriptor sets. Refer to the protoc docs and the \
'--descriptor_set_out' option for more information.
"""
)

case "UseAccessLevelOnImports":
if let value = Bool(pair.value.lowercased()) {
Expand Down