Skip to content

Commit e2ea4c5

Browse files
committed
Replace bespoke availability system
Removes the script based availability system with the experimental availability macro feature.
1 parent 99feed6 commit e2ea4c5

28 files changed

+157
-247
lines changed

Package.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,40 @@ let cSettings: [CSetting] = [
1616
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
1717
]
1818

19+
let availability = [
20+
("0.0.1", "macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"),
21+
("0.0.2", "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0"),
22+
// FIXME: 0.0.3
23+
("1.1.0", "macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4"),
24+
// FIXME: 1.1.1
25+
("1.2.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
26+
// FIXME: 1.2.1
27+
("1.3.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
28+
// FIXME: 1.3.1
29+
// FIXME: 1.3.2
30+
("1.4.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4"),
31+
// FIXME: 1.4.1
32+
// FIXME: 1.4.2
33+
// FIXME: 1.5.0
34+
]
35+
1936
let swiftSettings: [SwiftSetting] = [
2037
.define(
2138
"SYSTEM_PACKAGE_DARWIN",
2239
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
2340
.define("SYSTEM_PACKAGE"),
2441
.define("ENABLE_MOCKING", .when(configuration: .debug)),
25-
]
42+
] + availability.map { (version, osAvailability) -> SwiftSetting in
43+
#if SYSTEM_PACKAGE
44+
// Matches default SwiftPM availability
45+
let availability = "macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, visionOS 1.0"
46+
#else
47+
let availability = osAvailability
48+
#endif
49+
50+
return .enableExperimentalFeature(
51+
"AvailabilityMacro=System \(version):\(availability)")
52+
}
2653

2754
let package = Package(
2855
name: "swift-system",

Sources/System/Errno.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// An error number used by system calls to communicate what kind of error
1111
/// occurred.
1212
@frozen
13-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
13+
@available(System 0.0.1, *)
1414
public struct Errno: RawRepresentable, Error, Hashable, Codable {
1515
/// The raw C error number.
1616
@_alwaysEmitIntoClient
@@ -1391,7 +1391,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
13911391
}
13921392

13931393
// Constants defined in header but not man page
1394-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1394+
@available(System 0.0.1, *)
13951395
extension Errno {
13961396
/// Operation would block.
13971397
///
@@ -1520,7 +1520,7 @@ extension Errno {
15201520
#endif
15211521
}
15221522

1523-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1523+
@available(System 0.0.1, *)
15241524
extension Errno {
15251525
// TODO: We want to provide safe access to `errno`, but we need a
15261526
// release-barrier to do so.
@@ -1535,14 +1535,14 @@ extension Errno {
15351535
}
15361536

15371537
// Use "hidden" entry points for `NSError` bridging
1538-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1538+
@available(System 0.0.1, *)
15391539
extension Errno {
15401540
public var _code: Int { Int(rawValue) }
15411541

15421542
public var _domain: String { "NSPOSIXErrorDomain" }
15431543
}
15441544

1545-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1545+
@available(System 0.0.1, *)
15461546
extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
15471547
/// A textual representation of the most recent error
15481548
/// returned by a system call.
@@ -1562,7 +1562,7 @@ extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
15621562
public var debugDescription: String { self.description }
15631563
}
15641564

1565-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
1565+
@available(System 0.0.1, *)
15661566
extension Errno {
15671567
@_alwaysEmitIntoClient
15681568
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {

Sources/System/FileDescriptor.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// of `FileDescriptor` values,
1515
/// in the same way as you manage a raw C file handle.
1616
@frozen
17-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
17+
@available(System 0.0.1, *)
1818
public struct FileDescriptor: RawRepresentable, Hashable, Codable {
1919
/// The raw C file handle.
2020
@_alwaysEmitIntoClient
@@ -26,7 +26,7 @@ public struct FileDescriptor: RawRepresentable, Hashable, Codable {
2626
}
2727

2828
// Standard file descriptors.
29-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
29+
@available(System 0.0.1, *)
3030
extension FileDescriptor {
3131
/// The standard input file descriptor, with a numeric value of 0.
3232
@_alwaysEmitIntoClient
@@ -41,11 +41,11 @@ extension FileDescriptor {
4141
public static var standardError: FileDescriptor { .init(rawValue: 2) }
4242
}
4343

44-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
44+
@available(System 0.0.1, *)
4545
extension FileDescriptor {
4646
/// The desired read and write access for a newly opened file.
4747
@frozen
48-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
48+
@available(System 0.0.1, *)
4949
public struct AccessMode: RawRepresentable, Sendable, Hashable, Codable {
5050
/// The raw C access mode.
5151
@_alwaysEmitIntoClient
@@ -88,7 +88,7 @@ extension FileDescriptor {
8888

8989
/// Options that specify behavior for a newly-opened file.
9090
@frozen
91-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
91+
@available(System 0.0.1, *)
9292
public struct OpenOptions: OptionSet, Sendable, Hashable, Codable {
9393
/// The raw C options.
9494
@_alwaysEmitIntoClient
@@ -326,7 +326,7 @@ extension FileDescriptor {
326326

327327
/// Options for specifying what a file descriptor's offset is relative to.
328328
@frozen
329-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
329+
@available(System 0.0.1, *)
330330
public struct SeekOrigin: RawRepresentable, Sendable, Hashable, Codable {
331331
/// The raw C value.
332332
@_alwaysEmitIntoClient
@@ -402,7 +402,7 @@ extension FileDescriptor {
402402
}
403403
}
404404

405-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
405+
@available(System 0.0.1, *)
406406
extension FileDescriptor.AccessMode
407407
: CustomStringConvertible, CustomDebugStringConvertible
408408
{
@@ -421,7 +421,7 @@ extension FileDescriptor.AccessMode
421421
public var debugDescription: String { self.description }
422422
}
423423

424-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
424+
@available(System 0.0.1, *)
425425
extension FileDescriptor.SeekOrigin
426426
: CustomStringConvertible, CustomDebugStringConvertible
427427
{
@@ -444,7 +444,7 @@ extension FileDescriptor.SeekOrigin
444444
public var debugDescription: String { self.description }
445445
}
446446

447-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
447+
@available(System 0.0.1, *)
448448
extension FileDescriptor.OpenOptions
449449
: CustomStringConvertible, CustomDebugStringConvertible
450450
{

Sources/System/FileHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
10+
@available(System 0.0.1, *)
1111
extension FileDescriptor {
1212
/// Runs a closure and then closes the file descriptor, even if an error occurs.
1313
///

Sources/System/FileOperations.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
10+
@available(System 0.0.1, *)
1111
extension FileDescriptor {
1212
/// Opens or creates a file for reading or writing.
1313
///
@@ -368,7 +368,7 @@ extension FileDescriptor {
368368
}
369369

370370
#if !os(WASI)
371-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
371+
@available(System 0.0.2, *)
372372
extension FileDescriptor {
373373
/// Duplicates this file descriptor and return the newly created copy.
374374
///
@@ -398,15 +398,15 @@ extension FileDescriptor {
398398
///
399399
/// The corresponding C functions are `dup` and `dup2`.
400400
@_alwaysEmitIntoClient
401-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
401+
@available(System 0.0.2, *)
402402
public func duplicate(
403403
as target: FileDescriptor? = nil,
404404
retryOnInterrupt: Bool = true
405405
) throws -> FileDescriptor {
406406
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
407407
}
408408

409-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
409+
@available(System 0.0.2, *)
410410
@usableFromInline
411411
internal func _duplicate(
412412
as target: FileDescriptor?,
@@ -435,20 +435,20 @@ extension FileDescriptor {
435435
#endif
436436

437437
#if !os(WASI)
438-
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
438+
@available(System 1.1.0, *)
439439
extension FileDescriptor {
440440
/// Creates a unidirectional data channel, which can be used for interprocess communication.
441441
///
442442
/// - Returns: The pair of file descriptors.
443443
///
444444
/// The corresponding C function is `pipe`.
445445
@_alwaysEmitIntoClient
446-
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
446+
@available(System 1.1.0, *)
447447
public static func pipe() throws -> (readEnd: FileDescriptor, writeEnd: FileDescriptor) {
448448
try _pipe().get()
449449
}
450450

451-
@available(/*System 1.1.0: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4*/iOS 8, *)
451+
@available(System 1.1.0, *)
452452
@usableFromInline
453453
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
454454
var fds: (Int32, Int32) = (-1, -1)
@@ -463,7 +463,7 @@ extension FileDescriptor {
463463
}
464464
#endif
465465

466-
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
466+
@available(System 1.2.0, *)
467467
extension FileDescriptor {
468468
/// Truncates or extends the file referenced by this file descriptor.
469469
///
@@ -485,7 +485,7 @@ extension FileDescriptor {
485485
/// associated with the file.
486486
///
487487
/// The corresponding C function is `ftruncate`.
488-
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
488+
@available(System 1.2.0, *)
489489
@_alwaysEmitIntoClient
490490
public func resize(
491491
to newSize: Int64,
@@ -497,7 +497,7 @@ extension FileDescriptor {
497497
).get()
498498
}
499499

500-
@available(/*System 1.2.0: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999*/iOS 8, *)
500+
@available(System 1.2.0, *)
501501
@usableFromInline
502502
internal func _resize(
503503
to newSize: Int64,

Sources/System/FilePath/FilePath.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/// However, the rules for path equivalence
3838
/// are file-system–specific and have additional considerations
3939
/// like case insensitivity, Unicode normalization, and symbolic links.
40-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
40+
@available(System 0.0.1, *)
4141
public struct FilePath: Sendable {
4242
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
4343
// components, etc.
@@ -59,16 +59,16 @@ public struct FilePath: Sendable {
5959
}
6060
}
6161

62-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
62+
@available(System 0.0.1, *)
6363
extension FilePath {
6464
/// The length of the file path, excluding the null terminator.
6565
public var length: Int { _storage.length }
6666
}
6767

68-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
68+
@available(System 0.0.1, *)
6969
extension FilePath: Hashable {}
7070

71-
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
71+
@available(System 0.0.1, *)
7272
extension FilePath: Codable {
7373
// Encoder is synthesized; it probably should have been explicit and used
7474
// a single-value container, but making that change now is somewhat risky.

Sources/System/FilePath/FilePathComponentView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// MARK: - API
1111

12-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
12+
@available(System 0.0.2, *)
1313
extension FilePath {
1414
/// A bidirectional, range replaceable collection of the non-root components
1515
/// that make up a file path.
@@ -28,7 +28,7 @@ extension FilePath {
2828
///
2929
/// path.components.removeAll { $0.kind == .currentDirectory }
3030
/// // path is "/home/username/bin/scripts/tree"
31-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
31+
@available(System 0.0.2, *)
3232
public struct ComponentView: Sendable {
3333
internal var _path: FilePath
3434
internal var _start: SystemString.Index
@@ -64,11 +64,11 @@ extension FilePath {
6464
}
6565
}
6666

67-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
67+
@available(System 0.0.2, *)
6868
extension FilePath.ComponentView: BidirectionalCollection {
6969
public typealias Element = FilePath.Component
7070

71-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
71+
@available(System 0.0.2, *)
7272
public struct Index: Sendable, Comparable, Hashable {
7373
internal typealias Storage = SystemString.Index
7474

@@ -100,7 +100,7 @@ extension FilePath.ComponentView: BidirectionalCollection {
100100
}
101101
}
102102

103-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
103+
@available(System 0.0.2, *)
104104
extension FilePath.ComponentView: RangeReplaceableCollection {
105105
public init() {
106106
self.init(FilePath())
@@ -150,7 +150,7 @@ extension FilePath.ComponentView: RangeReplaceableCollection {
150150
}
151151
}
152152

153-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
153+
@available(System 0.0.2, *)
154154
extension FilePath {
155155
/// Create a file path from a root and a collection of components.
156156
public init<C: Collection>(
@@ -179,7 +179,7 @@ extension FilePath {
179179

180180
// MARK: - Internals
181181

182-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
182+
@available(System 0.0.2, *)
183183
extension FilePath.ComponentView: _PathSlice {
184184
internal var _range: Range<SystemString.Index> {
185185
_start ..< _path._storage.endIndex
@@ -192,7 +192,7 @@ extension FilePath.ComponentView: _PathSlice {
192192

193193
// MARK: - Invariants
194194

195-
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
195+
@available(System 0.0.2, *)
196196
extension FilePath.ComponentView {
197197
internal func _invariantCheck() {
198198
#if DEBUG

0 commit comments

Comments
 (0)