Skip to content

Commit 356e364

Browse files
committed
Replace Version.moduleName with SwiftProtobufInfo.name.
The Namer already had to know the module and used the other constant so generated module references would be correct.
1 parent 2839676 commit 356e364

File tree

9 files changed

+40
-43
lines changed

9 files changed

+40
-43
lines changed

Sources/protoc-gen-swift/Descriptor+Extensions.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ extension FieldDescriptor {
211211
switch type {
212212
case .bool: return "false"
213213
case .string: return "String()"
214-
case .bytes: return "\(Version.moduleName).Internal.emptyData"
214+
case .bytes: return "\(SwiftProtobufInfo.name).Internal.emptyData"
215215
case .group, .message:
216216
return namer.fullName(message: messageType) + "()"
217217
case .enum:
@@ -229,31 +229,31 @@ extension FieldDescriptor {
229229
let valueTraits = valueField.traitsType(namer: namer)
230230
switch valueField.type {
231231
case .message: // Map's can't have a group as the value
232-
return "\(Version.moduleName)._ProtobufMessageMap<\(keyTraits),\(valueTraits)>"
232+
return "\(SwiftProtobufInfo.name)._ProtobufMessageMap<\(keyTraits),\(valueTraits)>"
233233
case .enum:
234-
return "\(Version.moduleName)._ProtobufEnumMap<\(keyTraits),\(valueTraits)>"
234+
return "\(SwiftProtobufInfo.name)._ProtobufEnumMap<\(keyTraits),\(valueTraits)>"
235235
default:
236-
return "\(Version.moduleName)._ProtobufMap<\(keyTraits),\(valueTraits)>"
236+
return "\(SwiftProtobufInfo.name)._ProtobufMap<\(keyTraits),\(valueTraits)>"
237237
}
238238
}
239239
switch type {
240-
case .double: return "\(Version.moduleName).ProtobufDouble"
241-
case .float: return "\(Version.moduleName).ProtobufFloat"
242-
case .int64: return "\(Version.moduleName).ProtobufInt64"
243-
case .uint64: return "\(Version.moduleName).ProtobufUInt64"
244-
case .int32: return "\(Version.moduleName).ProtobufInt32"
245-
case .fixed64: return "\(Version.moduleName).ProtobufFixed64"
246-
case .fixed32: return "\(Version.moduleName).ProtobufFixed32"
247-
case .bool: return "\(Version.moduleName).ProtobufBool"
248-
case .string: return "\(Version.moduleName).ProtobufString"
240+
case .double: return "\(SwiftProtobufInfo.name).ProtobufDouble"
241+
case .float: return "\(SwiftProtobufInfo.name).ProtobufFloat"
242+
case .int64: return "\(SwiftProtobufInfo.name).ProtobufInt64"
243+
case .uint64: return "\(SwiftProtobufInfo.name).ProtobufUInt64"
244+
case .int32: return "\(SwiftProtobufInfo.name).ProtobufInt32"
245+
case .fixed64: return "\(SwiftProtobufInfo.name).ProtobufFixed64"
246+
case .fixed32: return "\(SwiftProtobufInfo.name).ProtobufFixed32"
247+
case .bool: return "\(SwiftProtobufInfo.name).ProtobufBool"
248+
case .string: return "\(SwiftProtobufInfo.name).ProtobufString"
249249
case .group, .message: return namer.fullName(message: messageType)
250-
case .bytes: return "\(Version.moduleName).ProtobufBytes"
251-
case .uint32: return "\(Version.moduleName).ProtobufUInt32"
250+
case .bytes: return "\(SwiftProtobufInfo.name).ProtobufBytes"
251+
case .uint32: return "\(SwiftProtobufInfo.name).ProtobufUInt32"
252252
case .enum: return namer.fullName(enum: enumType)
253-
case .sfixed32: return "\(Version.moduleName).ProtobufSFixed32"
254-
case .sfixed64: return "\(Version.moduleName).ProtobufSFixed64"
255-
case .sint32: return "\(Version.moduleName).ProtobufSInt32"
256-
case .sint64: return "\(Version.moduleName).ProtobufSInt64"
253+
case .sfixed32: return "\(SwiftProtobufInfo.name).ProtobufSFixed32"
254+
case .sfixed64: return "\(SwiftProtobufInfo.name).ProtobufSFixed64"
255+
case .sint32: return "\(SwiftProtobufInfo.name).ProtobufSInt32"
256+
case .sint64: return "\(SwiftProtobufInfo.name).ProtobufSInt64"
257257
}
258258
}
259259
}

Sources/protoc-gen-swift/EnumGenerator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class EnumGenerator {
5858

5959
p.print("\n")
6060
p.print(enumDescriptor.protoSourceComments())
61-
p.print("\(visibility)enum \(swiftRelativeName): \(Version.moduleName).Enum {\n")
61+
p.print("\(visibility)enum \(swiftRelativeName): \(SwiftProtobufInfo.name).Enum {\n")
6262
p.indent()
6363
p.print("\(visibility)typealias RawValue = Int\n")
6464

@@ -120,7 +120,7 @@ class EnumGenerator {
120120

121121
func generateRuntimeSupport(printer p: inout CodePrinter) {
122122
p.print("\n")
123-
p.print("extension \(swiftFullName): \(Version.moduleName)._ProtoNameProviding {\n")
123+
p.print("extension \(swiftFullName): \(SwiftProtobufInfo.name)._ProtoNameProviding {\n")
124124
p.indent()
125125
generateProtoNameProviding(printer: &p)
126126
p.outdent()
@@ -156,7 +156,7 @@ class EnumGenerator {
156156
private func generateProtoNameProviding(printer p: inout CodePrinter) {
157157
let visibility = generatorOptions.visibilitySourceSnippet
158158

159-
p.print("\(visibility)static let _protobuf_nameMap: \(Version.moduleName)._NameMap = [\n")
159+
p.print("\(visibility)static let _protobuf_nameMap: \(SwiftProtobufInfo.name)._NameMap = [\n")
160160
p.indent()
161161
for v in mainEnumValueDescriptorsSorted {
162162
if v.aliases.isEmpty {

Sources/protoc-gen-swift/ExtensionSetGenerator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ExtensionSetGenerator {
4747
default: modifier = ""
4848
}
4949

50-
return "\(Version.moduleName).\(label)\(modifier)ExtensionField"
50+
return "\(SwiftProtobufInfo.name).\(label)\(modifier)ExtensionField"
5151
}
5252

5353
init(descriptor: FieldDescriptor, generatorOptions: GeneratorOptions, namer: SwiftProtobufNamer) {
@@ -81,7 +81,7 @@ class ExtensionSetGenerator {
8181

8282
p.print(
8383
comments,
84-
"\(visibility)\(scope)let \(swiftRelativeExtensionName) = \(Version.moduleName).MessageExtension<\(extensionFieldType)<\(traitsType)>, \(containingTypeSwiftFullName)>(\n")
84+
"\(visibility)\(scope)let \(swiftRelativeExtensionName) = \(SwiftProtobufInfo.name).MessageExtension<\(extensionFieldType)<\(traitsType)>, \(containingTypeSwiftFullName)>(\n")
8585
p.indent()
8686
p.print(
8787
"_protobuf_fieldNumber: \(fieldDescriptor.number),\n",
@@ -223,7 +223,7 @@ class ExtensionSetGenerator {
223223
"/// this .proto file. It can be used any place an `SwiftProtobuf.ExtensionMap` is needed\n",
224224
"/// in parsing, or it can be combined with other `SwiftProtobuf.SimpleExtensionMap`s to create\n",
225225
"/// a larger `SwiftProtobuf.SimpleExtensionMap`.\n",
226-
"\(generatorOptions.visibilitySourceSnippet)let \(filePrefix)\(filenameAsIdentifer)_Extensions: \(Version.moduleName).SimpleExtensionMap = [\n")
226+
"\(generatorOptions.visibilitySourceSnippet)let \(filePrefix)\(filenameAsIdentifer)_Extensions: \(SwiftProtobufInfo.name).SimpleExtensionMap = [\n")
227227
p.indent()
228228
var separator = ""
229229
for e in extensions {

Sources/protoc-gen-swift/FileGenerator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class FileGenerator {
9393
if !fileDescriptor.isBundledProto {
9494
// The well known types ship with the runtime, everything else needs
9595
// to import the runtime.
96-
p.print("import \(Version.moduleName)\n")
96+
p.print("import \(SwiftProtobufInfo.name)\n")
9797
}
9898
if let neededImports = generatorOptions.protoToModuleMappings.neededModules(forFile: fileDescriptor) {
9999
p.print("\n")
@@ -190,10 +190,10 @@ class FileGenerator {
190190
"// incompatible with the version of SwiftProtobuf to which you are linking.\n",
191191
"// Please ensure that you are building against the same version of the API\n",
192192
"// that was used to generate this file.\n",
193-
"fileprivate struct _GeneratedWithProtocGenSwiftVersion: \(Version.moduleName).ProtobufAPIVersionCheck {\n")
193+
"fileprivate struct _GeneratedWithProtocGenSwiftVersion: \(SwiftProtobufInfo.name).ProtobufAPIVersionCheck {\n")
194194
p.indent()
195195
p.print(
196-
"struct _\(v): \(Version.moduleName).ProtobufAPIVersion_\(v) {}\n",
196+
"struct _\(v): \(SwiftProtobufInfo.name).ProtobufAPIVersion_\(v) {}\n",
197197
"typealias Version = _\(v)\n")
198198
p.outdent()
199199
p.print("}\n")

Sources/protoc-gen-swift/MessageFieldGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class MessageFieldGenerator: FieldGeneratorBase, FieldGenerator {
161161
guard isGroupOrMessage && fieldDescriptor.messageType.hasRequiredFields() else { return }
162162

163163
if isRepeated { // Map or Array
164-
p.print("if !\(Version.moduleName).Internal.areAllInitialized(\(storedProperty)) {return false}\n")
164+
p.print("if !\(SwiftProtobufInfo.name).Internal.areAllInitialized(\(storedProperty)) {return false}\n")
165165
} else {
166166
p.print("if let v = \(storedProperty), !v.isInitialized {return false}\n")
167167
}

Sources/protoc-gen-swift/MessageGenerator.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MessageGenerator {
118118

119119
let conformances: String
120120
if isExtensible {
121-
conformances = ": \(Version.moduleName).ExtensibleMessage"
121+
conformances = ": \(SwiftProtobufInfo.name).ExtensibleMessage"
122122
} else {
123123
conformances = ""
124124
}
@@ -127,7 +127,7 @@ class MessageGenerator {
127127
descriptor.protoSourceComments(),
128128
"\(visibility)struct \(swiftRelativeName)\(conformances) {\n")
129129
p.indent()
130-
p.print("// \(Version.moduleName).Message conformance is added in an extension below. See the\n",
130+
p.print("// \(SwiftProtobufInfo.name).Message conformance is added in an extension below. See the\n",
131131
"// `Message` and `Message+*Additions` files in the SwiftProtobuf library for\n",
132132
"// methods supported on all messages.\n")
133133

@@ -137,7 +137,7 @@ class MessageGenerator {
137137

138138
p.print(
139139
"\n",
140-
"\(visibility)var unknownFields = \(Version.moduleName).UnknownStorage()\n")
140+
"\(visibility)var unknownFields = \(SwiftProtobufInfo.name).UnknownStorage()\n")
141141

142142
for o in oneofs {
143143
o.generateMainEnum(printer: &p)
@@ -164,7 +164,7 @@ class MessageGenerator {
164164
if isExtensible {
165165
p.print(
166166
"\n",
167-
"\(visibility)var _protobuf_extensionFieldValues = \(Version.moduleName).ExtensionFieldValueSet()\n")
167+
"\(visibility)var _protobuf_extensionFieldValues = \(SwiftProtobufInfo.name).ExtensionFieldValueSet()\n")
168168
}
169169
if let storage = storage {
170170
if !isExtensible {
@@ -200,7 +200,7 @@ class MessageGenerator {
200200
func generateRuntimeSupport(printer p: inout CodePrinter, file: FileGenerator, parent: MessageGenerator?) {
201201
p.print(
202202
"\n",
203-
"extension \(swiftFullName): \(Version.moduleName).Message, \(Version.moduleName)._MessageImplementationBase, \(Version.moduleName)._ProtoNameProviding {\n")
203+
"extension \(swiftFullName): \(SwiftProtobufInfo.name).Message, \(SwiftProtobufInfo.name)._MessageImplementationBase, \(SwiftProtobufInfo.name)._ProtoNameProviding {\n")
204204
p.indent()
205205

206206
if let parent = parent {
@@ -239,9 +239,9 @@ class MessageGenerator {
239239

240240
private func generateProtoNameProviding(printer p: inout CodePrinter) {
241241
if fields.isEmpty {
242-
p.print("\(visibility)static let _protobuf_nameMap = \(Version.moduleName)._NameMap()\n")
242+
p.print("\(visibility)static let _protobuf_nameMap = \(SwiftProtobufInfo.name)._NameMap()\n")
243243
} else {
244-
p.print("\(visibility)static let _protobuf_nameMap: \(Version.moduleName)._NameMap = [\n")
244+
p.print("\(visibility)static let _protobuf_nameMap: \(SwiftProtobufInfo.name)._NameMap = [\n")
245245
p.indent()
246246
for f in fields {
247247
p.print("\(f.number): \(f.fieldMapNames),\n")
@@ -256,7 +256,7 @@ class MessageGenerator {
256256
///
257257
/// - Parameter p: The code printer.
258258
private func generateDecodeMessage(printer p: inout CodePrinter) {
259-
p.print("\(visibility)mutating func decodeMessage<D: \(Version.moduleName).Decoder>(decoder: inout D) throws {\n")
259+
p.print("\(visibility)mutating func decodeMessage<D: \(SwiftProtobufInfo.name).Decoder>(decoder: inout D) throws {\n")
260260
p.indent()
261261
if storage != nil {
262262
p.print("_ = _uniqueStorage()\n")
@@ -319,7 +319,7 @@ class MessageGenerator {
319319
///
320320
/// - Parameter p: The code printer.
321321
private func generateTraverse(printer p: inout CodePrinter) {
322-
p.print("\(visibility)func traverse<V: \(Version.moduleName).Visitor>(visitor: inout V) throws {\n")
322+
p.print("\(visibility)func traverse<V: \(SwiftProtobufInfo.name).Visitor>(visitor: inout V) throws {\n")
323323
p.indent()
324324
generateWithLifetimeExtension(printer: &p, throws: true) { p in
325325
if let storage = storage {

Sources/protoc-gen-swift/StringUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func trimWhitespace(_ s: String) -> String {
6161
/// \n\r\t\\\'\" and three-digit octal escapes but nothing else.
6262
func escapedToDataLiteral(_ s: String) -> String {
6363
if s.isEmpty {
64-
return "\(Version.moduleName).Internal.emptyData"
64+
return "\(SwiftProtobufInfo.name).Internal.emptyData"
6565
}
6666
var out = "Data(["
6767
var separator = ""

Sources/protoc-gen-swift/Version.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ struct Version {
2727
// or API-changing).
2828
static let compatibilityVersion = 2
2929

30-
// Name of the SwiftProtobuf module
31-
static let moduleName = "SwiftProtobuf"
32-
3330
static let copyright = "Copyright (C) 2014-2017 Apple Inc. and the project authors"
3431
}

Sources/protoc-gen-swift/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct GeneratorPlugin {
101101
+ "In particular, if you have renamed this program, you will need to\n"
102102
+ "adjust the protoc command-line option accordingly.\n"
103103
+ "\n"
104-
+ "The generated Swift output requires the \(Version.moduleName) \(SwiftProtobuf.Version.versionString)\n"
104+
+ "The generated Swift output requires the \(SwiftProtobufInfo.name) \(SwiftProtobuf.Version.versionString)\n"
105105
+ "library be included in your project.\n"
106106
+ "\n"
107107
+ "If you use `swift build` to compile your project, add this to\n"

0 commit comments

Comments
 (0)