Skip to content

Commit 8ee79e4

Browse files
committed
Add experimental_strip_nonfunctional_codegen generation option.
Almost all of the upstream generators seem to be adding this options. Adding it now to support any future validations that might need it (likely Protobuf Editions).
1 parent c118e39 commit 8ee79e4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Sources/protoc-gen-swift/GeneratorOptions.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class GeneratorOptions {
5353
let protoToModuleMappings: ProtoFileToModuleMappings
5454
let visibility: Visibility
5555
let implementationOnlyImports: Bool
56+
let experimentalStripNonfunctionalCodegen: Bool
5657

5758
/// A string snippet to insert for the visibility
5859
let visibilitySourceSnippet: String
@@ -63,6 +64,7 @@ class GeneratorOptions {
6364
var visibility: Visibility = .internal
6465
var swiftProtobufModuleName: String? = nil
6566
var implementationOnlyImports: Bool = false
67+
var experimentalStripNonfunctionalCodegen: Bool = false
6668

6769
for pair in parameter.parsedPairs {
6870
switch pair.key {
@@ -100,6 +102,15 @@ class GeneratorOptions {
100102
throw GenerationError.invalidParameterValue(name: pair.key,
101103
value: pair.value)
102104
}
105+
case "experimental_strip_nonfunctional_codegen":
106+
if pair.value.isEmpty { // Also support option without any value.
107+
experimentalStripNonfunctionalCodegen = true
108+
} else if let value = Bool(pair.value) {
109+
experimentalStripNonfunctionalCodegen = value
110+
} else {
111+
throw GenerationError.invalidParameterValue(name: pair.key,
112+
value: pair.value)
113+
}
103114
default:
104115
throw GenerationError.unknownParameter(name: pair.key)
105116
}
@@ -130,6 +141,7 @@ class GeneratorOptions {
130141
}
131142

132143
self.implementationOnlyImports = implementationOnlyImports
144+
self.experimentalStripNonfunctionalCodegen = experimentalStripNonfunctionalCodegen
133145

134146
// ------------------------------------------------------------------------
135147
// Now do "cross option" validations.

0 commit comments

Comments
 (0)