Browse Source

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
George Barnett 10 months ago
parent
commit
237ca5f91c

+ 0 - 27
Sources/protoc-gen-grpc-swift/GenerateGRPC.swift

@@ -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,

+ 11 - 7
Sources/protoc-gen-grpc-swift/Options.swift

@@ -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 {
@@ -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)"
     }
   }
 }
@@ -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 {
@@ -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()) {