forked from swiftlang/swift-package-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageDescriptionSerializationConversion.swift
More file actions
396 lines (360 loc) · 13.2 KB
/
Copy pathPackageDescriptionSerializationConversion.swift
File metadata and controls
396 lines (360 loc) · 13.2 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
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
extension Serialization.BuildConfiguration {
init(_ configuration: PackageDescription.BuildConfiguration) {
self.config = configuration.config
}
}
extension Serialization.BuildSettingCondition {
init(_ condition: PackageDescription.BuildSettingCondition) {
self.platforms = condition.platforms?.map { .init($0) }
self.config = condition.config.map { .init($0) }
}
}
extension Serialization.BuildSettingData {
init(_ settingsData: PackageDescription.BuildSettingData) {
self.name = settingsData.name
self.value = settingsData.value
self.condition = settingsData.condition.map { .init($0) }
}
}
extension Serialization.CSetting {
init(_ setting: PackageDescription.CSetting) {
self.data = .init(setting.data)
}
}
extension Serialization.CXXSetting {
init(_ setting: PackageDescription.CXXSetting) {
self.data = .init(setting.data)
}
}
extension Serialization.SwiftSetting {
init(_ setting: PackageDescription.SwiftSetting) {
self.data = .init(setting.data)
}
}
extension Serialization.LinkerSetting {
init(_ setting: PackageDescription.LinkerSetting) {
self.data = .init(setting.data)
}
}
extension Serialization.CLanguageStandard {
init(_ languageStandard: PackageDescription.CLanguageStandard) {
switch languageStandard {
case .c89: self = .c89
case .c90: self = .c90
case .c99: self = .c99
case .c11: self = .c11
case .c17: self = .c17
case .c18: self = .c18
case .c2x: self = .c2x
case .gnu89: self = .gnu89
case .gnu90: self = .gnu90
case .gnu99: self = .gnu99
case .gnu11: self = .gnu11
case .gnu17: self = .gnu17
case .gnu18: self = .gnu18
case .gnu2x: self = .gnu2x
case .iso9899_1990: self = .iso9899_1990
case .iso9899_199409: self = .iso9899_199409
case .iso9899_1999: self = .iso9899_1999
case .iso9899_2011: self = .iso9899_2011
case .iso9899_2017: self = .iso9899_2017
case .iso9899_2018: self = .iso9899_2018
}
}
}
extension Serialization.CXXLanguageStandard {
init(_ languageStandard: PackageDescription.CXXLanguageStandard) {
switch languageStandard {
case .cxx98: self = .cxx98
case .cxx03: self = .cxx03
case .cxx11: self = .cxx11
case .cxx14: self = .cxx14
case .cxx17: self = .cxx17
case .cxx1z: self = .cxx1z
case .cxx20: self = .cxx20
case .cxx2b: self = .cxx2b
case .gnucxx98: self = .gnucxx98
case .gnucxx03: self = .gnucxx03
case .gnucxx11: self = .gnucxx11
case .gnucxx14: self = .gnucxx14
case .gnucxx17: self = .gnucxx17
case .gnucxx1z: self = .gnucxx1z
case .gnucxx20: self = .gnucxx20
case .gnucxx2b: self = .gnucxx2b
}
}
}
extension Serialization.SwiftVersion {
init(_ swiftVersion: PackageDescription.SwiftVersion) {
switch swiftVersion {
case .v3: self = .v3
case .v4: self = .v4
case .v4_2: self = .v4_2
case .v5: self = .v5
case .v6: self = .v6
case .version(let version): self = .version(version)
}
}
}
extension Serialization.Version {
init(_ version: PackageDescription.Version) {
self.major = version.major
self.minor = version.minor
self.patch = version.patch
self.prereleaseIdentifiers = version.prereleaseIdentifiers
self.buildMetadataIdentifiers = version.buildMetadataIdentifiers
}
}
extension Serialization.PackageDependency.SourceControlRequirement {
init(_ requirement: PackageDescription.Package.Dependency.SourceControlRequirement) {
switch requirement {
case .range(let range):
self = .range(lowerBound: .init(range.lowerBound), upperBound: .init(range.upperBound))
case .exact(let version):
self = .exact(.init(version))
case .revision(let revision):
self = .revision(revision)
case .branch(let branch):
self = .branch(branch)
}
}
}
extension Serialization.PackageDependency.RegistryRequirement {
init(_ requirement: PackageDescription.Package.Dependency.RegistryRequirement) {
switch requirement {
case .exact(let version):
self = .exact(.init(version))
case .range(let range):
self = .range(lowerBound: .init(range.lowerBound), upperBound: .init(range.upperBound))
}
}
}
extension Serialization.PackageDependency.Kind {
init(_ kind: PackageDescription.Package.Dependency.Kind) {
switch kind {
case .fileSystem(let name, let path):
self = .fileSystem(name: name, path: path)
case .sourceControl(let name, let location, let requirement):
self = .sourceControl(name: name, location: location, requirement: .init(requirement))
case .registry(let identity, let requirement):
self = .registry(id: identity, requirement: .init(requirement))
}
}
}
extension Serialization.PackageDependency {
init(_ dependency: PackageDescription.Package.Dependency) {
self.kind = .init(dependency.kind)
self.moduleAliases = dependency.moduleAliases
}
}
extension Serialization.Platform {
init(_ platform: PackageDescription.Platform) {
self.name = platform.name
}
}
extension Serialization.SupportedPlatform {
init(_ platform: PackageDescription.SupportedPlatform) {
self.platform = .init(platform.platform)
self.version = platform.version
}
}
extension Serialization.TargetDependency.Condition {
init(_ condition: TargetDependencyCondition) {
self.platforms = condition.platforms?.map { .init($0) }
}
}
extension Serialization.TargetDependency {
init(_ dependency: PackageDescription.Target.Dependency) {
switch dependency {
case .targetItem(let name, let condition):
self = .target(name: name, condition: condition.map { .init($0) })
case .productItem(let name, let package, let moduleAliases, let condition):
self = .product(
name: name,
package: package,
moduleAliases: moduleAliases,
condition: condition.map { .init($0) }
)
case .byNameItem(let name, let condition):
self = .byName(name: name, condition: condition.map { .init($0) })
}
}
}
extension Serialization.TargetType {
init(_ type: PackageDescription.Target.TargetType) {
switch type {
case .regular: self = .regular
case .executable: self = .executable
case .test: self = .test
case .system: self = .system
case .binary: self = .binary
case .plugin: self = .plugin
case .macro: self = .macro
}
}
}
extension Serialization.PluginCapability {
init(_ capability: PackageDescription.Target.PluginCapability) {
switch capability {
case .buildTool: self = .buildTool
case .command(let intent, let permissions): self = .command(
intent: .init(intent),
permissions: permissions.map { .init($0) }
)
}
}
}
extension Serialization.PluginCommandIntent {
init(_ intent: PackageDescription.PluginCommandIntent) {
switch intent {
case .custom(let verb, let description): self = .custom(verb: verb, description: description)
case .sourceCodeFormatting: self = .sourceCodeFormatting
case .documentationGeneration: self = .documentationGeneration
}
}
}
extension Serialization.PluginPermission {
init(_ permission: PackageDescription.PluginPermission) {
switch permission {
case .allowNetworkConnections(let scope, let reason): self = .allowNetworkConnections(
scope: .init(scope),
reason: reason
)
case .writeToPackageDirectory(let reason): self = .writeToPackageDirectory(reason: reason)
}
}
}
extension Serialization.PluginNetworkPermissionScope {
init(_ scope: PackageDescription.PluginNetworkPermissionScope) {
switch scope {
case .none: self = .none
case .local(let ports): self = .local(ports: ports)
case .all(let ports): self = .all(ports: ports)
case .docker: self = .docker
case .unixDomainSocket: self = .unixDomainSocket
}
}
}
extension Serialization.PluginUsage {
init(_ usage: PackageDescription.Target.PluginUsage) {
switch usage {
case .plugin(let name, let package): self = .plugin(name: name, package: package)
}
}
}
extension Serialization.Target {
init(_ target: PackageDescription.Target) {
self.name = target.name
self.packageAccess = target.packageAccess
self.path = target.path
self.url = target.url
self.sources = target.sources
self.resources = target.resources?.map { .init($0) }
self.exclude = target.exclude
self.dependencies = target.dependencies.map { .init($0) }
self.publicHeadersPath = target.publicHeadersPath
self.type = .init(target.type)
self.pkgConfig = target.pkgConfig
self.providers = target.providers?.map { .init($0) }
self.pluginCapability = target.pluginCapability.map { .init($0) }
self.cSettings = target.cSettings?.map { .init($0) }
self.cxxSettings = target.cxxSettings?.map { .init($0) }
self.swiftSettings = target.swiftSettings?.map { .init($0) }
self.linkerSettings = target.linkerSettings?.map { .init($0) }
self.checksum = target.checksum
self.pluginUsages = target.plugins?.map { .init($0) }
}
}
extension Serialization.Resource {
init(_ resource: PackageDescription.Resource) {
self.rule = resource.rule
self.path = resource.path
self.localization = resource.localization.map { .init($0) }
}
}
extension Serialization.Resource.Localization {
init(_ localization: PackageDescription.Resource.Localization) {
switch localization {
case .base: self = .base
case .default: self = .default
}
}
}
extension Serialization.Product.ProductType.LibraryType {
init(_ type: PackageDescription.Product.Library.LibraryType) {
switch type {
case .dynamic: self = .dynamic
case .static: self = .static
}
}
}
extension Serialization.Product {
init(_ product: PackageDescription.Product) {
if let executable = product as? PackageDescription.Product.Executable {
self.init(executable)
} else if let library = product as? PackageDescription.Product.Library {
self.init(library)
} else if let plugin = product as? PackageDescription.Product.Plugin {
self.init(plugin)
} else {
fatalError("should not be reached")
}
}
init(_ executable: PackageDescription.Product.Executable) {
self.name = executable.name
self.targets = executable.targets
self.productType = .executable
}
init(_ library: PackageDescription.Product.Library) {
self.name = library.name
self.targets = library.targets
let libraryType = library.type.map { ProductType.LibraryType($0) } ?? .automatic
self.productType = .library(type: libraryType)
}
init(_ plugin: PackageDescription.Product.Plugin) {
self.name = plugin.name
self.targets = plugin.targets
self.productType = .plugin
}
}
extension Serialization.Package {
init(_ package: PackageDescription.Package) {
self.name = package.name
self.platforms = package.platforms?.map { .init($0) }
self.defaultLocalization = package.defaultLocalization.map { .init($0) }
self.pkgConfig = package.pkgConfig
self.providers = package.providers?.map { .init($0) }
self.targets = package.targets.map { .init($0) }
self.products = package.products.map { .init($0) }
self.dependencies = package.dependencies.map { .init($0) }
self.swiftLanguageVersions = package.swiftLanguageModes?.map { .init($0) }
self.cLanguageStandard = package.cLanguageStandard.map { .init($0) }
self.cxxLanguageStandard = package.cxxLanguageStandard.map { .init($0) }
}
}
extension Serialization.LanguageTag {
init(_ language: PackageDescription.LanguageTag) {
self.tag = language.tag
}
}
extension Serialization.SystemPackageProvider {
init(_ provider: PackageDescription.SystemPackageProvider) {
switch provider {
case .brewItem(let values): self = .brew(values)
case .aptItem(let values): self = .apt(values)
case .yumItem(let values): self = .yum(values)
case .nugetItem(let values): self = .nuget(values)
}
}
}