Skip to content

Commit d37e9f2

Browse files
committed
Remove unnecessary availability check around AsyncBufferSequence and closure based run()
1 parent b864ce4 commit d37e9f2

File tree

5 files changed

+15
-70
lines changed

5 files changed

+15
-70
lines changed

Sources/Subprocess/API.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ public func run<
158158
/// - body: The custom execution body to manually control the running process
159159
/// - Returns a ExecutableResult type containing the return value
160160
/// of the closure.
161-
#if SubprocessSpan
162-
@available(SubprocessSpan, *)
163-
#endif
164161
public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
165162
_ executable: Executable,
166163
arguments: Arguments = [],
@@ -208,9 +205,6 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
208205
}
209206
}
210207

211-
#if SubprocessSpan
212-
@available(SubprocessSpan, *)
213-
#endif
214208
public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
215209
_ executable: Executable,
216210
arguments: Arguments = [],
@@ -258,9 +252,6 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
258252
}
259253
}
260254

261-
#if SubprocessSpan
262-
@available(SubprocessSpan, *)
263-
#endif
264255
public func run<Result, Error: OutputProtocol>(
265256
_ executable: Executable,
266257
arguments: Arguments = [],
@@ -291,9 +282,6 @@ public func run<Result, Error: OutputProtocol>(
291282
}
292283
}
293284

294-
#if SubprocessSpan
295-
@available(SubprocessSpan, *)
296-
#endif
297285
public func run<Result, Output: OutputProtocol>(
298286
_ executable: Executable,
299287
arguments: Arguments = [],
@@ -340,9 +328,6 @@ public func run<Result, Output: OutputProtocol>(
340328
/// - body: The custom execution body to manually control the running process
341329
/// - Returns a ExecutableResult type containing the return value
342330
/// of the closure.
343-
#if SubprocessSpan
344-
@available(SubprocessSpan, *)
345-
#endif
346331
public func run<Result>(
347332
_ executable: Executable,
348333
arguments: Arguments = [],
@@ -486,9 +471,6 @@ public func run<
486471
/// the running process and write to its standard input.
487472
/// - Returns a ExecutableResult type containing the return value
488473
/// of the closure.
489-
#if SubprocessSpan
490-
@available(SubprocessSpan, *)
491-
#endif
492474
public func run<Result>(
493475
_ configuration: Configuration,
494476
isolation: isolated (any Actor)? = #isolation,
@@ -528,9 +510,6 @@ public func run<Result>(
528510
/// - output: A file descriptor to bind to the subprocess' standard output.
529511
/// - error: A file descriptor to bind to the subprocess' standard error.
530512
/// - Returns: the process identifier for the subprocess.
531-
#if SubprocessSpan
532-
@available(SubprocessSpan, *)
533-
#endif
534513
public func runDetached(
535514
_ executable: Executable,
536515
arguments: Arguments = [],
@@ -564,9 +543,6 @@ public func runDetached(
564543
/// - output: A file descriptor to bind to the subprocess' standard output.
565544
/// - error: A file descriptor to bind to the subprocess' standard error.
566545
/// - Returns: the process identifier for the subprocess.
567-
#if SubprocessSpan
568-
@available(SubprocessSpan, *)
569-
#endif
570546
public func runDetached(
571547
_ configuration: Configuration,
572548
input: FileDescriptor? = nil,

Sources/Subprocess/AsyncBufferSequence.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
internal import Dispatch
2020
#endif
2121

22-
#if SubprocessSpan
23-
@available(SubprocessSpan, *)
24-
#endif
2522
public struct AsyncBufferSequence: AsyncSequence, Sendable {
2623
public typealias Failure = any Swift.Error
2724
public typealias Element = Buffer
@@ -93,9 +90,6 @@ public struct AsyncBufferSequence: AsyncSequence, Sendable {
9390
}
9491

9592
// MARK: - LineSequence
96-
#if SubprocessSpan
97-
@available(SubprocessSpan, *)
98-
#endif
9993
extension AsyncBufferSequence {
10094
public struct LineSequence<Encoding: _UnicodeEncoding>: AsyncSequence, Sendable {
10195
public typealias Element = String
@@ -308,9 +302,6 @@ extension AsyncBufferSequence {
308302
}
309303
}
310304

311-
#if SubprocessSpan
312-
@available(SubprocessSpan, *)
313-
#endif
314305
extension AsyncBufferSequence.LineSequence {
315306
public enum BufferingPolicy: Sendable {
316307
/// Continue to add to the buffer, without imposing a limit

Sources/Subprocess/Buffer.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
@preconcurrency internal import Dispatch
1414
#endif
1515

16-
#if SubprocessSpan
17-
@available(SubprocessSpan, *)
18-
#endif
16+
1917
extension AsyncBufferSequence {
2018
/// A immutable collection of bytes
2119
public struct Buffer: Sendable {
@@ -52,9 +50,6 @@ extension AsyncBufferSequence {
5250
}
5351

5452
// MARK: - Properties
55-
#if SubprocessSpan
56-
@available(SubprocessSpan, *)
57-
#endif
5853
extension AsyncBufferSequence.Buffer {
5954
/// Number of bytes stored in the buffer
6055
public var count: Int {
@@ -68,9 +63,6 @@ extension AsyncBufferSequence.Buffer {
6863
}
6964

7065
// MARK: - Accessors
71-
#if SubprocessSpan
72-
@available(SubprocessSpan, *)
73-
#endif
7466
extension AsyncBufferSequence.Buffer {
7567
/// Access the raw bytes stored in this buffer
7668
/// - Parameter body: A closure with an `UnsafeRawBufferPointer` parameter that
@@ -87,6 +79,9 @@ extension AsyncBufferSequence.Buffer {
8779

8880
#if SubprocessSpan
8981
// Access the storge backing this Buffer
82+
#if SubprocessSpan
83+
@available(SubprocessSpan, *)
84+
#endif
9085
public var bytes: RawSpan {
9186
@lifetime(borrow self)
9287
borrowing get {
@@ -99,9 +94,6 @@ extension AsyncBufferSequence.Buffer {
9994
}
10095

10196
// MARK: - Hashable, Equatable
102-
#if SubprocessSpan
103-
@available(SubprocessSpan, *)
104-
#endif
10597
extension AsyncBufferSequence.Buffer: Equatable, Hashable {
10698
#if os(Windows)
10799
// Compiler generated conformances

Sources/Subprocess/IO/Output.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,11 @@ public struct BytesOutput: OutputProtocol {
166166
fatalError("Trying to capture output without file descriptor")
167167
}
168168
#if os(Windows)
169-
let result = try await diskIO.fileDescriptor.read(upToLength: self.maxSize)
169+
return try await diskIO.fileDescriptor.read(upToLength: self.maxSize) ?? []
170170
#else
171171
let result = try await diskIO.dispatchIO.read(upToLength: self.maxSize)
172-
#endif
173-
174172
return result?.array() ?? []
173+
#endif
175174
}
176175

177176
#if SubprocessSpan
@@ -315,11 +314,11 @@ extension OutputProtocol {
315314

316315
#if os(Windows)
317316
let result = try await diskIO.fileDescriptor.read(upToLength: self.maxSize)
317+
return try self.output(from: result ?? [])
318318
#else
319319
let result = try await diskIO.dispatchIO.read(upToLength: self.maxSize)
320-
#endif
321-
322320
return try self.output(from: result ?? .empty)
321+
#endif
323322
}
324323
}
325324

Tests/SubprocessTests/SubprocessTests+Unix.swift

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,6 @@ extension SubprocessUnixTests {
420420
}
421421

422422
@Test func testInputSequenceCustomExecutionBody() async throws {
423-
guard #available(SubprocessSpan , *) else {
424-
return
425-
}
426423
let expected: Data = try Data(
427424
contentsOf: URL(filePath: theMysteriousIsland.string)
428425
)
@@ -443,9 +440,6 @@ extension SubprocessUnixTests {
443440
}
444441

445442
@Test func testInputAsyncSequenceCustomExecutionBody() async throws {
446-
guard #available(SubprocessSpan , *) else {
447-
return
448-
}
449443
// Maeks ure we can read long text as AsyncSequence
450444
let fd: FileDescriptor = try .open(theMysteriousIsland, .readOnly)
451445
let expected: Data = try Data(
@@ -606,9 +600,6 @@ extension SubprocessUnixTests {
606600
}
607601

608602
@Test func testRedirectedOutputWithUnsafeBytes() async throws {
609-
guard #available(SubprocessSpan , *) else {
610-
return
611-
}
612603
// Make ure we can read long text redirected to AsyncSequence
613604
let expected: Data = try Data(
614605
contentsOf: URL(filePath: theMysteriousIsland.string)
@@ -629,20 +620,16 @@ extension SubprocessUnixTests {
629620
#expect(catResult.value == expected)
630621
}
631622

623+
#if SubprocessSpan
632624
@Test func testRedirectedOutputBytes() async throws {
633-
guard #available(SubprocessSpan , *) else {
634-
return
635-
}
636-
637625
// Make ure we can read long text redirected to AsyncSequence
638626
let expected: Data = try Data(
639627
contentsOf: URL(filePath: theMysteriousIsland.string)
640628
)
641629
let catResult = try await Subprocess.run(
642630
.path("/bin/cat"),
643-
arguments: [theMysteriousIsland.string],
644-
error: .discarded
645-
) { execution, standardOutput in
631+
arguments: [theMysteriousIsland.string]
632+
) { (execution: Execution, standardOutput: AsyncBufferSequence) -> Data in
646633
var buffer: Data = Data()
647634
for try await chunk in standardOutput {
648635
buffer += Data(bytes: chunk.bytes)
@@ -652,6 +639,7 @@ extension SubprocessUnixTests {
652639
#expect(catResult.terminationStatus.isSuccess)
653640
#expect(catResult.value == expected)
654641
}
642+
#endif
655643

656644
@Test func testBufferOutput() async throws {
657645
guard #available(SubprocessSpan , *) else {
@@ -688,6 +676,8 @@ extension SubprocessUnixTests {
688676
}
689677
}
690678

679+
#if SubprocessSpan
680+
@available(SubprocessSpan, *)
691681
extension Data {
692682
init(bytes: borrowing RawSpan) {
693683
let data = bytes.withUnsafeBytes {
@@ -696,6 +686,7 @@ extension Data {
696686
self = data
697687
}
698688
}
689+
#endif
699690

700691
// MARK: - PlatformOption Tests
701692
extension SubprocessUnixTests {
@@ -968,10 +959,6 @@ extension SubprocessUnixTests {
968959
}
969960

970961
@Test func testLineSequence() async throws {
971-
guard #available(SubprocessSpan , *) else {
972-
return
973-
}
974-
975962
typealias TestCase = (value: String, count: Int, newLine: String)
976963
enum TestCaseSize: CaseIterable {
977964
case large // (1.0 ~ 2.0) * buffer size

0 commit comments

Comments
 (0)