@@ -20,70 +20,18 @@ public struct TargetDescription: Equatable, Codable {
20
20
}
21
21
22
22
/// Represents a target's dependency on another entity.
23
- public enum Dependency : Equatable , ExpressibleByStringLiteral , Codable {
23
+ public enum Dependency : Equatable {
24
24
case target( name: String , condition: PackageConditionDescription ? )
25
25
case product( name: String , package : String ? , condition: PackageConditionDescription ? )
26
26
case byName( name: String , condition: PackageConditionDescription ? )
27
27
28
- public init ( stringLiteral value: String ) {
29
- self = . byName( name: value, condition: nil )
30
- }
31
-
32
28
public static func target( name: String ) -> Dependency {
33
29
return . target( name: name, condition: nil )
34
30
}
35
31
36
32
public static func product( name: String , package : String ? = nil ) -> Dependency {
37
33
return . product( name: name, package : package , condition: nil )
38
34
}
39
-
40
- private enum CodingKeys : String , CodingKey {
41
- case target, product, byName
42
- }
43
-
44
- public func encode( to encoder: Encoder ) throws {
45
- var container = encoder. container ( keyedBy: CodingKeys . self)
46
- switch self {
47
- case let . target( a1, a2) :
48
- var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . target)
49
- try unkeyedContainer. encode ( a1)
50
- try unkeyedContainer. encode ( a2)
51
- case let . product( a1, a2, a3) :
52
- var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . product)
53
- try unkeyedContainer. encode ( a1)
54
- try unkeyedContainer. encode ( a2)
55
- try unkeyedContainer. encode ( a3)
56
- case let . byName( a1, a2) :
57
- var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . byName)
58
- try unkeyedContainer. encode ( a1)
59
- try unkeyedContainer. encode ( a2)
60
- }
61
- }
62
-
63
- public init ( from decoder: Decoder ) throws {
64
- let values = try decoder. container ( keyedBy: CodingKeys . self)
65
- guard let key = values. allKeys. first ( where: values. contains) else {
66
- throw DecodingError . dataCorrupted ( . init( codingPath: decoder. codingPath, debugDescription: " Did not find a matching key " ) )
67
- }
68
- switch key {
69
- case . target:
70
- var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
71
- let a1 = try unkeyedValues. decode ( String . self)
72
- let a2 = try unkeyedValues. decodeIfPresent ( PackageConditionDescription . self)
73
- self = . target( name: a1, condition: a2)
74
- case . product:
75
- var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
76
- let a1 = try unkeyedValues. decode ( String . self)
77
- let a2 = try unkeyedValues. decodeIfPresent ( String . self)
78
- let a3 = try unkeyedValues. decodeIfPresent ( PackageConditionDescription . self)
79
- self = . product( name: a1, package : a2, condition: a3)
80
- case . byName:
81
- var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
82
- let a1 = try unkeyedValues. decode ( String . self)
83
- let a2 = try unkeyedValues. decodeIfPresent ( PackageConditionDescription . self)
84
- self = . byName( name: a1, condition: a2)
85
- }
86
- }
87
35
}
88
36
89
37
public struct Resource : Codable , Equatable {
@@ -222,3 +170,59 @@ public struct TargetDescription: Equatable, Codable {
222
170
self . checksum = checksum
223
171
}
224
172
}
173
+
174
+ extension TargetDescription . Dependency : Codable {
175
+ private enum CodingKeys : String , CodingKey {
176
+ case target, product, byName
177
+ }
178
+
179
+ public func encode( to encoder: Encoder ) throws {
180
+ var container = encoder. container ( keyedBy: CodingKeys . self)
181
+ switch self {
182
+ case let . target( a1, a2) :
183
+ var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . target)
184
+ try unkeyedContainer. encode ( a1)
185
+ try unkeyedContainer. encode ( a2)
186
+ case let . product( a1, a2, a3) :
187
+ var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . product)
188
+ try unkeyedContainer. encode ( a1)
189
+ try unkeyedContainer. encode ( a2)
190
+ try unkeyedContainer. encode ( a3)
191
+ case let . byName( a1, a2) :
192
+ var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . byName)
193
+ try unkeyedContainer. encode ( a1)
194
+ try unkeyedContainer. encode ( a2)
195
+ }
196
+ }
197
+
198
+ public init ( from decoder: Decoder ) throws {
199
+ let values = try decoder. container ( keyedBy: CodingKeys . self)
200
+ guard let key = values. allKeys. first ( where: values. contains) else {
201
+ throw DecodingError . dataCorrupted ( . init( codingPath: decoder. codingPath, debugDescription: " Did not find a matching key " ) )
202
+ }
203
+ switch key {
204
+ case . target:
205
+ var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
206
+ let a1 = try unkeyedValues. decode ( String . self)
207
+ let a2 = try unkeyedValues. decodeIfPresent ( PackageConditionDescription . self)
208
+ self = . target( name: a1, condition: a2)
209
+ case . product:
210
+ var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
211
+ let a1 = try unkeyedValues. decode ( String . self)
212
+ let a2 = try unkeyedValues. decodeIfPresent ( String . self)
213
+ let a3 = try unkeyedValues. decodeIfPresent ( PackageConditionDescription . self)
214
+ self = . product( name: a1, package : a2, condition: a3)
215
+ case . byName:
216
+ var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
217
+ let a1 = try unkeyedValues. decode ( String . self)
218
+ let a2 = try unkeyedValues. decodeIfPresent ( PackageConditionDescription . self)
219
+ self = . byName( name: a1, condition: a2)
220
+ }
221
+ }
222
+ }
223
+
224
+ extension TargetDescription . Dependency : ExpressibleByStringLiteral {
225
+ public init ( stringLiteral value: String ) {
226
+ self = . byName( name: value, condition: nil )
227
+ }
228
+ }
0 commit comments