-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathSWBServiceConsoleBuildCommandProtocol.swift
More file actions
1324 lines (1163 loc) · 48.8 KB
/
Copy pathSWBServiceConsoleBuildCommandProtocol.swift
File metadata and controls
1324 lines (1163 loc) · 48.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// NOTE: keep this in sync with Sources/XCBuildSupport/SwiftBuildMessage.swift in SwiftPM
public import Foundation
public import SWBProjectModel
import SWBUtil
public typealias BacktraceFrameInfo = SWBBuildOperationBacktraceFrame
/// Represents a message output by Swift Build.
public enum SwiftBuildMessage {
/// Event indicating that the service is about to start a planning operation.
public struct PlanningOperationStartedInfo {
public let planningOperationID: String
@_spi(Testing)
public init(planningOperationID: String) {
self.planningOperationID = planningOperationID
}
}
/// Event indicating that the service finished running a planning operation.
public struct PlanningOperationCompletedInfo {
public let planningOperationID: String
@_spi(Testing)
public init(planningOperationID: String) {
self.planningOperationID = planningOperationID
}
}
public struct ReportBuildDescriptionInfo {
public let buildDescriptionID: String
@_spi(Testing)
public init(buildDescriptionID: String) {
self.buildDescriptionID = buildDescriptionID
}
}
public struct ReportPathMapInfo {
public let copiedPathMap: [AbsolutePath: AbsolutePath]
public let generatedFilesPathMap: [AbsolutePath: AbsolutePath]
@_spi(Testing)
public init(
copiedPathMap: [AbsolutePath: AbsolutePath],
generatedFilesPathMap: [AbsolutePath: AbsolutePath]
) {
self.copiedPathMap = copiedPathMap
self.generatedFilesPathMap = generatedFilesPathMap
}
}
/// Wrapper for information provided about a 'prepare-for-index' operation.
public struct PreparedForIndexInfo {
public struct ResultInfo {
/// The timestamp of the 'prepare-for-index' marker node.
public let timestamp: Date
@_spi(Testing)
public init(timestamp: Date) {
self.timestamp = timestamp
}
}
public let targetGUID: String
public let resultInfo: ResultInfo
@_spi(Testing)
public init(
targetGUID: String,
resultInfo: ResultInfo
) {
self.targetGUID = targetGUID
self.resultInfo = resultInfo
}
}
public enum LocationContext {
case task(taskID: Int, targetID: Int)
case target(targetID: Int)
case globalTask(taskID: Int)
case global
}
public struct LocationContext2 {
// Consider replacing with a target signature in the future.
public let targetID: Int?
public let taskSignature: String?
@_spi(Testing)
public init(
targetID: Int? = nil,
taskSignature: String? = nil
) {
self.targetID = targetID
self.taskSignature = taskSignature
}
}
/// Wrapper for information provided about a diagnostic during the build.
public struct DiagnosticInfo {
public enum Kind: String {
case note
case warning
case error
case remark
}
public let kind: Kind
public enum Location {
public enum FileLocation {
/// Represents an absolute line/column location within a file.
/// - parameter line: The line number associated with the diagnostic, if known.
/// - parameter column: The column number associated with the diagnostic, if known.
case textual(line: Int, column: Int?)
/// Represents a file path diagnostic location with a semantic object identifier.
/// - parameter path: The file path associated with the diagnostic.
/// - parameter identifier: An opaque string identifying the object.
case object(identifier: String)
}
/// Represents an unknown diagnostic location.
case unknown
/// Represents a file diagnostic location.
/// - parameter path: The file path associated with the diagnostic.
/// - parameter fileLocation: The logical location within the file.
case path(_ path: String, fileLocation: FileLocation?)
/// Represents a build settings diagnostic location.
/// - parameter names: The names of the build settings associated with the diagnostic.
case buildSettings(names: [String])
public struct BuildFileAndPhase {
public let buildFileGUID: String
public let buildPhaseGUID: String
@_spi(Testing)
public init(
buildFileGUID: String,
buildPhaseGUID: String
) {
self.buildFileGUID = buildFileGUID
self.buildPhaseGUID = buildPhaseGUID
}
}
/// Represents a build file diagnostic location, within a particular target and project.
case buildFiles(_ buildFiles: [BuildFileAndPhase], targetGUID: String)
}
public let location: Location
@available(*, deprecated, message: "Use locationContext2 instead")
public let locationContext: LocationContext
public let locationContext2: LocationContext2
public enum Component {
case `default`
case packageResolution
case targetIntegrity
case clangCompiler(categoryName: String)
case targetMissingUserApproval
}
public let component: Component
public let message: String
public let optionName: String?
public let appendToOutputStream: Bool
public let childDiagnostics: [DiagnosticInfo]
public struct SourceRange {
public let path: String
public let startLine: Int
public let startColumn: Int
public let endLine: Int
public let endColumn: Int
@_spi(Testing)
public init(
path: String,
startLine: Int,
startColumn: Int,
endLine: Int,
endColumn: Int
) {
self.path = path
self.startLine = startLine
self.startColumn = startColumn
self.endLine = endLine
self.endColumn = endColumn
}
}
public let sourceRanges: [SourceRange]
public struct FixIt {
/// The location of the fix. May be an empty location (start and end locations the same) for pure insert.
public let sourceRange: SourceRange
/// The new text to replace the range. May be an empty string for pure delete.
public let textToInsert: String
@_spi(Testing)
public init(
sourceRange: SourceRange,
textToInsert: String
) {
self.sourceRange = sourceRange
self.textToInsert = textToInsert
}
}
public let fixIts: [FixIt]
public class Attachment: Codable, Equatable, @unchecked Sendable {
static func attachment(from attachment: SWBUtil.Diagnostic.Attachment) -> Attachment {
if let attachment = attachment as? SWBUtil.DiagnosticAttachments.ModuleErrorAttachment {
return ModuleErrorAttachment(pathsToDelete: attachment.pathsToDelete)
}
fatalError("Unrecognized attachment class: \(type(of:attachment))")
}
public static func == (lhs: borrowing SwiftBuildMessage.DiagnosticInfo.Attachment, rhs: borrowing SwiftBuildMessage.DiagnosticInfo.Attachment) -> Bool {
fatalError("This property is a subclass responsibility.")
}
}
public final class ModuleErrorAttachment: Attachment, @unchecked Sendable {
public let pathsToDelete: [String]
init(pathsToDelete: [String]) {
self.pathsToDelete = pathsToDelete
super.init()
}
private enum CodingKeys: String, CodingKey {
case pathsToDelete
}
required init(from decoder: any Swift.Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.pathsToDelete = try container.decode([String].self, forKey: .pathsToDelete)
try super.init(from: decoder)
}
}
public let traits: Set<String>
public let attachments: [String: Attachment]
@_spi(Testing)
public init(
kind: Kind,
location: Location,
locationContext: LocationContext,
locationContext2: LocationContext2,
component: Component,
message: String,
optionName: String? = nil,
appendToOutputStream: Bool,
childDiagnostics: [DiagnosticInfo] = [],
sourceRanges: [SourceRange] = [],
fixIts: [FixIt] = [],
traits: [String] = [],
attachments: [String: Attachment] = [:]
) {
self.kind = kind
self.location = location
self.locationContext = locationContext
self.locationContext2 = locationContext2
self.component = component
self.message = message
self.optionName = optionName
self.appendToOutputStream = appendToOutputStream
self.childDiagnostics = childDiagnostics
self.sourceRanges = sourceRanges
self.fixIts = fixIts
self.traits = Set(traits)
self.attachments = attachments
}
}
public struct OutputInfo {
public let data: Data
@available(*, deprecated, message: "Use locationContext2 instead")
public let locationContext: LocationContext
public let locationContext2: LocationContext2
@_spi(Testing)
public init(
data: Data,
locationContext: LocationContext,
locationContext2: LocationContext2
) {
self.data = data
self.locationContext = locationContext
self.locationContext2 = locationContext2
}
}
public struct BuildStartedInfo {
public let baseDirectory: AbsolutePath
public let derivedDataPath: AbsolutePath?
@_spi(Testing)
public init(
baseDirectory: AbsolutePath,
derivedDataPath: AbsolutePath? = nil
) {
self.baseDirectory = baseDirectory
self.derivedDataPath = derivedDataPath
}
}
public struct BuildDiagnosticInfo {
public let message: String
@_spi(Testing)
public init(message: String) {
self.message = message
}
}
public struct BuildOperationMetrics {
public let counters: [String: Int]
/// The key is the first component of task rule info, a.k.a. the rule info type
public let taskCounters: [String: [String: Int]]
@_spi(Testing)
public init(
counters: [String: Int],
taskCounters: [String: [String: Int]]
) {
self.counters = counters
self.taskCounters = taskCounters
}
}
public struct BuildCompletedInfo {
public enum Result: String {
case ok
case failed
case cancelled
case aborted
}
public let result: Result
public let metrics: BuildOperationMetrics?
@_spi(Testing)
public init(
result: Result,
metrics: BuildOperationMetrics? = nil
) {
self.result = result
self.metrics = metrics
}
}
public struct BuildOutputInfo {
public let data: String
@_spi(Testing)
public init(data: String) {
self.data = data
}
}
/// Event indicating that the "build preparation" phase is complete.
public struct PreparationCompleteInfo {
@_spi(Testing)
public init() {
}
}
/// Event indicating a high-level status message and percentage completion across the entire build operation, suitable for display in a user interface.
public struct DidUpdateProgressInfo {
public let message: String
public let percentComplete: Double
public let showInLog: Bool
public let targetName: String?
public let numCommands: Int?
public let numCommandsExpected: Int?
public let condensedStatusMessage: String?
@_spi(Testing)
public init(
message: String,
percentComplete: Double,
showInLog: Bool,
targetName: String? = nil,
numCommands: Int? = nil,
numCommandsExpected: Int? = nil,
condensedStatusMessage: String? = nil
) {
self.message = message
self.percentComplete = percentComplete
self.showInLog = showInLog
self.targetName = targetName
self.numCommands = numCommands
self.numCommandsExpected = numCommandsExpected
self.condensedStatusMessage = condensedStatusMessage
}
}
/// Event indicating that a target was already up to date and did not need to be built.
public struct TargetUpToDateInfo {
public let guid: PIF.GUID
@_spi(Testing)
public init(guid: PIF.GUID) {
self.guid = guid
}
}
/// Event indicating that a target has started building.
public struct TargetStartedInfo {
public enum Kind: String {
case native = "Native"
case aggregate = "Aggregate"
case external = "External"
case packageProduct = "Package Product"
}
/// An opaque ID to identify the target in subsequent events.
public let targetID: Int
/// The GUID of the target being started.
public let targetGUID: PIF.GUID
/// The name of the target.
public let targetName: String
/// The type of the target being built.
public let type: Kind
/// The name of the project containing the target.
public let projectName: String
/// The path of the project wrapper (for example, `.xcodeproj`) containing the target.
public let projectPath: AbsolutePath
/// Whether this project represents a Swift package.
public let projectIsPackage: Bool
/// Whether the project's name is unique across the whole workspace.
///
/// This can be used to determine whether diagnostic messages should attempt to additionally disambiguate the project name by path.
public let projectNameIsUniqueInWorkspace: Bool
/// The name of the configuration chosen to build.
public let configurationName: String
/// Whether or not the configuration was the default one.
public let configurationIsDefault: Bool
/// The canonical name of the SDK in use, if any.
public let sdkroot: String?
@_spi(Testing)
public init(
targetID: Int,
targetGUID: PIF.GUID,
targetName: String,
type: Kind,
projectName: String,
projectPath: AbsolutePath,
projectIsPackage: Bool,
projectNameIsUniqueInWorkspace: Bool,
configurationName: String,
configurationIsDefault: Bool,
sdkroot: String? = nil
) {
self.targetID = targetID
self.targetGUID = targetGUID
self.targetName = targetName
self.type = type
self.projectName = projectName
self.projectPath = projectPath
self.projectIsPackage = projectIsPackage
self.projectNameIsUniqueInWorkspace = projectNameIsUniqueInWorkspace
self.configurationName = configurationName
self.configurationIsDefault = configurationIsDefault
self.sdkroot = sdkroot
}
}
public struct TargetOutputInfo {
public let targetID: Int
public let data: String
@_spi(Testing)
public init(
targetID: Int,
data: String
) {
self.targetID = targetID
self.data = data
}
}
/// Event indicating that a target has finished building.
public struct TargetCompleteInfo {
public let targetID: Int
@_spi(Testing)
public init(targetID: Int) {
self.targetID = targetID
}
}
/// Event indicating that a task was already up to date and did not need to be built.
///
/// This method is *only* called for targets which have some tasks run; targets which are entirely up-to-date will merely receive a ``TargetUpToDateInfo`` event.
///
/// Otherwise, this message will be received in the order in which the task would have been run in some valid ordering of a target's tasks.
public struct TaskUpToDateInfo {
public let targetID: Int?
public let taskSignature: String
public let parentTaskID: Int?
@_spi(Testing)
public init(
targetID: Int? = nil,
taskSignature: String,
parentTaskID: Int? = nil
) {
self.targetID = targetID
self.taskSignature = taskSignature
self.parentTaskID = parentTaskID
}
}
/// Event indicating that a task has started building.
///
/// This task may be a top-level task within a target, or it may be a subtask of an existing task (if a parent ID is provided), or it may be a global task that is not associated with any target at all.
public struct TaskStartedInfo {
/// An opaque ID to identify the task in subsequent events.
public let taskID: Int
/// An opaque ID indicating the target that the task is operating on behalf of, if any.
public let targetID: Int?
/// A unique signature to represent this task within its target.
///
/// This signature is only valid for comparing with a ``TaskUpToDateInfo`` message across build operations, and should not be inspected.
public let taskSignature: String
/// An opaque ID identifying the parent task, if any.
public let parentTaskID: Int?
/// The rule info of the task.
public let ruleInfo: String
/// Any interesting path related to the task, for e.g. the file being compiled.
public let interestingPath: AbsolutePath?
/// The string to display describing the command line, if any.
public let commandLineDisplayString: String?
/// The execution description.
public let executionDescription: String
/// The set of paths to clang-format serialized diagnostics files, if used.
public let serializedDiagnosticsPaths: [AbsolutePath]
@_spi(Testing)
public init(
taskID: Int,
targetID: Int? = nil,
taskSignature: String,
parentTaskID: Int? = nil,
ruleInfo: String,
interestingPath: AbsolutePath? = nil,
commandLineDisplayString: String? = nil,
executionDescription: String,
serializedDiagnosticsPaths: [AbsolutePath] = []
) {
self.taskID = taskID
self.targetID = targetID
self.taskSignature = taskSignature
self.parentTaskID = parentTaskID
self.ruleInfo = ruleInfo
self.interestingPath = interestingPath
self.commandLineDisplayString = commandLineDisplayString
self.executionDescription = executionDescription
self.serializedDiagnosticsPaths = serializedDiagnosticsPaths
}
}
public struct TaskDiagnosticInfo {
public let taskID: Int
public let taskSignature: String
public let targetID: Int?
public let message: String
@_spi(Testing)
public init(
taskID: Int,
taskSignature: String,
targetID: Int? = nil,
message: String
) {
self.taskID = taskID
self.taskSignature = taskSignature
self.targetID = targetID
self.message = message
}
}
public struct TaskOutputInfo {
public let taskID: Int
public let data: String
@_spi(Testing)
public init(
taskID: Int,
data: String
) {
self.taskID = taskID
self.data = data
}
}
/// Event indicating that a task has finished building.
public struct TaskCompleteInfo {
public enum Result: String {
case success
case failed
case cancelled
}
public struct Metrics {
public let utime: UInt64
public let stime: UInt64
public let maxRSS: UInt64
public let wcStartTime: UInt64
public let wcDuration: UInt64
@_spi(Testing)
public init(
utime: UInt64,
stime: UInt64,
maxRSS: UInt64,
wcStartTime: UInt64,
wcDuration: UInt64
) {
self.utime = utime
self.stime = stime
self.maxRSS = maxRSS
self.wcStartTime = wcStartTime
self.wcDuration = wcDuration
}
}
public let taskID: Int
public let taskSignature: String
public let result: Result
public let signalled: Bool
public let metrics: Metrics?
@_spi(Testing)
public init(
taskID: Int,
taskSignature: String,
result: Result,
signalled: Bool,
metrics: Metrics? = nil
) {
self.taskID = taskID
self.taskSignature = taskSignature
self.result = result
self.signalled = signalled
self.metrics = metrics
}
}
public struct TargetDiagnosticInfo {
public let targetID: Int
public let message: String
@_spi(Testing)
public init(
targetID: Int,
message: String
) {
self.targetID = targetID
self.message = message
}
}
case planningOperationStarted(PlanningOperationStartedInfo)
case planningOperationCompleted(PlanningOperationCompletedInfo)
case reportBuildDescription(ReportBuildDescriptionInfo)
case reportPathMap(ReportPathMapInfo)
case preparedForIndex(PreparedForIndexInfo)
case backtraceFrame(BacktraceFrameInfo)
case buildStarted(BuildStartedInfo)
case buildDiagnostic(BuildDiagnosticInfo)
case buildCompleted(BuildCompletedInfo)
case buildOutput(BuildOutputInfo)
case preparationComplete(PreparationCompleteInfo)
case didUpdateProgress(DidUpdateProgressInfo)
case targetUpToDate(TargetUpToDateInfo)
case targetStarted(TargetStartedInfo)
case targetOutput(TargetOutputInfo)
case targetComplete(TargetCompleteInfo)
case taskUpToDate(TaskUpToDateInfo)
case taskStarted(TaskStartedInfo)
case taskDiagnostic(TaskDiagnosticInfo)
case taskOutput(TaskOutputInfo)
case taskComplete(TaskCompleteInfo)
case targetDiagnostic(TargetDiagnosticInfo)
case diagnostic(DiagnosticInfo)
case output(OutputInfo)
}
extension SwiftBuildMessage.DiagnosticInfo.Kind: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.DiagnosticInfo.Location.BuildFileAndPhase: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.DiagnosticInfo.Location.FileLocation: Equatable, Sendable {}
extension SwiftBuildMessage.DiagnosticInfo.Location: Codable, Equatable, Sendable {
private enum CodingKeys: String, CodingKey {
case locationType
case path
case line
case column
case identifier
case names
case buildFiles
case targetGUID
}
private enum LocationType: String, Codable {
case unknown
case path
case buildSettings
case buildFiles
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
switch try container.decode(LocationType.self, forKey: .locationType) {
case .unknown:
self = .unknown
case .path:
let path = try container.decode(String.self, forKey: .path)
let line = try container.decodeIfPresent(Int.self, forKey: .line)
let column = try container.decodeIfPresent(Int.self, forKey: .column)
let identifier = try container.decodeIfPresent(String.self, forKey: .identifier)
switch (identifier, line, column) {
case (let identifier?, nil, nil):
self = .path(path, fileLocation: .object(identifier: identifier))
case (nil, let line?, let column):
self = .path(path, fileLocation: .textual(line: line, column: column))
case (nil, nil, nil):
self = .path(path, fileLocation: nil)
default:
throw DecodingError.dataCorruptedError(forKey: .path, in: container, debugDescription: "invalid path location properties")
}
case .buildSettings:
let names = try container.decode([String].self, forKey: .names)
self = .buildSettings(names: names)
case .buildFiles:
let buildFiles = try container.decode([BuildFileAndPhase].self, forKey: .buildFiles)
let targetGUID = try container.decode(String.self, forKey: .targetGUID)
self = .buildFiles(buildFiles, targetGUID: targetGUID)
}
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .unknown:
try container.encode(LocationType.unknown, forKey: .locationType)
case let .path(path, fileLocation):
try container.encode(LocationType.path, forKey: .locationType)
try container.encode(path, forKey: .path)
switch fileLocation {
case let .textual(line, column):
try container.encode(line, forKey: .line)
try container.encodeIfPresent(column, forKey: .column)
case let .object(identifier):
try container.encode(identifier, forKey: .identifier)
case .none:
break
}
case let .buildSettings(names):
try container.encode(LocationType.buildSettings, forKey: .locationType)
try container.encode(names, forKey: .names)
case let .buildFiles(buildFiles, targetGUID):
try container.encode(LocationType.buildFiles, forKey: .locationType)
try container.encode(buildFiles, forKey: .buildFiles)
try container.encode(targetGUID, forKey: .targetGUID)
}
}
}
extension SwiftBuildMessage.LocationContext: Codable, Equatable, Sendable {
private enum CodingKeys: String, CodingKey {
case locationType
case taskID
case targetID
}
private enum LocationType: String, Codable {
case task
case target
case globalTask
case global
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
switch try container.decode(LocationType.self, forKey: .locationType) {
case .task:
self = try .task(
taskID: container.decode(Int.self, forKey: .taskID),
targetID: container.decode(Int.self, forKey: .targetID))
case .target:
self = try .target(targetID: container.decode(Int.self, forKey: .targetID))
case .globalTask:
self = try .globalTask(taskID: container.decode(Int.self, forKey: .taskID))
case .global:
self = .global
}
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case let .task(taskID, targetID):
try container.encode(LocationType.task, forKey: .locationType)
try container.encode(taskID, forKey: .taskID)
try container.encode(targetID, forKey: .targetID)
case let .target(targetID):
try container.encode(LocationType.target, forKey: .locationType)
try container.encode(targetID, forKey: .targetID)
case let .globalTask(taskID):
try container.encode(LocationType.globalTask, forKey: .locationType)
try container.encode(taskID, forKey: .taskID)
case .global:
try container.encode(LocationType.global, forKey: .locationType)
}
}
}
extension SwiftBuildMessage.LocationContext2: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.DiagnosticInfo.Component: Codable, Equatable, Sendable {
private enum CodingKeys: String, CodingKey {
case componentType
case categoryName
}
private enum ComponentType: String, Codable {
case `default`
case packageResolution
case targetIntegrity
case clangCompiler
case targetMissingUserApproval
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
switch try container.decode(ComponentType.self, forKey: .componentType) {
case .`default`:
self = .`default`
case .packageResolution:
self = .packageResolution
case .targetIntegrity:
self = .targetIntegrity
case .clangCompiler:
self = try .clangCompiler(categoryName: container.decode(String.self, forKey: .categoryName))
case .targetMissingUserApproval:
self = .targetMissingUserApproval
}
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .`default`:
try container.encode(ComponentType.default, forKey: .componentType)
case .packageResolution:
try container.encode(ComponentType.packageResolution, forKey: .componentType)
case .targetIntegrity:
try container.encode(ComponentType.targetIntegrity, forKey: .componentType)
case let .clangCompiler(categoryName):
try container.encode(ComponentType.clangCompiler, forKey: .componentType)
try container.encode(categoryName, forKey: .categoryName)
case .targetMissingUserApproval:
try container.encode(ComponentType.targetMissingUserApproval, forKey: .componentType)
}
}
}
extension SwiftBuildMessage.DiagnosticInfo.SourceRange: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.DiagnosticInfo.FixIt: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.DiagnosticInfo: Codable, Equatable, Sendable {}
/// Convenience enum defining well-known diagnostic traits.
///
/// This matches the list in `BuildOperationMessages.swift`.
public enum SwiftBuildMessageDiagnosticTrait: String, Sendable {
case moduleError = "compiler.module-error"
}
extension SwiftBuildMessage.OutputInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.BuildStartedInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.BuildDiagnosticInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.BuildOperationMetrics: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.BuildCompletedInfo.Result: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.BuildCompletedInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.BuildOutputInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.TargetUpToDateInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.TaskDiagnosticInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.TargetDiagnosticInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.PreparationCompleteInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.DidUpdateProgressInfo: Codable, Equatable, Sendable {
enum CodingKeys: String, CodingKey {
case message
case percentComplete
case showInLog
case targetName
case numCommands
case numCommandsExpected
case condensedStatusMessage
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
message = try container.decode(String.self, forKey: .message)
percentComplete = try container.decodeDoubleOrString(forKey: .percentComplete)
showInLog = try container.decodeBoolOrString(forKey: .showInLog)
targetName = try container.decodeIfPresent(String.self, forKey: .targetName)
numCommands = try container.decodeIfPresent(Int.self, forKey: .numCommands)
numCommandsExpected = try container.decodeIfPresent(Int.self, forKey: .numCommandsExpected)
condensedStatusMessage = try container.decodeIfPresent(String.self, forKey: .condensedStatusMessage)
}
}
extension SwiftBuildMessage.TargetStartedInfo.Kind: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.TargetStartedInfo: Codable, Equatable, Sendable {
enum CodingKeys: String, CodingKey {
case targetID = "id"
case targetGUID = "guid"
case targetName = "name"
case type
case projectName
case projectPath
case projectIsPackage
case projectNameIsUniqueInWorkspace
case configurationName
case configurationIsDefault
case sdkroot
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
targetID = try container.decodeIntOrString(forKey: .targetID)
targetGUID = try container.decode(PIF.GUID.self, forKey: .targetGUID)
targetName = try container.decode(String.self, forKey: .targetName)
type = try container.decode(Kind.self, forKey: .type)
projectName = try container.decode(String.self, forKey: .projectName)
projectPath = try container.decode(AbsolutePath.self, forKey: .projectPath)
projectIsPackage = try container.decode(Bool.self, forKey: .projectIsPackage)
projectNameIsUniqueInWorkspace = try container.decode(Bool.self, forKey: .projectNameIsUniqueInWorkspace)
configurationName = try container.decode(String.self, forKey: .configurationName)
configurationIsDefault = try container.decode(Bool.self, forKey: .configurationIsDefault)
sdkroot = try container.decodeIfPresent(String.self, forKey: .sdkroot)
}
}
extension SwiftBuildMessage.TargetOutputInfo: Codable, Equatable, Sendable {}
extension SwiftBuildMessage.TargetCompleteInfo: Codable, Equatable, Sendable {