File: ProjectDescriptorTypes.swift

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (637 lines) | stat: -rw-r--r-- 22,565 bytes parent folder | download
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
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

public import SWBUtil
import Foundation

public struct SchemeInput: Equatable, Hashable, Serializable, Sendable {
    public let name: String
    public let isShared: Bool
    public let isAutogenerated: Bool

    public let analyze: ActionInput
    public let archive: ActionInput
    public let profile: ActionInput
    public let run: ActionInput
    public let test: ActionInput

    public init(name: String, isShared: Bool, isAutogenerated: Bool, analyze: ActionInput, archive: ActionInput, profile: ActionInput, run: ActionInput, test: ActionInput) {
        self.name = name
        self.isShared = isShared
        self.isAutogenerated = isAutogenerated
        self.analyze = analyze
        self.archive = archive
        self.profile = profile
        self.run = run
        self.test = test
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(8)
        self.name = try deserializer.deserialize()
        self.isShared = try deserializer.deserialize()
        self.isAutogenerated = try deserializer.deserialize()
        self.analyze = try deserializer.deserialize()
        self.archive = try deserializer.deserialize()
        self.profile = try deserializer.deserialize()
        self.run = try deserializer.deserialize()
        self.test = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(8)
        serializer.serialize(self.name)
        serializer.serialize(self.isShared)
        serializer.serialize(self.isAutogenerated)
        serializer.serialize(self.analyze)
        serializer.serialize(self.archive)
        serializer.serialize(self.profile)
        serializer.serialize(self.run)
        serializer.serialize(self.test)
    }
}

public struct ActionInput: Equatable, Hashable, Serializable, Sendable {
    public let configurationName: String
    public let targetIdentifiers: [String]

    public init(configurationName: String, targetIdentifiers: [String]) {
        self.configurationName = configurationName
        self.targetIdentifiers = targetIdentifiers
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(2)
        self.configurationName = try deserializer.deserialize()
        self.targetIdentifiers = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(2)
        serializer.serialize(self.configurationName)
        serializer.serialize(self.targetIdentifiers)
    }
}

/// Description of a scheme.
/// Scheme represents "what" (products) and "how" (configuration) of building.
public struct SchemeDescription: Codable, Equatable, Hashable, Serializable, Sendable {
    /// Human-readable name, show to users.
    public let name: String

    /// Disambiguated name. If the workspace closure contains more than one scheme of the same name,
    /// this will also contain the name of the container.
    /// Pass this to xcodebuild to ensure we always choose the right scheme.
    public let disambiguatedName: String

    /// Needed to know whether a job will see it when it checks out on the server.
    /// If not shared, client should offer to share+commit the scheme if user wants to use it for CI.
    public let isShared: Bool

    /// If the scheme is not actually present on disk, but is automatically
    /// generated by Xcode.
    public let isAutogenerated: Bool

    /// Actions with their metadata.
    public let actions: ActionsInfo

    public init(name: String, disambiguatedName: String, isShared: Bool, isAutogenerated: Bool, actions: ActionsInfo) {
        self.name = name
        self.disambiguatedName = disambiguatedName
        self.isShared = isShared
        self.isAutogenerated = isAutogenerated
        self.actions = actions
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(5)
        self.name = try deserializer.deserialize()
        self.disambiguatedName = try deserializer.deserialize()
        self.isShared = try deserializer.deserialize()
        self.isAutogenerated = try deserializer.deserialize()
        self.actions = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(5)
        serializer.serialize(self.name)
        serializer.serialize(self.disambiguatedName)
        serializer.serialize(self.isShared)
        serializer.serialize(self.isAutogenerated)
        serializer.serialize(self.actions)
    }
}

/// Describes a destination

/// Describes a reference to a Product, used in describeSchemes.
public struct ProductInfo: Codable, Equatable, Hashable, Serializable, Sendable {

    /// Human-readable name.
    public let displayName: String

    /// Identifier, used to reference the product in `describeProducts`.
    public let identifier: String

    /// Supported destinations.
    /// We need this here so that we can pass the right platform/destination into the second call.
    public let supportedDestinations: [DestinationInfo]

    public init(displayName: String, identifier: String, supportedDestinations: [DestinationInfo]) {
        self.displayName = displayName
        self.identifier = identifier
        self.supportedDestinations = supportedDestinations
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(3)
        self.displayName = try deserializer.deserialize()
        self.identifier = try deserializer.deserialize()
        self.supportedDestinations = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(3)
        serializer.serialize(self.displayName)
        serializer.serialize(self.identifier)
        serializer.serialize(self.supportedDestinations)
    }
}

/// Describes a reference to a Test Plan, used in describeSchemes
public struct TestPlanInfo: Codable, Equatable, Hashable, Serializable, Sendable {

    /// Human-readable name
    public let displayName: String

    public init(displayName: String) {
        self.displayName = displayName
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(1)
        self.displayName = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(1)
        serializer.serialize(self.displayName)
    }
}

/// Describes a destination.
public struct DestinationInfo: Codable, Equatable, Hashable, Comparable, Serializable, Sendable {

    /// Platform name
    public let platformName: String

    /// Whether destination represents a simulator.
    public let isSimulator: Bool

    public init(platformName: String, isSimulator: Bool) {
        self.platformName = platformName
        self.isSimulator = isSimulator
    }

    public static func <(lhs: DestinationInfo, rhs: DestinationInfo) -> Bool {
        return lhs.platformName.localizedCompare(rhs.platformName) == .orderedAscending
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(2)
        self.platformName = try deserializer.deserialize()
        self.isSimulator = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(2)
        serializer.serialize(self.platformName)
        serializer.serialize(self.isSimulator)
    }
}

/// Describes an action.
public struct ActionInfo: Codable, Equatable, Hashable, Serializable, Sendable {

    /// Build configuration.
    public let configurationName: String

    /// Products built for this action.
    public let products: [ProductInfo]

    /// Test plans associated with this action.
    public let testPlans: [TestPlanInfo]?

    public init(configurationName: String, products: [ProductInfo], testPlans: [TestPlanInfo]?) {
        self.configurationName = configurationName
        self.products = products
        self.testPlans = testPlans
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(3)
        self.configurationName = try deserializer.deserialize()
        self.products = try deserializer.deserialize()
        self.testPlans = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(3)
        serializer.serialize(self.configurationName)
        serializer.serialize(self.products)
        serializer.serialize(self.testPlans)
    }
}

/// Describes actions associated with the scheme.
public struct ActionsInfo: Codable, Equatable, Hashable, Serializable, Sendable {
    public let analyze: ActionInfo
    public let archive: ActionInfo
    public let profile: ActionInfo
    public let run: ActionInfo
    public let test: ActionInfo

    public init(analyze: ActionInfo, archive: ActionInfo, profile: ActionInfo, run: ActionInfo, test: ActionInfo) {
        self.analyze = analyze
        self.archive = archive
        self.profile = profile
        self.run = run
        self.test = test
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(5)
        self.analyze = try deserializer.deserialize()
        self.archive = try deserializer.deserialize()
        self.profile = try deserializer.deserialize()
        self.run = try deserializer.deserialize()
        self.test = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(5)
        serializer.serialize(self.analyze)
        serializer.serialize(self.archive)
        serializer.serialize(self.profile)
        serializer.serialize(self.run)
        serializer.serialize(self.test)
    }
}

/// ProductDescription represents an interesting build asset that the user can run or link.
/// Used in describeProducts.
public struct ProductDescription: Equatable, Hashable, Serializable, Sendable {

    /// Human-readable name of the product's Xcode target.
    public let displayName: String

    /// Product name, e.g. name of the app on the home screen, aka CFBundleName.
    public let productName: String

    /// Internal identifier in the project model.
    public let identifier: String

    public enum ProductType: Codable, Equatable, Hashable, Sendable {

        /// Aggregate target - not a product, but has products as dependencies.
        case none

        /// Application.
        case app

        /// Command line tool.
        case tool

        /// Library (framework or a static library).
        case library

        /// App extension.
        case appex

        /// Test bundle.
        case tests

        /// Unknown.
        case unknown(String)

        public init(from decoder: any Decoder) throws {
            let value = try decoder.singleValueContainer().decode(String.self)
            self = Self.fromString(value)
        }

        public func encode(to encoder: any Encoder) throws {
            let value = self.asString()
            var container = encoder.singleValueContainer()
            try container.encode(value)
        }

        public func asString() -> String {
            let value: String
            switch self {
            case .none:
                value = "none"
            case .app:
                value = "app"
            case .tool:
                value = "tool"
            case .library:
                value = "library"
            case .appex:
                value = "appex"
            case .tests:
                value = "tests"
            case .unknown(let raw):
                value = raw
            }
            return value
        }

        static func fromString(_ value: String) -> ProductType {
            switch value {
            case "none":
                return .none
            case "app":
                return .app
            case "tool":
                return .tool
            case "library":
                return .library
            case "appex":
                return .appex
            case "tests":
                return .tests
            default:
                return .unknown(value)
            }
        }
    }

    /// Product type. App/Library?
    public let productType: ProductType

    /// Dependent products (watch apps, app extensions)
    public let dependencies: [ProductDescription]?

    /// Bundle ID, aka CFBundleIdentifier.
    /// CLI tools might not have one.
    public let bundleIdentifier: String?

    public enum DeviceFamily: Codable, Equatable, Hashable, Sendable {
        case iPhone
        case iPad
        case appleTV
        case appleWatch
        case unknown(String)

        public init(from decoder: any Decoder) throws {
            let value = try decoder.singleValueContainer().decode(String.self)
            self = Self.fromString(value)
        }

        public func encode(to encoder: any Encoder) throws {
            let value = self.asString()
            var container = encoder.singleValueContainer()
            try container.encode(value)
        }

        public func asString() -> String {
            let value: String
            switch self {
            case .iPhone:
                value = "iPhone"
            case .iPad:
                value = "iPad"
            case .appleTV:
                value = "appleTV"
            case .appleWatch:
                value = "appleWatch"
            case .unknown(let raw):
                value = raw
            }
            return value
        }

        static func fromString(_ value: String) -> DeviceFamily {
            switch value {
            case "iPhone":
                return .iPhone
            case "iPad":
                return .iPad
            case "appleTV":
                return .appleTV
            case "appleWatch":
                return .appleWatch
            default:
                return .unknown(value)
            }
        }
    }

    /// iPhone/iPad/Apple TV
    public let targetedDeviceFamilies: [DeviceFamily]?

    /// Minimum OS version.
    public let deploymentTarget: Version

    /// Marketing version string, aka CFBundleShortVersionString.
    public let marketingVersion: String?

    /// Build version string, aka CFBundleVersion.
    /// CLI tools might not have one.
    public let buildVersion: String?

    /// Bitcode - no longer supported
    public let enableBitcode: Bool

    /// Codesigning
    public enum CodesignMode: Codable, Equatable, Hashable, Sendable {
        case automatic
        case manual
        case unknown(String)

        public init(from decoder: any Decoder) throws {
            let value = try decoder.singleValueContainer().decode(String.self)
            self = Self.fromString(value)
        }

        public func encode(to encoder: any Encoder) throws {
            let value = self.asString()
            var container = encoder.singleValueContainer()
            try container.encode(value)
        }

        public func asString() -> String {
            let value: String
            switch self {
            case .automatic:
                value = "automatic"
            case .manual:
                value = "manual"
            case .unknown(let raw):
                value = raw
            }
            return value
        }

        static func fromString(_ value: String) -> CodesignMode {
            switch value {
            case "automatic":
                return .automatic
            case "manual":
                return .manual
            default:
                return .unknown(value)
            }
        }
    }
    public let codesign: CodesignMode?

    /// Development team
    public let team: String?

    /// Path to the Info.plist file
    /// Used to set the CFBundleVersion by CI
    /// This is not great and we should instead add a way to set
    /// the build version explicitly. Once we do that, this property
    /// will be removed.
    /// CLI tools might not have one.
    public let infoPlistPath: String?

    /// Path to an icon file, largest available size.
    /// Relative to SRCROOT (parent of the .xcodeproj/.xcworkspace).
    public let iconPath: String?

    public init(
        displayName: String,
        productName: String,
        identifier: String,
        productType: ProductType,
        dependencies: [ProductDescription]?,
        bundleIdentifier: String?,
        targetedDeviceFamilies: [DeviceFamily]?,
        deploymentTarget: Version,
        marketingVersion: String?,
        buildVersion: String?,
        codesign: CodesignMode?,
        team: String?,
        infoPlistPath: String?,
        iconPath: String?
        ) {
        self.displayName = displayName
        self.productName = productName
        self.identifier = identifier
        self.productType = productType
        self.dependencies = dependencies
        self.bundleIdentifier = bundleIdentifier
        self.targetedDeviceFamilies = targetedDeviceFamilies
        self.deploymentTarget = deploymentTarget
        self.marketingVersion = marketingVersion
        self.buildVersion = buildVersion
        self.enableBitcode = false
        self.codesign = codesign
        self.team = team
        self.infoPlistPath = infoPlistPath
        self.iconPath = iconPath
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(14)
        self.displayName = try deserializer.deserialize()
        self.productName = try deserializer.deserialize()
        self.identifier = try deserializer.deserialize()
        self.productType = try ProductType.fromString(deserializer.deserialize())
        self.dependencies = try deserializer.deserialize()
        self.bundleIdentifier = try deserializer.deserialize()
        let targetedDeviceFamilies: [String]? = try deserializer.deserialize()
        self.targetedDeviceFamilies = targetedDeviceFamilies?.map { DeviceFamily.fromString($0) }
        let deploymentTarget: String = try deserializer.deserialize()
        self.deploymentTarget = try Version(deploymentTarget)
        self.marketingVersion = try deserializer.deserialize()
        self.buildVersion = try deserializer.deserialize()
        self.enableBitcode = false
        let codesign: String? = try deserializer.deserialize()
        self.codesign = codesign.map { CodesignMode.fromString($0) }
        self.team = try deserializer.deserialize()
        self.infoPlistPath = try deserializer.deserialize()
        self.iconPath = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(14)
        serializer.serialize(self.displayName)
        serializer.serialize(self.productName)
        serializer.serialize(self.identifier)
        serializer.serialize(self.productType.asString())
        serializer.serialize(self.dependencies)
        serializer.serialize(self.bundleIdentifier)
        serializer.serialize(self.targetedDeviceFamilies?.map { $0.asString() })
        serializer.serialize(self.deploymentTarget.description)
        serializer.serialize(self.marketingVersion)
        serializer.serialize(self.buildVersion)
        serializer.serialize(self.codesign?.asString())
        serializer.serialize(self.team)
        serializer.serialize(self.infoPlistPath)
        serializer.serialize(self.iconPath)
    }
}

/// Tuple of product name + type + bundle ID + destination name.
/// AllProductsInProjectDescription can be used to search for all of these in a given project.
public struct ProductTupleDescription: Equatable, Hashable, Codable, Serializable, Sendable {
    public let displayName: String
    public let productName: String
    public let productType: ProductDescription.ProductType
    public let identifier: String
    public let team: String?
    public let bundleIdentifier: String?
    public let destination: DestinationInfo
    public let containingSchemes: [String]
    public let iconPath: String?

    public init(displayName: String, productName: String, productType: ProductDescription.ProductType, identifier: String, team: String?, bundleIdentifier: String?, destination: DestinationInfo, containingSchemes: [String], iconPath: String?) {
        self.displayName = displayName
        self.productName = productName
        self.productType = productType
        self.identifier = identifier
        self.team = team
        self.bundleIdentifier = bundleIdentifier
        self.destination = destination
        self.containingSchemes = containingSchemes
        self.iconPath = iconPath
    }

    public init(from deserializer: any Deserializer) throws {
        try deserializer.beginAggregate(9)
        self.displayName = try deserializer.deserialize()
        self.productName = try deserializer.deserialize()
        self.productType = try ProductDescription.ProductType.fromString(deserializer.deserialize())
        self.identifier = try deserializer.deserialize()
        self.team = try deserializer.deserialize()
        self.bundleIdentifier = try deserializer.deserialize()
        self.containingSchemes = try deserializer.deserialize()
        self.iconPath = try deserializer.deserialize()
        self.destination = try deserializer.deserialize()
    }

    public func serialize<T: Serializer>(to serializer: T) {
        serializer.beginAggregate(9)
        serializer.serialize(self.displayName)
        serializer.serialize(self.productName)
        serializer.serialize(self.productType.asString())
        serializer.serialize(self.identifier)
        serializer.serialize(self.team)
        serializer.serialize(self.bundleIdentifier)
        serializer.serialize(self.containingSchemes)
        serializer.serialize(self.iconPath)
        serializer.serialize(self.destination)
    }
}