@@ -38,6 +38,13 @@ public struct ProtoFileToModuleMappings {
38
38
/// access it to verify things.
39
39
let mappings : [ String : String ]
40
40
41
+ /// A Boolean value that indicates that there were developer provided
42
+ /// mappings.
43
+ ///
44
+ /// Since `mappings` will have the bundled proto files also, this is used
45
+ /// to track whether there are any provided mappings.
46
+ public let hasMappings : Bool
47
+
41
48
/// The name of the runtime module for SwiftProtobuf (usually "SwiftProtobuf").
42
49
/// We expect to find the WKTs in the module named here.
43
50
public let swiftProtobufModuleName : String
@@ -71,6 +78,7 @@ public struct ProtoFileToModuleMappings {
71
78
public init ( moduleMappingsProto mappings: SwiftProtobuf_GenSwift_ModuleMappings , swiftProtobufModuleName: String ? ) throws {
72
79
self . swiftProtobufModuleName = swiftProtobufModuleName ?? defaultSwiftProtobufModuleName
73
80
var builder = wktMappings ( swiftProtobufModuleName: self . swiftProtobufModuleName)
81
+ let initialCount = builder. count
74
82
for (idx, mapping) in mappings. mapping. lazy. enumerated ( ) {
75
83
if mapping. moduleName. isEmpty {
76
84
throw LoadError . entryMissingModuleName ( mappingIndex: idx)
@@ -92,6 +100,7 @@ public struct ProtoFileToModuleMappings {
92
100
}
93
101
}
94
102
self . mappings = builder
103
+ self . hasMappings = initialCount != builder. count
95
104
}
96
105
97
106
public init ( ) {
@@ -110,6 +119,7 @@ public struct ProtoFileToModuleMappings {
110
119
/// Returns the list of modules that need to be imported for a given file based on
111
120
/// the dependencies it has.
112
121
public func neededModules( forFile file: FileDescriptor ) -> [ String ] ? {
122
+ guard hasMappings else { return nil }
113
123
if file. dependencies. isEmpty {
114
124
return nil
115
125
}
0 commit comments