Skip to content

Commit 237ca5f

Browse files
authored
Don't generate reflection data. (#51)
Motivation: v1 generated reflection data via the protoc plugin; this wasn't remvoed from v2 but the v2 reflection servcice doesn't use data in the same format. Instead, v2 expects users to invoke protoc directly to generate a descriptor set. This makes the option redundant: it can be called but the output can't be used. Modifications: - Remove the reflection data generating code and have the option throw an error. Result: Less code
1 parent 9cd9d4e commit 237ca5f

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

Sources/protoc-gen-grpc-swift/GenerateGRPC.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,10 @@ final class GenerateGRPC: SwiftProtobufPluginLibrary.CodeGenerator {
5555
let options = try GeneratorOptions(parameter: parameter)
5656

5757
for descriptor in fileDescriptors {
58-
if options.generateReflectionData {
59-
try self.generateReflectionData(
60-
descriptor,
61-
options: options,
62-
outputs: outputs
63-
)
64-
}
65-
6658
try self.generateV2Stubs(descriptor, options: options, outputs: outputs)
6759
}
6860
}
6961

70-
private func generateReflectionData(
71-
_ descriptor: FileDescriptor,
72-
options: GeneratorOptions,
73-
outputs: any GeneratorOutputs
74-
) throws {
75-
let fileName = self.uniqueOutputFileName(
76-
fileDescriptor: descriptor,
77-
fileNamingOption: options.fileNaming,
78-
extension: "reflection"
79-
)
80-
81-
var options = ExtractProtoOptions()
82-
options.includeSourceCodeInfo = true
83-
let proto = descriptor.extractProto(options: options)
84-
let serializedProto = try proto.serializedData()
85-
let reflectionData = serializedProto.base64EncodedString()
86-
try outputs.add(fileName: fileName, contents: reflectionData)
87-
}
88-
8962
private func generateV2Stubs(
9063
_ descriptor: FileDescriptor,
9164
options: GeneratorOptions,

Sources/protoc-gen-grpc-swift/Options.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ enum GenerationError: Error, CustomStringConvertible {
2525
case invalidParameterValue(name: String, value: String)
2626
/// Raised to wrap another error but provide a context message.
2727
case wrappedError(message: String, error: any Error)
28+
/// The parameter isn't supported.
29+
case unsupportedParameter(name: String, message: String)
2830

2931
var description: String {
3032
switch self {
@@ -34,6 +36,8 @@ enum GenerationError: Error, CustomStringConvertible {
3436
return "Unknown value for generation parameter '\(name)': '\(value)'"
3537
case let .wrappedError(message, error):
3638
return "\(message): \(error)"
39+
case let .unsupportedParameter(name, message):
40+
return "Unsupported parameter '\(name)': \(message)"
3741
}
3842
}
3943
}
@@ -49,8 +53,6 @@ struct GeneratorOptions {
4953
private(set) var fileNaming = FileNaming.fullPath
5054
private(set) var extraModuleImports: [String] = []
5155

52-
private(set) var generateReflectionData = false
53-
5456
private(set) var config: ProtobufCodeGenerator.Config = .defaults
5557

5658
init(parameter: any CodeGeneratorParameter) throws {
@@ -129,11 +131,13 @@ struct GeneratorOptions {
129131
}
130132

131133
case "ReflectionData":
132-
if let value = Bool(pair.value.lowercased()) {
133-
self.generateReflectionData = value
134-
} else {
135-
throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value)
136-
}
134+
throw GenerationError.unsupportedParameter(
135+
name: pair.key,
136+
message: """
137+
The reflection service uses descriptor sets. Refer to the protoc docs and the \
138+
'--descriptor_set_out' option for more information.
139+
"""
140+
)
137141

138142
case "UseAccessLevelOnImports":
139143
if let value = Bool(pair.value.lowercased()) {

0 commit comments

Comments
 (0)