Skip to content

Commit 99b0b06

Browse files
committed
Clean up some Darwin platform conditions
We should prefer not to list out Darwin-derived platforms, and remove some old conditional code for versions we no longer support.
1 parent 57ce13a commit 99b0b06

File tree

5 files changed

+8
-70
lines changed

5 files changed

+8
-70
lines changed

Sources/Basics/Cancellator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public final class Cancellator: Cancellable, Sendable {
128128
self.register(name: "\(process.arguments.joined(separator: " "))", handler: process.terminate)
129129
}
130130

131-
#if !os(iOS) && !os(watchOS) && !os(tvOS)
131+
#if !canImport(Darwin) || os(macOS)
132132
public func register(_ process: Foundation.Process) -> RegistrationKey? {
133133
self.register(name: "\(process.description)", handler: process.terminate(timeout:))
134134
}
@@ -245,7 +245,7 @@ extension AsyncProcess {
245245
}
246246
}
247247

248-
#if !os(iOS) && !os(watchOS) && !os(tvOS)
248+
#if !canImport(Darwin) || os(macOS)
249249
extension Foundation.Process {
250250
fileprivate func terminate(timeout: DispatchTime) {
251251
guard self.isRunning else {

Sources/Basics/DispatchTimeInterval+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension DispatchTimeInterval {
8686
return String(format: "%.2f", Double(value) / Double(1_000_000_000)) + "s"
8787
case .never:
8888
return "n/a"
89-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
89+
#if canImport(Darwin)
9090
@unknown default:
9191
return "n/a"
9292
#endif

Sources/Basics/JSON+Extensions.swift

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,8 @@ import class Foundation.DateFormatter
1515
import class Foundation.JSONDecoder
1616
import class Foundation.JSONEncoder
1717

18-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
19-
extension DateFormatter {
20-
public static let iso8601: DateFormatter = {
21-
let dateFormatter = DateFormatter()
22-
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
23-
return dateFormatter
24-
}()
25-
}
26-
27-
extension JSONEncoder.DateEncodingStrategy {
28-
public static let customISO8601 = custom {
29-
var container = $1.singleValueContainer()
30-
try container.encode(DateFormatter.iso8601.string(from: $0))
31-
}
32-
}
33-
34-
extension JSONDecoder.DateDecodingStrategy {
35-
public static let customISO8601 = custom {
36-
let container = try $0.singleValueContainer()
37-
let string = try container.decode(String.self)
38-
if let date = DateFormatter.iso8601.date(from: string) {
39-
return date
40-
}
41-
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date: \(string)")
42-
}
43-
}
44-
#endif
45-
46-
extension JSONEncoder.DateEncodingStrategy {
47-
public static var safeISO8601: JSONEncoder.DateEncodingStrategy {
48-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
49-
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
50-
return .iso8601
51-
} else {
52-
return .customISO8601
53-
}
54-
#else
55-
return .iso8601
56-
#endif
57-
}
58-
}
59-
60-
extension JSONDecoder.DateDecodingStrategy {
61-
public static var safeISO8601: JSONDecoder.DateDecodingStrategy {
62-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
63-
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
64-
return .iso8601
65-
} else {
66-
return .customISO8601
67-
}
68-
#else
69-
return .iso8601
70-
#endif
71-
}
72-
}
73-
7418
extension JSONDecoder {
75-
public static func makeWithDefaults(dateDecodingStrategy: DateDecodingStrategy = .safeISO8601) -> JSONDecoder {
19+
public static func makeWithDefaults(dateDecodingStrategy: DateDecodingStrategy = .iso8601) -> JSONDecoder {
7620
let decoder = JSONDecoder()
7721
decoder.dateDecodingStrategy = dateDecodingStrategy
7822
return decoder
@@ -82,7 +26,7 @@ extension JSONDecoder {
8226
extension JSONEncoder {
8327
public static func makeWithDefaults(
8428
prettified: Bool = true,
85-
dateEncodingStrategy: DateEncodingStrategy = .safeISO8601
29+
dateEncodingStrategy: DateEncodingStrategy = .iso8601
8630
) -> JSONEncoder {
8731
Self.makeWithDefaults(
8832
sortKeys: prettified,
@@ -96,19 +40,13 @@ extension JSONEncoder {
9640
sortKeys: Bool,
9741
prettyPrint: Bool,
9842
escapeSlashes: Bool,
99-
dateEncodingStrategy: DateEncodingStrategy = .safeISO8601
43+
dateEncodingStrategy: DateEncodingStrategy = .iso8601
10044
) -> JSONEncoder {
10145
let encoder = JSONEncoder()
10246
var outputFormatting: JSONEncoder.OutputFormatting = []
10347

10448
if sortKeys {
105-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
106-
if #available(macOS 10.15, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
107-
outputFormatting.insert(.sortedKeys)
108-
}
109-
#else
11049
outputFormatting.insert(.sortedKeys)
111-
#endif
11250
}
11351
if prettyPrint {
11452
outputFormatting.insert(.prettyPrinted)

Sources/SPMBuildCore/Plugins/DefaultPluginScriptRunner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
433433
delegate: PluginScriptRunnerDelegate,
434434
completion: @escaping (Result<Int32, Error>) -> Void
435435
) {
436-
#if os(iOS) || os(watchOS) || os(tvOS)
436+
#if canImport(Darwin) && !os(macOS)
437437
callbackQueue.async {
438438
completion(.failure(DefaultPluginScriptRunnerError.pluginUnavailable(reason: "subprocess invocations are unavailable on this platform")))
439439
}

Sources/_InternalTestSupport/MockBuildTestHelper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import XCTest
2323
public struct MockToolchain: PackageModel.Toolchain {
2424
#if os(Windows)
2525
public let librarianPath = AbsolutePath("/fake/path/to/link.exe")
26-
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
26+
#elseif canImport(Darwin)
2727
public let librarianPath = AbsolutePath("/fake/path/to/libtool")
2828
#else
2929
public let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")

0 commit comments

Comments
 (0)