forked from apple/swift-package-manager
/
SupportedPlatforms.swift
703 lines (589 loc) · 28.7 KB
/
SupportedPlatforms.swift
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
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2018-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
//
//===----------------------------------------------------------------------===//
/// A platform supported by Swift Package Manager.
public struct Platform: Equatable {
/// The name of the platform.
let name: String
private init(name: String) {
self.name = name
}
/// Creates a custom platform.
///
/// Use this function if none of the predefined platform names match the platform you are targeting.
/// - Parameter platformName: The name of the platform.
/// - Returns: A `Platform` instance.
@available(_PackageDescription, introduced: 5.6)
public static func custom(_ platformName: String) -> Platform {
return Platform(name: platformName)
}
/// The macOS platform.
public static let macOS: Platform = Platform(name: "macos")
/// The Mac Catalyst platform.
public static let macCatalyst: Platform = Platform(name: "maccatalyst")
/// The iOS platform.
public static let iOS: Platform = Platform(name: "ios")
/// The tvOS platform.
public static let tvOS: Platform = Platform(name: "tvos")
/// The watchOS platform.
public static let watchOS: Platform = Platform(name: "watchos")
/// The DriverKit platform
public static let driverKit: Platform = Platform(name: "driverkit")
/// The Linux platform.
public static let linux: Platform = Platform(name: "linux")
/// The Windows platform.
@available(_PackageDescription, introduced: 5.2)
public static let windows: Platform = Platform(name: "windows")
/// The Android platform.
@available(_PackageDescription, introduced: 5.2)
public static let android: Platform = Platform(name: "android")
/// The WebAssembly System Interface platform.
@available(_PackageDescription, introduced: 5.3)
public static let wasi: Platform = Platform(name: "wasi")
/// The OpenBSD platform.
@available(_PackageDescription, introduced: 5.8)
public static let openbsd: Platform = Platform(name: "openbsd")
}
/// A platform that the Swift package supports.
///
/// By default, Swift Package Manager assigns a predefined minimum deployment version for each
/// supported platforms unless you configure supported platforms using the
/// `platforms` API. This predefined deployment version is the oldest deployment
/// target version that the installed SDK supports for a given platform. One
/// exception to this rule is macOS, for which the minimum deployment target
/// version starts from 10.10. Packages can choose to configure the minimum
/// deployment target version for a platform by using the APIs defined in this
/// struct. Swift Package Manager emits appropriate errors when an invalid value is provided for
/// supported platforms, such as an empty array, multiple declarations for the
/// same platform, or an invalid version specification.
///
/// Swift Package Manager emits an error if a dependency isn't compatible with the top-level
/// package's deployment version. The deployment target of a package's
/// dependencies must be lower than or equal to the top-level package's
/// deployment target version for a particular platform.
public struct SupportedPlatform: Equatable {
/// The platform.
let platform: Platform
/// The platform version.
let version: String?
/// Creates supported platform instance.
init(platform: Platform, version: String? = nil) {
self.platform = platform
self.version = version
}
/// Configures the minimum deployment target version for the macOS platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
public static func macOS(_ version: SupportedPlatform.MacOSVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .macOS, version: version.version)
}
/// Configures the minimum deployment target version for the macOS platform
/// using a version string.
///
/// The version string must be a series of two or three dot-separated
/// integers, such as `10.10` or `10.10.1`.
///
/// - Since: First available in PackageDescription 5.0.
///
/// - Parameter versionString: The minimum deployment target as a string
/// representation of two or three dot-separated integers, such as
/// `10.10.1`.
/// - Returns: A `SupportedPlatform` instance.
public static func macOS(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .macOS, version: SupportedPlatform.MacOSVersion(string: versionString).version)
}
/// Configures the minimum deployment target version for the Mac Catalyst platform.
///
/// - Since: First available in PackageDescription 5.5
///
/// - Parameter version: The minimum deployment target that the package supports.
/// - Returns: A `SupportedPlatform` instance.
@available(_PackageDescription, introduced: 5.5)
public static func macCatalyst(_ version: SupportedPlatform.MacCatalystVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .macCatalyst, version: version.version)
}
/// Configures the minimum deployment target version for the Mac Catalyst platform
/// using a version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `13.0` or `13.0.1`.
///
/// - Since: First available in PackageDescription 5.5
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `13.0.1`.
/// - Returns: A `SupportedPlatform` instance.
@available(_PackageDescription, introduced: 5.5)
public static func macCatalyst(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .macCatalyst, version: SupportedPlatform.MacCatalystVersion(string: versionString).version)
}
/// Configures the minimum deployment target version for the iOS platform.
///
/// - Since: First available in PackageDescription 5.0.
///
/// - Parameter version: The minimum deployment target that the package supports.
/// - Returns: A `SupportedPlatform` instance.
public static func iOS(_ version: SupportedPlatform.IOSVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .iOS, version: version.version)
}
/// Configures the minimum deployment target version for the iOS platform
/// using a custom version string.
///
/// The version string must be a series of two or three dot-separated
/// integers, such as `8.0` or `8.0.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string
/// representation of two or three dot-separated integers, such as `8.0.1`.
/// - Returns: A `SupportedPlatform` instance.
public static func iOS(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .iOS, version: SupportedPlatform.IOSVersion(string: versionString).version)
}
/// Configures the minimum deployment target version for the tvOS platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
/// - Returns: A `SupportedPlatform` instance.
public static func tvOS(_ version: SupportedPlatform.TVOSVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .tvOS, version: version.version)
}
/// Configures the minimum deployment target version for the tvOS platform
/// using a custom version string.
///
/// The version string must be a series of two or three dot-separated
/// integers,such as `9.0` or `9.0.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string
/// representation of two or three dot-separated integers, such as `9.0.1`.
/// - Returns: A `SupportedPlatform` instance.
public static func tvOS(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .tvOS, version: SupportedPlatform.TVOSVersion(string: versionString).version)
}
/// Configure the minimum deployment target version for the watchOS
/// platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
/// - Returns: A `SupportedPlatform` instance.
public static func watchOS(_ version: SupportedPlatform.WatchOSVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .watchOS, version: version.version)
}
/// Configure the minimum deployment target version for the watchOS
/// platform using a custom version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `2.0` or `2.0.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string
/// representation of two or three dot-separated integers, such as `2.0.1`.
/// - Returns: A `SupportedPlatform` instance.
public static func watchOS(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .watchOS, version: SupportedPlatform.WatchOSVersion(string: versionString).version)
}
/// Configures the minimum deployment target version for the DriverKit platform.
///
/// - Parameter version: The minimum deployment target that the package supports.
@available(_PackageDescription, introduced: 5.5)
public static func driverKit(_ version: SupportedPlatform.DriverKitVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .driverKit, version: version.version)
}
/// Configures the minimum deployment target version for the DriverKit platform
/// using a custom version string.
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `19.0.1`.
/// - Returns: A `SupportedPlatform` instance.
@available(_PackageDescription, introduced: 5.5)
public static func driverKit(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .driverKit, version: SupportedPlatform.DriverKitVersion(string: versionString).version)
}
/// Configures the minimum deployment target version for custom platforms.
///
/// - Since: First available in PackageDescription 5.6
///
/// - Parameters:
/// - platformName: The name of the platform.
/// - versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `19.0.1`.
/// - Returns: A `SupportedPlatform` instance.
@available(_PackageDescription, introduced: 5.6)
public static func custom(_ platformName: String, versionString: String) -> SupportedPlatform {
do {
try CustomPlatformVersion.validateVersion(versionString)
} catch {
errors.append("\(error)")
}
return SupportedPlatform(platform: .custom(platformName), version: versionString)
}
}
/// An extension to the SupportedPlatform struct that defines major platform versions.
extension SupportedPlatform {
/// The supported macOS version.
public struct MacOSVersion: AppleOSVersion {
fileprivate static let name = "macOS"
fileprivate static let minimumMajorVersion = 10
/// The underlying version representation.
let version: String
fileprivate init(uncheckedVersion version: String) {
self.version = version
}
/// The value that represents macOS 10.10.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "macOS 10.13 is the oldest supported version")
public static let v10_10: MacOSVersion = .init(string: "10.10")
/// The value that represents macOS 10.11.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "macOS 10.13 is the oldest supported version")
public static let v10_11: MacOSVersion = .init(string: "10.11")
/// The value that represents macOS 10.12.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "macOS 10.13 is the oldest supported version")
public static let v10_12: MacOSVersion = .init(string: "10.12")
/// The value that represents macOS 10.13.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v10_13: MacOSVersion = .init(string: "10.13")
/// The value that represents macOS 10.14.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v10_14: MacOSVersion = .init(string: "10.14")
/// The value that represents macOS 10.15.
///
/// - Since: First available in PackageDescription 5.1.
@available(_PackageDescription, introduced: 5.1)
public static let v10_15: MacOSVersion = .init(string: "10.15")
/// The value that represents macOS 10.16, which has been
/// replaced by the value for macOS 11.0.
///
/// - Since: First available in PackageDescription 5.3.
@available(*, unavailable, renamed: "v11")
@available(_PackageDescription, introduced: 5.3)
public static let v10_16: MacOSVersion = .init(string: "11.0")
/// The value that represents macOS 11.0.
/// - Since: First available in PackageDescription 5.3.
@available(_PackageDescription, introduced: 5.3)
public static let v11: MacOSVersion = .init(string: "11.0")
/// The value that represents macOS 12.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v12: MacOSVersion = .init(string: "12.0")
/// The value that represents macOS 13.0.
///
/// - Since: First available in PackageDescription 5.7.
@available(_PackageDescription, introduced: 5.7)
public static let v13: MacOSVersion = .init(string: "13.0")
/// The value that represents macOS 14.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v14: MacOSVersion = .init(string: "14.0")
}
/// The supported tvOS version.
public struct TVOSVersion: AppleOSVersion {
fileprivate static let name = "tvOS"
fileprivate static let minimumMajorVersion = 9
/// The underlying version representation.
let version: String
fileprivate init(uncheckedVersion version: String) {
self.version = version
}
/// The value that represents tvOS 9.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "tvOS 11.0 is the oldest supported version")
public static let v9: TVOSVersion = .init(string: "9.0")
/// The value that represents tvOS 10.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "tvOS 11.0 is the oldest supported version")
public static let v10: TVOSVersion = .init(string: "10.0")
/// The value that represents tvOS 11.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v11: TVOSVersion = .init(string: "11.0")
/// The value that represents tvOS 12.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v12: TVOSVersion = .init(string: "12.0")
/// The value that represents tvOS 13.0.
///
/// - Since: First available in PackageDescription 5.1.
@available(_PackageDescription, introduced: 5.1)
public static let v13: TVOSVersion = .init(string: "13.0")
/// The value that represents tvOS 14.0.
///
/// - Since: First available in PackageDescription 5.3.
@available(_PackageDescription, introduced: 5.3)
public static let v14: TVOSVersion = .init(string: "14.0")
/// The value that represents tvOS 15.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v15: TVOSVersion = .init(string: "15.0")
/// The value that represents tvOS 16.0.
///
/// - Since: First available in PackageDescription 5.7.
@available(_PackageDescription, introduced: 5.7)
public static let v16: TVOSVersion = .init(string: "16.0")
/// The value that represents tvOS 17.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v17: TVOSVersion = .init(string: "17.0")
}
/// The supported Mac Catalyst version.
public struct MacCatalystVersion: AppleOSVersion {
fileprivate static let name = "macCatalyst"
fileprivate static let minimumMajorVersion = 13
/// The underlying version representation.
let version: String
fileprivate init(uncheckedVersion version: String) {
self.version = version
}
/// The value that represents Mac Catalyst 13.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v13: MacCatalystVersion = .init(string: "13.0")
/// The value that represents Mac Catalyst 14.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v14: MacCatalystVersion = .init(string: "14.0")
/// The value that represents Mac Catalyst 15.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v15: MacCatalystVersion = .init(string: "15.0")
/// The value that represents Mac Catalyst 16.0.
///
/// - Since: First available in PackageDescription 5.7.
@available(_PackageDescription, introduced: 5.7)
public static let v16: MacCatalystVersion = .init(string: "16.0")
/// The value that represents Mac Catalyst 17.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v17: MacCatalystVersion = .init(string: "17.0")
}
/// The supported iOS version.
public struct IOSVersion: AppleOSVersion {
fileprivate static let name = "iOS"
fileprivate static let minimumMajorVersion = 2
/// The underlying version representation.
let version: String
fileprivate init(uncheckedVersion version: String) {
self.version = version
}
/// The value that represents iOS 8.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "iOS 11.0 is the oldest supported version")
public static let v8: IOSVersion = .init(string: "8.0")
/// The value that represents iOS 9.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "iOS 11.0 is the oldest supported version")
public static let v9: IOSVersion = .init(string: "9.0")
/// The value that represents iOS 10.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "iOS 11.0 is the oldest supported version")
public static let v10: IOSVersion = .init(string: "10.0")
/// The value that represents iOS 11.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v11: IOSVersion = .init(string: "11.0")
/// The value that represents iOS 12.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v12: IOSVersion = .init(string: "12.0")
/// The value that represents iOS 13.0.
///
/// - Since: First available in PackageDescription 5.1.
@available(_PackageDescription, introduced: 5.1)
public static let v13: IOSVersion = .init(string: "13.0")
/// The value that represents iOS 14.0.
///
/// - Since: First available in PackageDescription 5.3.
@available(_PackageDescription, introduced: 5.3)
public static let v14: IOSVersion = .init(string: "14.0")
/// The value that represents iOS 15.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v15: IOSVersion = .init(string: "15.0")
/// The value that represents iOS 16.0.
///
/// - Since: First available in PackageDescription 5.7.
@available(_PackageDescription, introduced: 5.7)
public static let v16: IOSVersion = .init(string: "16.0")
/// The value that represents iOS 17.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v17: IOSVersion = .init(string: "17.0")
}
/// The supported watchOS version.
public struct WatchOSVersion: AppleOSVersion {
fileprivate static let name = "watchOS"
fileprivate static let minimumMajorVersion = 2
/// The underlying version representation.
let version: String
fileprivate init(uncheckedVersion version: String) {
self.version = version
}
/// The value that represents watchOS 2.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "watchOS 4.0 is the oldest supported version")
public static let v2: WatchOSVersion = .init(string: "2.0")
/// The value that represents watchOS 3.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0, deprecated: 5.7, message: "watchOS 4.0 is the oldest supported version")
public static let v3: WatchOSVersion = .init(string: "3.0")
/// The value that represents watchOS 4.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v4: WatchOSVersion = .init(string: "4.0")
/// The value that represents watchOS 5.0.
///
/// - Since: First available in PackageDescription 5.0.
@available(_PackageDescription, introduced: 5.0)
public static let v5: WatchOSVersion = .init(string: "5.0")
/// The value that represents watchOS 6.0.
///
/// - Since: First available in PackageDescription 5.1.
@available(_PackageDescription, introduced: 5.1)
public static let v6: WatchOSVersion = .init(string: "6.0")
/// The value that represents watchOS 7.0.
///
/// - Since: First available in PackageDescription 5.3.
@available(_PackageDescription, introduced: 5.3)
public static let v7: WatchOSVersion = .init(string: "7.0")
/// The value that represents watchOS 8.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v8: WatchOSVersion = .init(string: "8.0")
/// The value that represents watchOS 9.0.
///
/// - Since: First available in PackageDescription 5.7.
@available(_PackageDescription, introduced: 5.7)
public static let v9: WatchOSVersion = .init(string: "9.0")
/// The value that represents watchOS 10.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v10: WatchOSVersion = .init(string: "10.0")
}
/// The supported DriverKit version.
public struct DriverKitVersion: AppleOSVersion {
fileprivate static let name = "DriverKit"
fileprivate static let minimumMajorVersion = 19
/// The underlying version representation.
let version: String
fileprivate init(uncheckedVersion version: String) {
self.version = version
}
/// The value that represents DriverKit 19.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v19: DriverKitVersion = .init(string: "19.0")
/// The value that represents DriverKit 20.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v20: DriverKitVersion = .init(string: "20.0")
/// The value that represents DriverKit 21.0.
///
/// - Since: First available in PackageDescription 5.5.
@available(_PackageDescription, introduced: 5.5)
public static let v21: DriverKitVersion = .init(string: "21.0")
/// The value that represents DriverKit 22.0.
///
/// - Since: First available in PackageDescription 5.7.
@available(_PackageDescription, introduced: 5.7)
public static let v22: DriverKitVersion = .init(string: "22.0")
/// The value that represents DriverKit 23.0.
///
/// - Since: First available in PackageDescription 5.9.
@available(_PackageDescription, introduced: 5.9)
public static let v23: DriverKitVersion = .init(string: "23.0")
}
/// A supported custom platform version.
public struct CustomPlatformVersion: AppleOSVersion {
/// The name of the custom platform.
static var name: String = "custom platform"
/// The minimum valid major version number.
static var minimumMajorVersion = 0
fileprivate init(uncheckedVersion version: String) {
}
}
}
fileprivate protocol AppleOSVersion {
static var name: String { get }
static var minimumMajorVersion: Int { get }
init(uncheckedVersion: String)
}
struct StringError: Error, CustomStringConvertible {
var error: String
init(_ error: String) {
self.error = error
}
var description: String { error }
}
fileprivate extension AppleOSVersion {
static func validateVersion(_ string: String) throws {
let components = string.split(separator: ".", omittingEmptySubsequences: false)
func error(_ error: String) throws {
throw StringError("invalid \(Self.name) version \(string); \(error)")
}
for (idx, component) in components.enumerated() {
if component.isEmpty {
try error("found an empty component")
}
if idx < 2 {
if UInt(component) == nil {
try error("\(component) should be a positive integer")
}
}
}
if (UInt(components[0]) ?? 0) < Self.minimumMajorVersion {
try error("the minimum major version should be \(Self.minimumMajorVersion)")
}
}
init(string: String) {
do {
try Self.validateVersion(string)
} catch {
errors.append("\(error)")
}
self.init(uncheckedVersion: string)
}
}