Skip to content

Commit 360412e

Browse files
committed
Get rid of the SystemPackage dependency
1 parent 5d36391 commit 360412e

File tree

14 files changed

+155
-46
lines changed

14 files changed

+155
-46
lines changed

Package.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Foundation
55

66

77
/* ⚠️ Do not use the concurrency check flags in a release! */
8-
let noSwiftSettings: [SwiftSetting] = []
8+
let noSwiftSettings: [SwiftSetting] = []
99
//let concurrencySwiftSettings: [SwiftSetting] = [.unsafeFlags(["-Xfrontend", "-warn-concurrency", "-Xfrontend", "-enable-actor-data-race-checks"])]
1010

1111

@@ -40,9 +40,6 @@ let package = Package(
4040
res.append(.package(url: "https://github.com/xcode-actions/clt-logger.git", from: "1.0.0-beta.4"))
4141
res.append(.package(url: "https://github.com/xcode-actions/stream-reader.git", from: "3.6.0"))
4242
res.append(.package(url: "https://github.com/xcode-actions/swift-signal-handling.git", .upToNextMinor(from: "1.1.2")))
43-
#if !canImport(System)
44-
res.append(.package(url: "https://github.com/apple/swift-system.git", from: "1.0.0"))
45-
#endif
4643
if useXtenderZ {
4744
res.append(.package(url: "https://github.com/Frizlab/eXtenderZ.git", from: "2.0.0"))
4845
}
@@ -57,9 +54,6 @@ let package = Package(
5754
res.append(.product(name: "SignalHandling", package: "swift-signal-handling"))
5855
res.append(.product(name: "StreamReader", package: "stream-reader"))
5956
res.append(.product(name: "UnwrapOrThrow", package: "UnwrapOrThrow"))
60-
#if !canImport(System)
61-
res.append(.product(name: "SystemPackage", package: "swift-system"))
62-
#endif
6357
res.append(.target(name: "CMacroExports"))
6458
if useXtenderZ {
6559
res.append(.product(name: "eXtenderZ-static", package: "eXtenderZ"))
@@ -78,9 +72,7 @@ let package = Package(
7872
res.append(.product(name: "ArgumentParser", package: "swift-argument-parser"))
7973
res.append(.product(name: "CLTLogger", package: "clt-logger"))
8074
res.append(.product(name: "Logging", package: "swift-log"))
81-
#if !canImport(System)
82-
res.append(.product(name: "SystemPackage", package: "swift-system"))
83-
#endif
75+
res.append(.product(name: "StreamReader", package: "stream-reader"))
8476
res.append(.target(name: "CMacroExports"))
8577
if needsGNUSourceExports {
8678
res.append(.target(name: "CGNUSourceExports"))
@@ -94,9 +86,6 @@ let package = Package(
9486
res.append(.product(name: "CLTLogger", package: "clt-logger"))
9587
res.append(.product(name: "Logging", package: "swift-log"))
9688
res.append(.product(name: "StreamReader", package: "stream-reader"))
97-
#if !canImport(System)
98-
res.append(.product(name: "SystemPackage", package: "swift-system"))
99-
#endif
10089
if needsGNUSourceExports {
10190
res.append(.target(name: "CGNUSourceExportsForTests"))
10291
}

Sources/ManualTests/main.swift

Lines changed: 9 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 CLTLogger
@@ -37,8 +37,14 @@ let logger = Logger(label: "com.xcode-actions.manual-process-invocation-tests")
3737
//}
3838

3939
do {
40+
#if canImport(SystemPackage) || canImport(System)
4041
let fd = try! FileDescriptor.open("/dev/null", .readOnly)
4142
defer {_ = try? fd.close()}
43+
#else
44+
let fh = FileHandle(forReadingAtPath: "/dev/null")!
45+
let fd = FileDescriptor(rawValue: fh.fileDescriptor)
46+
defer {_ = try? fh.close()}
47+
#endif
4248

4349
/*let p = Process()
4450
p.executableURL = URL(fileURLWithPath: "./toto")

Sources/ProcessInvocation/ Errors.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/ProcessInvocation/InputRedirectMode.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 StreamReader

Sources/ProcessInvocation/LineWithSource.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 UnwrapOrThrow
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#if !canImport(SystemPackage) && !canImport(System)
2+
import Foundation
3+
4+
import StreamReader
5+
6+
7+
public struct FileDescriptor : RawRepresentable, Hashable, Codable {
8+
public enum OpenMode {
9+
case readOnly
10+
}
11+
public static var standardInput: FileDescriptor {.init(rawValue: FileHandle.standardInput.fileDescriptor)}
12+
public static var standardOutput: FileDescriptor {.init(rawValue: FileHandle.standardOutput.fileDescriptor)}
13+
public static var standardError: FileDescriptor {.init(rawValue: FileHandle.standardError.fileDescriptor)}
14+
public static func open(_ path: String, _ mode: OpenMode) -> FileDescriptor {
15+
let fh = FileHandle(forReadingAtPath: path)!
16+
return .init(rawValue: fh.fileDescriptor, fh: fh)
17+
}
18+
public let rawValue: CInt
19+
public init(rawValue: CInt) {
20+
self.rawValue = rawValue
21+
self.fh = nil
22+
}
23+
public func close() throws {
24+
try fh?.close() ?? {
25+
let ret = globalClose(rawValue)
26+
guard ret == 0 else {throw Errno(rawValue: errno)}
27+
}()
28+
}
29+
public func closeAfter<R>(_ body: () throws -> R) throws -> R {
30+
let r: R
31+
do {r = try body()}
32+
catch {try? close(); throw error}
33+
try close()
34+
return r
35+
}
36+
/* We do not implement retryOnInterrupt.
37+
* I guess FileHandle does it, but it’s far from certain… */
38+
public func read(into buffer: UnsafeMutableRawBufferPointer, retryOnInterrupt: Bool = true) throws -> Int {
39+
try FileHandle(fileDescriptor: rawValue).read(buffer.baseAddress!, maxLength: buffer.count)
40+
}
41+
private init(rawValue: CInt, fh: FileHandle) {
42+
self.rawValue = rawValue
43+
self.fh = fh
44+
}
45+
private let fh: FileHandle?
46+
}
47+
/* To avoid the shadowing of close in the dummy FileDescriptor implementation. */
48+
private func globalClose(_ fd: Int32) -> Int32 {close(fd)}
49+
50+
public struct Errno : RawRepresentable, Error, Hashable, Codable {
51+
public let rawValue: CInt
52+
public init(rawValue: CInt) {
53+
self.rawValue = rawValue
54+
}
55+
}
56+
57+
#endif

Sources/ProcessInvocation/OutputRedirectMode.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/ProcessInvocation/ProcessInvocation+Deprecated.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 SignalHandling

Sources/ProcessInvocation/ProcessInvocation+Pipe.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 StreamReader

Sources/ProcessInvocation/ProcessInvocation.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
#if canImport(eXtenderZ)

0 commit comments

Comments
 (0)