@@ -62,25 +62,25 @@ public enum XCBuildMessage {
62
62
}
63
63
64
64
public struct TaskUpToDateInfo {
65
- let targetID : Int
66
- let targetSignature : String
65
+ let targetID : Int ?
66
+ let taskSignature : String
67
67
let parentTaskID : Int ?
68
68
}
69
69
70
70
public struct TaskStartedInfo {
71
71
let taskID : Int
72
- let targetID : Int
73
- let targetSignature : String
72
+ let targetID : Int ?
73
+ let taskSignature : String
74
74
let parentTaskID : Int ?
75
75
let ruleInfo : String
76
76
let interestingPath : AbsolutePath ?
77
- let commandLineDisplayString : String
77
+ let commandLineDisplayString : String ?
78
78
let executionDescription : String
79
79
}
80
80
81
81
public struct TaskDiagnosticInfo {
82
82
let taskID : Int
83
- let targetID : Int
83
+ let targetID : Int ?
84
84
let message : String
85
85
}
86
86
@@ -211,8 +211,8 @@ extension XCBuildMessage.DidUpdateProgressInfo: Decodable, Equatable {
211
211
public init ( from decoder: Decoder ) throws {
212
212
let container = try decoder. container ( keyedBy: CodingKeys . self)
213
213
message = try container. decode ( String . self, forKey: . message)
214
- percentComplete = try Double ( container. decode ( String . self , forKey: . percentComplete) ) !
215
- showInLog = try Bool ( container. decode ( String . self , forKey: . showInLog) ) !
214
+ percentComplete = try container. decodeDoubleOrString ( forKey: . percentComplete)
215
+ showInLog = try container. decodeBoolOrString ( forKey: . showInLog)
216
216
}
217
217
}
218
218
@@ -227,7 +227,7 @@ extension XCBuildMessage.TargetStartedInfo: Decodable, Equatable {
227
227
228
228
public init ( from decoder: Decoder ) throws {
229
229
let container = try decoder. container ( keyedBy: CodingKeys . self)
230
- targetID = try Int ( container. decode ( String . self , forKey: . targetID) ) !
230
+ targetID = try container. decodeIntOrString ( forKey: . targetID)
231
231
targetGUID = try container. decode ( PIF . GUID. self, forKey: . targetGUID)
232
232
targetName = try container. decode ( String . self, forKey: . targetName)
233
233
type = try container. decode ( Kind . self, forKey: . type)
@@ -241,31 +241,30 @@ extension XCBuildMessage.TargetCompleteInfo: Decodable, Equatable {
241
241
242
242
public init ( from decoder: Decoder ) throws {
243
243
let container = try decoder. container ( keyedBy: CodingKeys . self)
244
- targetID = try Int ( container. decode ( String . self , forKey: . targetID) ) !
244
+ targetID = try container. decodeIntOrString ( forKey: . targetID)
245
245
}
246
246
}
247
247
248
248
extension XCBuildMessage . TaskUpToDateInfo : Decodable , Equatable {
249
249
enum CodingKeys : String , CodingKey {
250
250
case targetID
251
- case targetSignature = " signature "
251
+ case taskSignature = " signature "
252
252
case parentTaskID = " parentID "
253
253
}
254
254
255
255
public init ( from decoder: Decoder ) throws {
256
256
let container = try decoder. container ( keyedBy: CodingKeys . self)
257
- targetID = try Int ( container. decode ( String . self, forKey: . targetID) ) !
258
- targetSignature = try container. decode ( String . self, forKey: . targetSignature)
259
- let parentTaskIDString = try container. decode ( String . self, forKey: . parentTaskID)
260
- parentTaskID = !parentTaskIDString. isEmpty ? Int ( parentTaskIDString) ! : nil
257
+ targetID = try container. decodeIntOrStringIfPresent ( forKey: . targetID)
258
+ taskSignature = try container. decode ( String . self, forKey: . taskSignature)
259
+ parentTaskID = try container. decodeIntOrStringIfPresent ( forKey: . parentTaskID)
261
260
}
262
261
}
263
262
264
263
extension XCBuildMessage . TaskStartedInfo : Decodable , Equatable {
265
264
enum CodingKeys : String , CodingKey {
266
265
case taskID = " id "
267
266
case targetID
268
- case targetSignature = " signature "
267
+ case taskSignature = " signature "
269
268
case parentTaskID = " parentID "
270
269
case ruleInfo
271
270
case interestingPath
@@ -275,14 +274,12 @@ extension XCBuildMessage.TaskStartedInfo: Decodable, Equatable {
275
274
276
275
public init ( from decoder: Decoder ) throws {
277
276
let container = try decoder. container ( keyedBy: CodingKeys . self)
278
- taskID = try Int ( container. decode ( String . self, forKey: . taskID) ) !
279
- targetID = try Int ( container. decode ( String . self, forKey: . targetID) ) !
280
- targetSignature = try container. decode ( String . self, forKey: . targetSignature)
281
- let parentTaskIDString = try container. decode ( String . self, forKey: . parentTaskID)
282
- parentTaskID = !parentTaskIDString. isEmpty ? Int ( parentTaskIDString) ! : nil
277
+ taskID = try container. decodeIntOrString ( forKey: . taskID)
278
+ targetID = try container. decodeIntOrStringIfPresent ( forKey: . targetID)
279
+ taskSignature = try container. decode ( String . self, forKey: . taskSignature)
280
+ parentTaskID = try container. decodeIntOrStringIfPresent ( forKey: . parentTaskID)
283
281
ruleInfo = try container. decode ( String . self, forKey: . ruleInfo)
284
- let interestingPathString = try container. decode ( String . self, forKey: . interestingPath)
285
- interestingPath = !interestingPathString. isEmpty ? AbsolutePath ( interestingPathString) : nil
282
+ interestingPath = try container. decodeIfPresent ( AbsolutePath . self, forKey: . interestingPath)
286
283
commandLineDisplayString = try container. decode ( String . self, forKey: . commandLineDisplayString)
287
284
executionDescription = try container. decode ( String . self, forKey: . executionDescription)
288
285
}
@@ -296,7 +293,7 @@ extension XCBuildMessage.TaskOutputInfo: Decodable, Equatable {
296
293
297
294
public init ( from decoder: Decoder ) throws {
298
295
let container = try decoder. container ( keyedBy: CodingKeys . self)
299
- taskID = try Int ( container. decode ( String . self , forKey: . taskID) ) !
296
+ taskID = try container. decodeIntOrString ( forKey: . taskID)
300
297
data = try container. decode ( String . self, forKey: . data)
301
298
}
302
299
}
@@ -311,7 +308,7 @@ extension XCBuildMessage.TaskCompleteInfo: Decodable, Equatable {
311
308
312
309
public init ( from decoder: Decoder ) throws {
313
310
let container = try decoder. container ( keyedBy: CodingKeys . self)
314
- taskID = try Int ( container. decode ( String . self , forKey: . taskID) ) !
311
+ taskID = try container. decodeIntOrString ( forKey: . taskID)
315
312
result = try container. decode ( Result . self, forKey: . result)
316
313
signalled = try container. decode ( Bool . self, forKey: . signalled)
317
314
}
@@ -361,3 +358,55 @@ extension XCBuildMessage: Decodable, Equatable {
361
358
}
362
359
}
363
360
}
361
+
362
+ fileprivate extension KeyedDecodingContainer {
363
+ func decodeBoolOrString( forKey key: Key ) throws -> Bool {
364
+ do {
365
+ return try decode ( Bool . self, forKey: key)
366
+ } catch {
367
+ let string = try decode ( String . self, forKey: key)
368
+ guard let value = Bool ( string) else {
369
+ throw DecodingError . dataCorruptedError ( forKey: key, in: self , debugDescription: " Could not parse ' \( string) ' as Bool for key \( key) " )
370
+ }
371
+ return value
372
+ }
373
+ }
374
+
375
+ func decodeDoubleOrString( forKey key: Key ) throws -> Double {
376
+ do {
377
+ return try decode ( Double . self, forKey: key)
378
+ } catch {
379
+ let string = try decode ( String . self, forKey: key)
380
+ guard let value = Double ( string) else {
381
+ throw DecodingError . dataCorruptedError ( forKey: key, in: self , debugDescription: " Could not parse ' \( string) ' as Double for key \( key) " )
382
+ }
383
+ return value
384
+ }
385
+ }
386
+
387
+ func decodeIntOrString( forKey key: Key ) throws -> Int {
388
+ do {
389
+ return try decode ( Int . self, forKey: key)
390
+ } catch {
391
+ let string = try decode ( String . self, forKey: key)
392
+ guard let value = Int ( string) else {
393
+ throw DecodingError . dataCorruptedError ( forKey: key, in: self , debugDescription: " Could not parse ' \( string) ' as Int for key \( key) " )
394
+ }
395
+ return value
396
+ }
397
+ }
398
+
399
+ func decodeIntOrStringIfPresent( forKey key: Key ) throws -> Int ? {
400
+ do {
401
+ return try decodeIfPresent ( Int . self, forKey: key)
402
+ } catch {
403
+ guard let string = try decodeIfPresent ( String . self, forKey: key) , !string. isEmpty else {
404
+ return nil
405
+ }
406
+ guard let value = Int ( string) else {
407
+ throw DecodingError . dataCorruptedError ( forKey: key, in: self , debugDescription: " Could not parse ' \( string) ' as Int for key \( key) " )
408
+ }
409
+ return value
410
+ }
411
+ }
412
+ }
0 commit comments