Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Sources/Subprocess/AsyncBufferSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import SystemPackage
#endif

#if !os(Windows)
internal import Dispatch

#if SubprocessFoundation

Expand Down
1 change: 0 additions & 1 deletion Sources/Subprocess/IO/AsyncIO+Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import SystemPackage

import _SubprocessCShims
import Synchronization
internal import Dispatch
@preconcurrency import WinSDK

private typealias SignalStream = AsyncThrowingStream<DWORD, any Error>
Expand Down
1 change: 0 additions & 1 deletion Sources/Subprocess/Platforms/Subprocess+Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#if canImport(Darwin)

public import Darwin
internal import Dispatch
#if canImport(System)
import System
#else
Expand Down
2 changes: 0 additions & 2 deletions Sources/Subprocess/Platforms/Subprocess+Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import Android
import Musl
#endif

internal import Dispatch

import Synchronization
import _SubprocessCShims

Expand Down
2 changes: 0 additions & 2 deletions Sources/Subprocess/Platforms/Subprocess+Unix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public import Glibc
public import Musl
#endif

@preconcurrency internal import Dispatch

// MARK: - Signals

/// Signals are standardized messages sent to a running program to
Expand Down
1 change: 0 additions & 1 deletion Sources/Subprocess/Platforms/Subprocess+Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#if canImport(WinSDK)

@preconcurrency public import WinSDK
internal import Dispatch
#if canImport(System)
import System
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import System
import SystemPackage
#endif

internal import Dispatch

/// An input type that reads from a `Data` value.
public struct DataInput: InputProtocol {
private let data: Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import Foundation
import FoundationEssentials
#endif // canImport(Darwin)

internal import Dispatch

extension Data {
init(_ s: borrowing RawSpan) {
self = s.withUnsafeBytes { Data($0) }
Expand Down
1 change: 0 additions & 1 deletion Sources/Subprocess/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Musl
import WinSDK
#endif

internal import Dispatch
import _SubprocessCShims

#if canImport(Synchronization)
Expand Down
3 changes: 1 addition & 2 deletions Tests/SubprocessTests/AsyncIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import WinSDK
#endif

import Testing
import Dispatch
import Foundation
import TestResources
import _SubprocessCShims
Expand Down Expand Up @@ -283,7 +282,7 @@ extension SubprocessAsyncIOTests {

try await group.waitForAll()
// Keep both pipe endpoints alive until both tasks complete,
// preventing the DispatchIO cleanup handler from closing
// preventing the cleanup handler from closing
// a pipe fd while the other task is still using it.
withExtendedLifetime((readTestBed, writeTestBed)) {}
// Teardown
Expand Down
34 changes: 0 additions & 34 deletions Tests/SubprocessTests/DarwinTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,4 @@ struct SubprocessDarwinTests {
}
}

extension FileDescriptor {
internal func readUntilEOF(upToLength maxLength: Int) async throws -> Data {
return try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Data, any Error>) in
let dispatchIO = DispatchIO(
type: .stream,
fileDescriptor: self.rawValue,
queue: .global()
) { error in
if error != 0 {
continuation.resume(throwing: POSIXError(.init(rawValue: error) ?? .ENODEV))
}
}
var buffer: Data = Data()
dispatchIO.read(
offset: 0,
length: maxLength,
queue: .global()
) { done, data, error in
guard error == 0 else {
continuation.resume(throwing: POSIXError(.init(rawValue: error) ?? .ENODEV))
return
}
if let data = data {
buffer += Data(data)
}
if done {
dispatchIO.close()
continuation.resume(returning: buffer)
}
}
}
}
}

#endif // canImport(Darwin)
3 changes: 1 addition & 2 deletions Tests/SubprocessTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import WinSDK
#endif

import Testing
import Dispatch
import Foundation
import TestResources
import _SubprocessCShims
Expand Down Expand Up @@ -951,7 +950,7 @@ extension SubprocessIntegrationTests {
contentsOf: URL(filePath: theMysteriousIsland.string)
)
let stream: AsyncStream<Data> = AsyncStream { continuation in
DispatchQueue.global().async {
Task<Void, Never>.detached {
var currentStart = 0
while currentStart + chunkSize < expected.count {
continuation.yield(expected[currentStart..<currentStart + chunkSize])
Expand Down
1 change: 0 additions & 1 deletion Tests/SubprocessTests/ProcessMonitoringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import WinSDK
#endif

import Testing
import Dispatch
import Foundation
import TestResources
import _SubprocessCShims
Expand Down
1 change: 0 additions & 1 deletion Tests/SubprocessTests/UnixTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Testing

import TestResources

import Dispatch
#if canImport(System)
import System
#else
Expand Down
61 changes: 0 additions & 61 deletions Tests/SubprocessTests/WindowsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@preconcurrency import WinSDK
import Foundation
import Testing
import Dispatch

#if canImport(System)
import System
Expand Down Expand Up @@ -413,64 +412,4 @@ extension SubprocessWindowsTests {
}
}

extension FileDescriptor {
internal func readUntilEOF(upToLength maxLength: Int) async throws -> Data {
// TODO: Figure out a better way to asynchronously read
return try await withCheckedThrowingContinuation { continuation in
DispatchQueue.global(qos: .userInitiated).async {
var totalBytesRead: Int = 0
var lastError: DWORD? = nil
let values = [UInt8](
unsafeUninitializedCapacity: maxLength
) { buffer, initializedCount in
while true {
guard let baseAddress = buffer.baseAddress else {
initializedCount = 0
break
}
let bufferPtr = baseAddress.advanced(by: totalBytesRead)
var bytesRead: DWORD = 0
let readSucceed = ReadFile(
self.platformDescriptor,
UnsafeMutableRawPointer(mutating: bufferPtr),
DWORD(maxLength - totalBytesRead),
&bytesRead,
nil
)
if !readSucceed {
// Windows throws ERROR_BROKEN_PIPE when the pipe is closed
let error = GetLastError()
if error == ERROR_BROKEN_PIPE {
// We are done reading
initializedCount = totalBytesRead
} else {
// We got some error
lastError = error
initializedCount = 0
}
break
} else {
// We successfully read the current round
totalBytesRead += Int(bytesRead)
}

if totalBytesRead >= maxLength {
initializedCount = min(maxLength, totalBytesRead)
break
}
}
}
if let lastError = lastError {
let windowsError: SubprocessError = .failedToReadFromProcess(
withUnderlyingError: SubprocessError.WindowsError(rawValue: lastError)
)
continuation.resume(throwing: windowsError)
} else {
continuation.resume(returning: Data(values))
}
}
}
}
}

#endif // canImport(WinSDK)
Loading