Skip to content

Commit 1907218

Browse files
committed
Add more missing availability annotations and clean up ifdefs
1 parent 866b28a commit 1907218

19 files changed

+41
-39
lines changed

Sources/TSCBasic/HashAlgorithms.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public struct SHA256: HashAlgorithm {
174174
}
175175

176176
/// Wraps CryptoKit.SHA256 to provide a HashAlgorithm conformance to it.
177-
@available(macOS 10.15, iOS 13, *)
177+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
178178
public struct CryptoKitSHA256: HashAlgorithm {
179179
public init() {
180180
}

Sources/TSCBasic/Process.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public final class Process {
465465

466466
try _process?.run()
467467
return stdinPipe.fileHandleForWriting
468-
#else
468+
#elseif (!canImport(Darwin) || os(macOS))
469469
// Initialize the spawn attributes.
470470
#if canImport(Darwin) || os(Android) || os(OpenBSD)
471471
var attributes: posix_spawnattr_t? = nil
@@ -481,7 +481,7 @@ public final class Process {
481481
posix_spawnattr_setsigmask(&attributes, &noSignals)
482482

483483
// Reset all signals to default behavior.
484-
#if os(macOS)
484+
#if canImport(Darwin)
485485
var mostSignals = sigset_t()
486486
sigfillset(&mostSignals)
487487
sigdelset(&mostSignals, SIGKILL)
@@ -521,7 +521,7 @@ public final class Process {
521521
defer { posix_spawn_file_actions_destroy(&fileActions) }
522522

523523
if let workingDirectory = workingDirectory?.pathString {
524-
#if os(macOS)
524+
#if canImport(Darwin)
525525
// The only way to set a workingDirectory is using an availability-gated initializer, so we don't need
526526
// to handle the case where the posix_spawn_file_actions_addchdir_np method is unavailable. This check only
527527
// exists here to make the compiler happy.
@@ -669,6 +669,8 @@ public final class Process {
669669
}
670670

671671
return stdinStream
672+
#else
673+
preconditionFailure("Process spawning is not available")
672674
#endif // POSIX implementation
673675
}
674676

@@ -849,7 +851,7 @@ extension Process: Hashable {
849851
// MARK: - Private helpers
850852

851853
#if !os(Windows)
852-
#if os(macOS)
854+
#if canImport(Darwin)
853855
private typealias swiftpm_posix_spawn_file_actions_t = posix_spawn_file_actions_t?
854856
#else
855857
private typealias swiftpm_posix_spawn_file_actions_t = posix_spawn_file_actions_t

Sources/TSCBasic/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public func exec(path: String, args: [String]) throws -> Never {
3333
else {
3434
throw SystemError.exec(errno, path: path, args: args)
3535
}
36-
#else
36+
#elseif (!canImport(Darwin) || os(macOS))
3737
guard execv(path, cArgs.cArray) != -1 else {
3838
throw SystemError.exec(errno, path: path, args: args)
3939
}

Sources/TSCTestSupport/FileSystemExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import func XCTest.XCTFail
1313
import TSCBasic
1414
import TSCUtility
1515

16-
#if os(macOS)
16+
#if canImport(Darwin)
1717
import class Foundation.Bundle
1818
#endif
1919

Sources/TSCTestSupport/Product.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import class Foundation.ProcessInfo
1414
import TSCBasic
1515
import TSCUtility
1616

17-
#if os(macOS)
17+
#if canImport(Darwin)
1818
import class Foundation.Bundle
1919
#endif
2020

@@ -33,7 +33,7 @@ public protocol Product {
3333
extension Product {
3434
/// Path to currently built binary.
3535
public var path: AbsolutePath {
36-
#if os(macOS)
36+
#if canImport(Darwin)
3737
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
3838
return AbsolutePath(bundle.bundlePath).parentDirectory.appending(self.exec)
3939
}

Sources/TSCTestSupport/XCTAssertHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import XCTest
1313
import TSCBasic
1414
import TSCUtility
1515

16-
#if os(macOS)
16+
#if canImport(Darwin)
1717
import class Foundation.Bundle
1818
#endif
1919

Sources/TSCTestSupport/XCTestCasePerf.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import TSCBasic
1818
/// This is useful because we always want to be able to compile the perf tests
1919
/// even if they are not run locally.
2020
open class XCTestCasePerf: XCTestCase {
21-
#if os(macOS)
21+
#if canImport(Darwin)
2222
override open class var defaultTestSuite: XCTestSuite {
2323
if ProcessEnv.vars.keys.contains("TSC_ENABLE_PERF_TESTS") {
2424
return super.defaultTestSuite

Sources/TSCTestSupport/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import class Foundation.Thread
1515
import TSCBasic
1616
import TSCUtility
1717

18-
#if os(macOS)
18+
#if canImport(Darwin)
1919
import class Foundation.Bundle
2020
#endif
2121

Sources/TSCUtility/FSWatch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private protocol _FileWatcher {
100100
func stop()
101101
}
102102

103-
#if os(OpenBSD) || os(iOS)
103+
#if os(OpenBSD) || (!os(macOS) && canImport(Darwin))
104104
extension FSWatch._WatcherDelegate: NoOpWatcherDelegate {}
105105
extension NoOpWatcher: _FileWatcher{}
106106
#elseif os(Windows)
@@ -118,7 +118,7 @@ extension FSEventStream: _FileWatcher{}
118118

119119
// MARK:- inotify
120120

121-
#if os(OpenBSD) || os(iOS)
121+
#if os(OpenBSD) || (!os(macOS) && canImport(Darwin))
122122

123123
public protocol NoOpWatcherDelegate {
124124
func pathsDidReceiveEvent(_ paths: [AbsolutePath])

Sources/TSCUtility/Platform.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public enum Platform: Equatable {
8585
// Compute the directories.
8686
directories.append(AbsolutePath("/private/var/tmp"))
8787
(try? TSCBasic.determineTempDirectory()).map{ directories.append($0) }
88-
#if os(macOS)
88+
#if canImport(Darwin)
8989
getConfstr(_CS_DARWIN_USER_TEMP_DIR).map({ directories.append($0) })
9090
getConfstr(_CS_DARWIN_USER_CACHE_DIR).map({ directories.append($0) })
9191
#endif
@@ -95,7 +95,7 @@ public enum Platform: Equatable {
9595
}
9696

9797

98-
#if os(macOS)
98+
#if canImport(Darwin)
9999
/// Returns the value of given path variable using `getconf` utility.
100100
///
101101
/// - Note: This method returns `nil` if the value is an invalid path.

Sources/TSCUtility/dlopen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct DLOpenFlags: RawRepresentable, OptionSet {
5757
public static let global: DLOpenFlags = DLOpenFlags(rawValue: RTLD_GLOBAL)
5858

5959
// Platform-specific flags.
60-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
60+
#if canImport(Darwin)
6161
public static let first: DLOpenFlags = DLOpenFlags(rawValue: RTLD_FIRST)
6262
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0)
6363
#else

Tests/TSCBasicPerformanceTests/ByteStringPerfTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TSCTestSupport
1515

1616
class ByteStringPerfTests: XCTestCasePerf {
1717
func testInitialization() {
18-
#if os(macOS)
18+
#if canImport(Darwin)
1919
let listOfStrings: [String] = (0..<10).map { "This is the number: \($0)!\n" }
2020
let expectedTotalCount = listOfStrings.map({ $0.utf8.count }).reduce(0, +)
2121
measure {

Tests/TSCBasicPerformanceTests/PathPerfTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PathPerfTests: XCTestCasePerf {
1717

1818
/// Tests creating very long AbsolutePaths by joining path components.
1919
func testJoinPerf_X100000() {
20-
#if os(macOS)
20+
#if canImport(Darwin)
2121
let absPath = AbsolutePath("/hello/little")
2222
let relPath = RelativePath("world")
2323
let N = 100000

Tests/TSCBasicPerformanceTests/SHA256PerfTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TSCTestSupport
1515

1616
class SHA256PerfTests: XCTestCasePerf {
1717
func test20MBDigest_X1000() {
18-
#if os(macOS)
18+
#if canImport(Darwin)
1919
let sha256 = SHA256()
2020
let byte = "f"
2121
let stream = BufferedOutputByteStream()

Tests/TSCBasicPerformanceTests/SortedArrayPerfTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import TSCTestSupport
1313

1414
class SortedArrayPerfTests: XCTestCasePerf {
1515
func testPerformanceOfSortedArrayInAscendingOrder() {
16-
#if os(macOS)
16+
#if canImport(Darwin)
1717
measure() {
1818
var arr = SortedArray<Int>(areInIncreasingOrder: <)
1919
for i in 1...200_000 {
@@ -24,7 +24,7 @@ class SortedArrayPerfTests: XCTestCasePerf {
2424
}
2525

2626
func testPerformanceOfSortedArrayInsertWithDuplicates() {
27-
#if os(macOS)
27+
#if canImport(Darwin)
2828
let initial = SortedArray<Int>(0..<80_000, areInIncreasingOrder: <)
2929

3030
measure() {
@@ -37,7 +37,7 @@ class SortedArrayPerfTests: XCTestCasePerf {
3737
}
3838

3939
func testPerformanceOfSortedArrayInsertContentsOfWithDuplicates() {
40-
#if os(macOS)
40+
#if canImport(Darwin)
4141
let initial = SortedArray<Int>(0..<120_000, areInIncreasingOrder: <)
4242

4343
measure() {
@@ -48,7 +48,7 @@ class SortedArrayPerfTests: XCTestCasePerf {
4848
}
4949

5050
func testPerformanceOfSmallSortedArrayInsertContentsOfWithDuplicates() {
51-
#if os(macOS)
51+
#if canImport(Darwin)
5252
let initial = SortedArray<Int>(0..<100, areInIncreasingOrder: <)
5353

5454
measure() {

Tests/TSCBasicPerformanceTests/WritableByteStreamPerfTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct ByteSequenceIterator: IteratorProtocol {
4545
class OutputByteStreamPerfTests: XCTestCasePerf {
4646

4747
func test1MBOfSequence_X10() {
48-
#if os(macOS)
48+
#if canImport(Darwin)
4949
let sequence = ByteSequence()
5050
measure {
5151
for _ in 0..<10 {
@@ -60,7 +60,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
6060
}
6161

6262
func test1MBOfByte_X10() {
63-
#if os(macOS)
63+
#if canImport(Darwin)
6464
let byte = UInt8(0)
6565
measure {
6666
for _ in 0..<10 {
@@ -75,7 +75,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
7575
}
7676

7777
func test1MBOfCharacters_X1() {
78-
#if os(macOS)
78+
#if canImport(Darwin)
7979
measure {
8080
for _ in 0..<1 {
8181
let stream = BufferedOutputByteStream()
@@ -89,7 +89,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
8989
}
9090

9191
func test1MBOf16ByteArrays_X100() {
92-
#if os(macOS)
92+
#if canImport(Darwin)
9393
// Test writing 1MB worth of 16 byte strings.
9494
let bytes16 = [UInt8](repeating: 0, count: 1 << 4)
9595

@@ -107,7 +107,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
107107

108108
// This should give same performance as 16ByteArrays_X100.
109109
func test1MBOf16ByteArraySlice_X100() {
110-
#if os(macOS)
110+
#if canImport(Darwin)
111111
let bytes32 = [UInt8](repeating: 0, count: 1 << 5)
112112
// Test writing 1MB worth of 16 byte strings.
113113
let bytes16 = bytes32.suffix(from: bytes32.count/2)
@@ -125,7 +125,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
125125
}
126126

127127
func test1MBOf1KByteArrays_X1000() {
128-
#if os(macOS)
128+
#if canImport(Darwin)
129129
// Test writing 1MB worth of 1K byte strings.
130130
let bytes1k = [UInt8](repeating: 0, count: 1 << 10)
131131

@@ -142,7 +142,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
142142
}
143143

144144
func test1MBOf16ByteStrings_X10() {
145-
#if os(macOS)
145+
#if canImport(Darwin)
146146
// Test writing 1MB worth of 16 byte strings.
147147
let string16 = String(repeating: "X", count: 1 << 4)
148148

@@ -159,7 +159,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
159159
}
160160

161161
func test1MBOf1KByteStrings_X100() {
162-
#if os(macOS)
162+
#if canImport(Darwin)
163163
// Test writing 1MB worth of 1K byte strings.
164164
let bytes1k = String(repeating: "X", count: 1 << 10)
165165

@@ -176,7 +176,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
176176
}
177177

178178
func test1MBOfJSONEncoded16ByteStrings_X10() {
179-
#if os(macOS)
179+
#if canImport(Darwin)
180180
// Test writing 1MB worth of JSON encoded 16 byte strings.
181181
let string16 = String(repeating: "X", count: 1 << 4)
182182

@@ -193,7 +193,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
193193
}
194194

195195
func testFormattedJSONOutput() {
196-
#if os(macOS)
196+
#if canImport(Darwin)
197197
// Test the writing of JSON formatted output using stream operators.
198198
struct Thing {
199199
var value: String
@@ -218,7 +218,7 @@ class OutputByteStreamPerfTests: XCTestCasePerf {
218218
}
219219

220220
func testJSONToString_X100() {
221-
#if os(macOS)
221+
#if canImport(Darwin)
222222
let foo = JSON.dictionary([
223223
"foo": .string("bar"),
224224
"bar": .int(2),

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class FileSystemTests: XCTestCase {
695695
}
696696

697697
func testSetAttribute() throws {
698-
#if os(macOS) || os(Linux) || os(Android)
698+
#if canImport(Darwin) || os(Linux) || os(Android)
699699
try testWithTemporaryDirectory { tmpdir in
700700
let fs = TSCBasic.localFileSystem
701701

Tests/TSCBasicTests/RegExTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RegExTests: XCTestCase {
1515

1616
func testErrors() {
1717
// https://bugs.swift.org/browse/SR-5557
18-
#if os(macOS)
18+
#if canImport(Darwin)
1919
XCTAssertThrowsError(try RegEx(pattern: "("))
2020
#endif
2121
}

Tests/TSCBasicTests/SHA256Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class SHA256Tests: XCTestCase {
4444
XCTAssertEqual(digest, "907422e2f24d749d0add2b504ccae8ad1aa392477591905880fb2dc494e33d63")
4545
}
4646

47-
#if os(macOS)
48-
@available(macOS 10.15, *)
47+
#if canImport(Darwin)
48+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
4949
func testCryptoKitSHA256() {
5050
let sha = CryptoKitSHA256()
5151
XCTAssertEqual(

0 commit comments

Comments
 (0)