File: PackageDescriptionSerialization.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 (429 lines) | stat: -rw-r--r-- 13,959 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
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023 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
//
//===----------------------------------------------------------------------===//

#if USE_IMPL_ONLY_IMPORTS
@_implementationOnly import Foundation
#else
import Foundation
#endif

enum Serialization {
    // MARK: - build settings serialization

    struct BuildConfiguration: Codable {
        let config: String
    }

    struct BuildSettingCondition: Codable {
        let platforms: [Platform]?
        let config: BuildConfiguration?
        let traits: Set<String>?
    }

    struct BuildSettingData: Codable {
        let name: String
        let value: [String]
        let condition: BuildSettingCondition?
    }

    struct CSetting: Codable {
        let data: BuildSettingData
    }

    struct CXXSetting: Codable {
        let data: BuildSettingData
    }

    struct SwiftSetting: Codable {
        let data: BuildSettingData
    }

    struct LinkerSetting: Codable {
        let data: BuildSettingData
    }

    // MARK: - language standards serialization

    enum CLanguageStandard: String, Codable {
        case c89
        case c90
        case c99
        case c11
        case c17
        case c18
        case c2x
        case gnu89
        case gnu90
        case gnu99
        case gnu11
        case gnu17
        case gnu18
        case gnu2x
        case iso9899_1990 = "iso9899:1990"
        case iso9899_199409 = "iso9899:199409"
        case iso9899_1999 = "iso9899:1999"
        case iso9899_2011 = "iso9899:2011"
        case iso9899_2017 = "iso9899:2017"
        case iso9899_2018 = "iso9899:2018"
    }

    enum CXXLanguageStandard: String, Codable {
        case cxx98 = "c++98"
        case cxx03 = "c++03"
        case cxx11 = "c++11"
        case cxx14 = "c++14"
        case cxx17 = "c++17"
        case cxx1z = "c++1z"
        case cxx20 = "c++20"
        case cxx2b = "c++2b"
        case gnucxx98 = "gnu++98"
        case gnucxx03 = "gnu++03"
        case gnucxx11 = "gnu++11"
        case gnucxx14 = "gnu++14"
        case gnucxx17 = "gnu++17"
        case gnucxx1z = "gnu++1z"
        case gnucxx20 = "gnu++20"
        case gnucxx2b = "gnu++2b"
    }

    enum SwiftVersion: Codable {
        case v3
        case v4
        case v4_2
        case v5
        case v6
        case version(String)
    }

    // MARK: - version serialization

    struct Version: Codable {
        let major: Int
        let minor: Int
        let patch: Int
        let prereleaseIdentifiers: [String]
        let buildMetadataIdentifiers: [String]
    }

    // MARK: - package dependency serialization

    struct PackageDependency: Codable {
        struct Trait: Hashable, Codable {
            struct Condition: Hashable, Codable {
                let traits: Set<String>?
            }

            var name: String
            var condition: Condition?
        }
        enum SourceControlRequirement: Codable {
            case exact(Version)
            case range(lowerBound: Version, upperBound: Version)
            case revision(String)
            case branch(String)
        }

        enum RegistryRequirement: Codable {
            case exact(Version)
            case range(lowerBound: Version, upperBound: Version)
        }

        enum Kind: Codable {
            case fileSystem(name: String?, path: String)
            case sourceControl(name: String?, location: String, requirement: SourceControlRequirement)
            case registry(id: String, requirement: RegistryRequirement)
        }

        let kind: Kind
        let moduleAliases: [String: String]?
        let traits: Set<Trait>?
    }

    // MARK: - platforms serialization

    struct Platform: Codable {
        let name: String
    }

    struct SupportedPlatform: Codable {
        let platform: Platform
        let version: String?
    }

    // MARK: - target serialization

    enum TargetDependency: Codable {
        struct Condition: Codable {
            let platforms: [Platform]?
            let traits: Set<String>?
        }

        case target(name: String, condition: Condition?)
        case product(name: String, package: String?, moduleAliases: [String: String]?, condition: Condition?)
        case byName(name: String, condition: Condition?)
    }

    enum TargetType: Codable {
        case regular
        case executable
        case test
        case system
        case binary
        case plugin
        case `macro`
    }

    enum PluginCapability: Codable {
        case buildTool
        case command(intent: PluginCommandIntent, permissions: [PluginPermission])
    }

    enum PluginCommandIntent: Codable {
        case documentationGeneration
        case sourceCodeFormatting
        case custom(verb: String, description: String)
    }

    enum PluginPermission: Codable {
        case allowNetworkConnections(scope: PluginNetworkPermissionScope, reason: String)
        case writeToPackageDirectory(reason: String)
    }

    enum PluginNetworkPermissionScope: Codable {
        case none
        case local(ports: [Int])
        case all(ports: [Int])
        case docker
        case unixDomainSocket
    }

    enum PluginUsage: Codable {
        case plugin(name: String, package: String?)
    }

    struct Target: Codable {
        let name: String
        let path: String?
        let url: String?
        let sources: [String]?
        let resources: [Resource]?
        let exclude: [String]
        let dependencies: [TargetDependency]
        let publicHeadersPath: String?
        let type: TargetType
        let packageAccess: Bool
        let pkgConfig: String?
        let providers: [SystemPackageProvider]?
        let pluginCapability: PluginCapability?
        let cSettings: [CSetting]?
        let cxxSettings: [CXXSetting]?
        let swiftSettings: [SwiftSetting]?
        let linkerSettings: [LinkerSetting]?
        let checksum: String?
        let pluginUsages: [PluginUsage]?
    }

    // MARK: - resource serialization

    struct Resource: Codable {
        enum Localization: String, Codable {
            case `default`
            case base
        }

        let rule: String
        let path: String
        let localization: Localization?
    }

    // MARK: - product serialization

    struct Product: Codable {
        enum ProductType: Codable {
            enum LibraryType: Codable {
                case automatic
                case dynamic
                case `static`
            }

            case executable
            case library(type: LibraryType)
            case plugin
        }

        let name: String
        let targets: [String]
        let productType: ProductType

        #if ENABLE_APPLE_PRODUCT_TYPES
        let settings: [ProductSetting]
        #endif
    }

    // MARK: - trait serialization

    struct Trait: Hashable, Codable {
        let name: String
        let description: String?
        let enabledTraits: Set<String>
    }

    // MARK: - package serialization

    struct LanguageTag: Codable {
        let tag: String
    }

    enum SystemPackageProvider: Codable {
        case brew([String])
        case apt([String])
        case yum([String])
        case nuget([String])
    }

    struct Package: Codable {
        let name: String
        let platforms: [SupportedPlatform]?
        let defaultLocalization: LanguageTag?
        let pkgConfig: String?
        let providers: [SystemPackageProvider]?
        let targets: [Target]
        let products: [Product]
        let traits: Set<Trait>?
        let dependencies: [PackageDependency]
        let swiftLanguageVersions: [SwiftVersion]?
        let cLanguageStandard: CLanguageStandard?
        let cxxLanguageStandard: CXXLanguageStandard?
    }
}

#if ENABLE_APPLE_PRODUCT_TYPES
extension Serialization {
    enum ProductSetting: Codable {
        case bundleIdentifier(String)
        case teamIdentifier(String)
        case displayVersion(String)
        case bundleVersion(String)
        case iOSAppInfo(IOSAppInfo)
        
        struct IOSAppInfo: Codable {
            var appIcon: AppIcon?
            var accentColor: AccentColor?
            var supportedDeviceFamilies: [DeviceFamily]
            var supportedInterfaceOrientations: [InterfaceOrientation]
            var capabilities: [Capability] = []
            var appCategory: AppCategory?
            var additionalInfoPlistContentFilePath: String?
            
            enum AccentColor: Codable {
                struct PresetColor: Codable {
                    var rawValue: String
                }
                
                case presetColor(PresetColor)
                case asset(String)
            }
            
            enum AppIcon: Codable {
                struct PlaceholderIcon: Codable {
                    var rawValue: String
                }
                
                case placeholder(icon: PlaceholderIcon)
                case asset(String)
            }
            
            enum DeviceFamily: String, Codable {
                case phone
                case pad
                case mac
            }
            
            struct DeviceFamilyCondition: Codable {
                var deviceFamilies: [DeviceFamily]
            }
            
            enum InterfaceOrientation: Codable {
                case portrait(_ condition: DeviceFamilyCondition? = nil)
                case portraitUpsideDown(_ condition: DeviceFamilyCondition? = nil)
                case landscapeRight(_ condition: DeviceFamilyCondition? = nil)
                case landscapeLeft(_ condition: DeviceFamilyCondition? = nil)
            }
            
            enum Capability: Codable {
                case appTransportSecurity(configuration: AppTransportSecurityConfiguration, _ condition: DeviceFamilyCondition? = nil)
                case bluetoothAlways(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case calendars(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case camera(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case contacts(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case faceID(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case fileAccess(_ location: FileAccessLocation, mode: FileAccessMode, _ condition: DeviceFamilyCondition? = nil)
                case incomingNetworkConnections(_ condition: DeviceFamilyCondition? = nil)
                case localNetwork(purposeString: String, bonjourServiceTypes: [String]? = nil, _ condition: DeviceFamilyCondition? = nil)
                case locationAlwaysAndWhenInUse(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case locationWhenInUse(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case mediaLibrary(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case microphone(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case motion(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case nearbyInteractionAllowOnce(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case outgoingNetworkConnections(_ condition: DeviceFamilyCondition? = nil)
                case photoLibrary(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case photoLibraryAdd(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case reminders(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case speechRecognition(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
                case userTracking(purposeString: String, _ condition: DeviceFamilyCondition? = nil)
            }
            
            struct AppTransportSecurityConfiguration: Codable {
                var allowsArbitraryLoadsInWebContent: Bool? = nil
                var allowsArbitraryLoadsForMedia: Bool? = nil
                var allowsLocalNetworking: Bool? = nil
                var exceptionDomains: [ExceptionDomain]? = nil
                var pinnedDomains: [PinnedDomain]? = nil
                
                struct ExceptionDomain: Codable {
                    var domainName: String
                    var includesSubdomains: Bool? = nil
                    var exceptionAllowsInsecureHTTPLoads: Bool? = nil
                    var exceptionMinimumTLSVersion: String? = nil
                    var exceptionRequiresForwardSecrecy: Bool? = nil
                    var requiresCertificateTransparency: Bool? = nil
                }
                
                struct PinnedDomain: Codable {
                    var domainName: String
                    var includesSubdomains : Bool? = nil
                    var pinnedCAIdentities : [[String: String]]? = nil
                    var pinnedLeafIdentities : [[String: String]]? = nil
                }
            }
            
            enum FileAccessLocation: String, Codable {
                case userSelectedFiles
                case downloadsFolder
                case pictureFolder
                case musicFolder
                case moviesFolder
            }
            
            enum FileAccessMode: String, Codable {
                case readOnly
                case readWrite
            }
            
            struct AppCategory: Codable {
                var rawValue: String
            }
        }
    }
}
#endif