Skip to content

Commit 883081c

Browse files
committed
Use canImport(Darwin) instead of !os(Linux)
1 parent 72fd6ce commit 883081c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let noSwiftSettings: [SwiftSetting] = []
1414
* See Process+Utils for reason why we use the eXtenderZ. */
1515
let useXtenderZ = (NSStringFromClass(Process().classForCoder) != "NSTask")
1616
/* Do we need the _GNU_SOURCE exports? This allows using execvpe on Linux. */
17-
#if !os(Linux)
17+
#if canImport(Darwin)
1818
let needsGNUSourceExports = false
1919
#else
2020
let needsGNUSourceExports = true

Sources/ProcessInvocation/ProcessInvocation.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import eXtenderZ
1212
import SignalHandling
1313
import StreamReader
1414

15-
#if os(Linux)
15+
#if !canImport(Darwin)
1616
import CGNUSourceExports
1717
#endif
1818
import CMacroExports
@@ -494,13 +494,13 @@ public struct ProcessInvocation : AsyncSequence {
494494
p.standardError = FileHandle(fileDescriptor: fdForWriting.rawValue, closeOnDealloc: false)
495495
}
496496

497-
#if !os(Linux)
497+
#if canImport(Darwin)
498498
let platformSpecificInfo: Void = ()
499499
#else
500500
var platformSpecificInfo = StreamReadPlatformSpecificInfo()
501501
#endif
502502

503-
#if os(Linux)
503+
#if !canImport(Darwin)
504504
for fd in outputFileDescriptors {
505505
/* Let’s see if the fd is a master pt or not.
506506
* This is needed to detect EOF properly and not throw an error when reading from a master pt (see handleProcessOutput for more info). */
@@ -603,7 +603,7 @@ public struct ProcessInvocation : AsyncSequence {
603603
let sv = UnsafeMutablePointer<CInt>.allocate(capacity: 2)
604604
sv.initialize(repeating: -1, count: 2)
605605
defer {sv.deallocate()}
606-
#if !os(Linux)
606+
#if canImport(Darwin)
607607
let sockDgram = SOCK_DGRAM
608608
#else
609609
let sockDgram = Int32(SOCK_DGRAM.rawValue)
@@ -838,7 +838,7 @@ public struct ProcessInvocation : AsyncSequence {
838838
  MARK: - Private
839839
  *************** */
840840

841-
#if !os(Linux)
841+
#if canImport(Darwin)
842842
private typealias StreamReadPlatformSpecificInfo = Void
843843
#else
844844
private struct StreamReadPlatformSpecificInfo {
@@ -905,7 +905,7 @@ public struct ProcessInvocation : AsyncSequence {
905905
) {
906906
do {
907907
let toRead = Int(Swift.min(Swift.max(estimatedBytesAvailable, 1), UInt(Int.max)))
908-
#if !os(Linux)
908+
#if canImport(Darwin)
909909
/* We do not need to check the number of bytes actually read.
910910
* If EOF was reached (nothing was read),
911911
* the stream reader will remember it, and
@@ -1008,7 +1008,7 @@ public struct ProcessInvocation : AsyncSequence {
10081008
let buf = UnsafeMutableRawPointer.allocate(byteCount: SPI_CMSG_SPACE(sizeOfFd), alignment: MemoryLayout<cmsghdr>.alignment)
10091009
defer {buf.deallocate()}
10101010

1011-
#if !os(Linux)
1011+
#if canImport(Darwin)
10121012
msg.msg_control = UnsafeMutableRawPointer(buf)
10131013
msg.msg_controllen = socklen_t(SPI_CMSG_SPACE(sizeOfFd))
10141014
#else
@@ -1020,15 +1020,15 @@ public struct ProcessInvocation : AsyncSequence {
10201020
throw Err.internalError("CMSG_FIRSTHDR returned nil.")
10211021
}
10221022

1023-
#if !os(Linux)
1023+
#if canImport(Darwin)
10241024
cmsg.pointee.cmsg_type = SCM_RIGHTS
10251025
cmsg.pointee.cmsg_level = SOL_SOCKET
10261026
#else
10271027
cmsg.pointee.cmsg_type = Int32(SCM_RIGHTS)
10281028
cmsg.pointee.cmsg_level = SOL_SOCKET
10291029
#endif
10301030

1031-
#if !os(Linux)
1031+
#if canImport(Darwin)
10321032
cmsg.pointee.cmsg_len = socklen_t(SPI_CMSG_LEN(sizeOfFd))
10331033
#else
10341034
cmsg.pointee.cmsg_len = Int(SPI_CMSG_LEN(sizeOfFd))

Sources/ProcessInvocationBridge/ProcessInvocationBridge.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CLTLogger
1010
import CMacroExports
1111
import Logging
1212

13-
#if os(Linux)
13+
#if !canImport(Darwin)
1414
import CGNUSourceExports
1515
#endif
1616

@@ -136,7 +136,7 @@ struct ProcessInvocationBridge : ParsableCommand {
136136
Self.logger.trace("exec’ing.", metadata: ["executable": "\(toolName)"])
137137
let ret: Int32
138138
if usePath {
139-
#if !os(Linux)
139+
#if canImport(Darwin)
140140
/* The P implementation of exec searches for the binary path in the given search path.
141141
* The v means we pass an array to exec (as opposed to the variadic exec variant, which is not available in Swift anyway). */
142142
ret = execvP(toolName, path ?? _PATH_DEFPATH, cargs)
@@ -214,7 +214,7 @@ struct ProcessInvocationBridge : ParsableCommand {
214214
defer {controlBuf.deallocate()}
215215
controlBuf.update(repeating: 0, count: controlBufSize)
216216
msg.msg_control = UnsafeMutableRawPointer(controlBuf)
217-
#if !os(Linux)
217+
#if canImport(Darwin)
218218
msg.msg_controllen = socklen_t(controlBufSize)
219219
#else
220220
msg.msg_controllen = Int(controlBufSize)

Tests/ProcessInvocationTests/ProcessInvocationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ final class ProcessInvocationTests : XCTestCase {
302302
await tempAsyncAssertThrowsError(try await ProcessInvocation(spyScriptPath, usePATH: true, customPATH: [Self.filesPath], signalsToProcess: []).invokeAndGetRawOutput())
303303
await tempAsyncAssertNoThrow(try await ProcessInvocation(spyScriptPath, usePATH: true, customPATH: [Self.scriptsPath], signalsToProcess: []).invokeAndGetRawOutput())
304304
await tempAsyncAssertNoThrow(try await ProcessInvocation(spyScriptPath, usePATH: true, customPATH: [Self.scriptsPath, Self.filesPath], signalsToProcess: []).invokeAndGetRawOutput())
305-
#if os(Linux)
305+
#if !canImport(Darwin)
306306
/* On Linux, the error when trying to execute a non-executable file is correct (no permission), and so we don’t try next path available. */
307307
await tempAsyncAssertThrowsError(try await ProcessInvocation(spyScriptPath, usePATH: true, customPATH: [Self.filesPath, Self.scriptsPath], signalsToProcess: []).invokeAndGetRawOutput())
308308
#else

0 commit comments

Comments
 (0)