Skip to content

Commit 62eadfe

Browse files
committed
Remove SystemPackage as an explicit dependency
If the package is available (e.g. other dependant on parent project), we’ll use it, otherwise we’ll use a dummy Errno implementation to have things compile.
1 parent d5ca63f commit 62eadfe

File tree

8 files changed

+40
-54
lines changed

8 files changed

+40
-54
lines changed

Package.swift

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,31 @@ let package = Package(
1212
.macOS(.v11),
1313
.tvOS(.v14),
1414
.iOS(.v14),
15-
.watchOS(.v7)
15+
.watchOS(.v7),
1616
],
1717
products: [
1818
.library(name: "SignalHandling", targets: ["SignalHandling"])
1919
],
20-
dependencies: {
21-
var res = [Package.Dependency]()
22-
res.append(.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"))
23-
res.append(.package(url: "https://github.com/apple/swift-log.git", from: "1.4.2"))
24-
res.append(.package(url: "https://github.com/xcode-actions/clt-logger.git", from: "0.4.0"))
25-
#if !canImport(System)
26-
res.append(.package(url: "https://github.com/apple/swift-system.git", from: "1.0.0"))
27-
#endif
28-
return res
29-
}(),
20+
dependencies: [
21+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"),
22+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.2"),
23+
.package(url: "https://github.com/xcode-actions/clt-logger.git", from: "0.4.0"),
24+
],
3025
targets: [
31-
.target(name: "SignalHandling", dependencies: {
32-
var res = [Target.Dependency]()
33-
res.append(.product(name: "Logging", package: "swift-log"))
34-
#if !canImport(System)
35-
res.append(.product(name: "SystemPackage", package: "swift-system"))
36-
#endif
37-
return res
38-
}(), swiftSettings: noSwiftSettings),
26+
.target(name: "SignalHandling", dependencies: [
27+
.product(name: "Logging", package: "swift-log"),
28+
], swiftSettings: noSwiftSettings),
3929

4030
.target(name: "signal-handling-tests-helper", dependencies: [
4131
.product(name: "ArgumentParser", package: "swift-argument-parser"),
4232
.product(name: "CLTLogger", package: "clt-logger"),
4333
.product(name: "Logging", package: "swift-log"),
44-
.target(name: "SignalHandling")
34+
.target(name: "SignalHandling"),
4535
], swiftSettings: noSwiftSettings),
46-
.testTarget(name: "SignalHandlingTests", dependencies: {
47-
var res = [Target.Dependency]()
48-
res.append(.target(name: "signal-handling-tests-helper"))
49-
res.append(.product(name: "CLTLogger", package: "clt-logger"))
50-
res.append(.product(name: "Logging", package: "swift-log"))
51-
#if !canImport(System)
52-
res.append(.product(name: "SystemPackage", package: "swift-system"))
53-
#endif
54-
return res
55-
}(), swiftSettings: noSwiftSettings)
36+
.testTarget(name: "SignalHandlingTests", dependencies: [
37+
.target(name: "signal-handling-tests-helper"),
38+
.product(name: "CLTLogger", package: "clt-logger"),
39+
.product(name: "Logging", package: "swift-log"),
40+
], swiftSettings: noSwiftSettings)
5641
]
5742
)

Sources/SignalHandling/CStructsInSwift/Sigaction.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
2-
#if canImport(System)
3-
import System
4-
#else
2+
#if canImport(SystemPackage)
53
import SystemPackage
4+
#elseif canImport(System)
5+
import System
66
#endif
77

88

Sources/SignalHandling/DelayedSigaction/SigactionDelayer_Block.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
2-
#if canImport(System)
3-
import System
4-
#else
2+
#if canImport(SystemPackage)
53
import SystemPackage
4+
#elseif canImport(System)
5+
import System
66
#endif
77

88

Sources/SignalHandling/DelayedSigaction/SigactionDelayer_Unsig.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
2-
#if canImport(System)
3-
import System
4-
#else
2+
#if canImport(SystemPackage)
53
import SystemPackage
4+
#elseif canImport(System)
5+
import System
66
#endif
77

88
import Logging
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#if !canImport(SystemPackage) && !canImport(System)
2+
import Foundation
3+
4+
public struct Errno : RawRepresentable, Error, Hashable, Codable {
5+
public let rawValue: CInt
6+
public init(rawValue: CInt) {
7+
self.rawValue = rawValue
8+
}
9+
}
10+
11+
#endif

Sources/SignalHandling/SignalHandlingError.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
2-
#if canImport(System)
3-
import System
4-
#else
2+
#if canImport(SystemPackage)
53
import SystemPackage
4+
#elseif canImport(System)
5+
import System
66
#endif
77

88

Sources/signal-handling-tests-helper/DelaySignalBlock.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import Foundation
2-
#if canImport(System)
3-
import System
4-
#else
5-
import SystemPackage
6-
#endif
72

83
import ArgumentParser
94
import CLTLogger
@@ -42,5 +37,5 @@ struct DelaySignalBlock : ParsableCommand {
4237

4338
/* Using print does not work in Terminal probably due to buffering. */
4439
private func writeToStdout(_ str: String) {
45-
try! FileDescriptor.standardOutput.writeAll(Data((str + "\n").utf8))
40+
try! FileHandle.standardOutput.write(contentsOf: Data((str + "\n").utf8))
4641
}

Sources/signal-handling-tests-helper/DelaySignalUnsigaction.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import Foundation
2-
#if canImport(System)
3-
import System
4-
#else
5-
import SystemPackage
6-
#endif
72

83
import ArgumentParser
94
import CLTLogger
@@ -40,5 +35,5 @@ struct DelaySignalUnsigaction : ParsableCommand {
4035

4136
/* Using print does not work in Terminal probably due to buffering. */
4237
private func writeToStdout(_ str: String) {
43-
try! FileDescriptor.standardOutput.writeAll(Data((str + "\n").utf8))
38+
try! FileHandle.standardOutput.write(contentsOf: Data((str + "\n").utf8))
4439
}

0 commit comments

Comments
 (0)