Skip to content

Commit 3cc99d0

Browse files
Fix the build when the SubprocessFoundation trait is disabled (#154)
Closes #129
1 parent 32312d5 commit 3cc99d0

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

.github/workflows/pull_request.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,22 @@ jobs:
2828
# Test dependencies
2929
yum install -y procps
3030
fi
31+
linux_build_command: 'swift test && swift test --disable-default-traits'
3132
windows_swift_versions: '["6.1", "nightly-main"]'
33+
windows_build_command: |
34+
Invoke-Program swift test
35+
Invoke-Program swift test --disable-default-traits
3236
enable_macos_checks: true
3337
macos_xcode_versions: '["16.3"]'
38+
macos_build_command: 'xcrun swift test && xcrun swift test --disable-default-traits'
3439
enable_linux_static_sdk_build: true
3540
linux_static_sdk_versions: '["6.1", "nightly-6.2"]'
41+
linux_static_sdk_build_command: |
42+
for triple in aarch64-swift-linux-musl x86_64-swift-linux-musl ; do
43+
swift build --swift-sdk "\$triple"
44+
swift build --swift-sdk "\$triple" --disable-default-traits
45+
done
46+
# empty line to ignore the --swift-sdk given by swiftlang/github-workflows/.github/workflows/scripts/install-and-build-with-sdk.sh \
3647
3748
soundness:
3849
name: Soundness

Sources/Subprocess/Buffer.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,45 @@ extension DispatchData.Region {
120120
}
121121
}
122122
}
123-
#endif
123+
#if !SubprocessFoundation
124+
/// `DispatchData.Region` is defined in Foundation, but we can't depend on Foundation when the SubprocessFoundation trait is disabled.
125+
extension DispatchData {
126+
typealias Region = _ContiguousBufferView
127+
128+
var regions: [Region] {
129+
contiguousBufferViews
130+
}
131+
132+
internal struct _ContiguousBufferView: @unchecked Sendable, RandomAccessCollection {
133+
typealias Element = UInt8
134+
135+
internal let bytes: UnsafeBufferPointer<UInt8>
136+
137+
internal var startIndex: Int { self.bytes.startIndex }
138+
internal var endIndex: Int { self.bytes.endIndex }
139+
140+
internal init(bytes: UnsafeBufferPointer<UInt8>) {
141+
self.bytes = bytes
142+
}
143+
144+
internal func withUnsafeBytes<ResultType>(_ body: (UnsafeRawBufferPointer) throws -> ResultType) rethrows -> ResultType {
145+
return try body(UnsafeRawBufferPointer(self.bytes))
146+
}
124147

148+
subscript(position: Int) -> UInt8 {
149+
_read {
150+
yield self.bytes[position]
151+
}
152+
}
153+
}
154+
155+
internal var contiguousBufferViews: [_ContiguousBufferView] {
156+
var slices = [_ContiguousBufferView]()
157+
enumerateBytes { (bytes, index, stop) in
158+
slices.append(_ContiguousBufferView(bytes: bytes))
159+
}
160+
return slices
161+
}
162+
}
163+
#endif
164+
#endif

Tests/SubprocessTests/IntegrationTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ extension SubprocessIntegrationTests {
559559
)
560560
}
561561

562+
#if SubprocessFoundation
562563
@Test func testFileDescriptorInput() async throws {
563564
#if os(Windows)
564565
let setup = TestSetup(
@@ -592,6 +593,7 @@ extension SubprocessIntegrationTests {
592593
// Make sure we read all bytes
593594
#expect(cat.standardOutput == expected)
594595
}
596+
#endif
595597

596598
#if SubprocessFoundation
597599
@Test func testDataInput() async throws {
@@ -658,6 +660,7 @@ extension SubprocessIntegrationTests {
658660
}
659661
#endif
660662

663+
#if SubprocessFoundation
661664
@Test func testAsyncSequenceInput() async throws {
662665
#if os(Windows)
663666
let setup = TestSetup(
@@ -700,6 +703,7 @@ extension SubprocessIntegrationTests {
700703
#expect(catResult.terminationStatus.isSuccess)
701704
#expect(catResult.standardOutput == expected)
702705
}
706+
#endif
703707

704708
@Test func testStandardInputWriterInput() async throws {
705709
#if os(Windows)
@@ -810,6 +814,7 @@ extension SubprocessIntegrationTests {
810814
#expect(echoResult.terminationStatus.isSuccess)
811815
}
812816

817+
#if SubprocessFoundation
813818
@Test func testStringOutput() async throws {
814819
#if os(Windows)
815820
let setup = TestSetup(
@@ -845,6 +850,7 @@ extension SubprocessIntegrationTests {
845850
).trimmingNewLineAndQuotes()
846851
)
847852
}
853+
#endif
848854

849855
@Test func testStringOutputExceedsLimit() async throws {
850856
#if os(Windows)
@@ -878,6 +884,7 @@ extension SubprocessIntegrationTests {
878884
}
879885
}
880886

887+
#if SubprocessFoundation
881888
@Test func testBytesOutput() async throws {
882889
#if os(Windows)
883890
let setup = TestSetup(
@@ -907,6 +914,7 @@ extension SubprocessIntegrationTests {
907914
catResult.standardOutput == Array(expected)
908915
)
909916
}
917+
#endif
910918

911919
@Test func testBytesOutputExceedsLimit() async throws {
912920
#if os(Windows)
@@ -1089,6 +1097,7 @@ extension SubprocessIntegrationTests {
10891097
}
10901098
#endif
10911099

1100+
#if SubprocessFoundation
10921101
@Test func testStringErrorOutput() async throws {
10931102
#if os(Windows)
10941103
let setup = TestSetup(
@@ -1124,6 +1133,7 @@ extension SubprocessIntegrationTests {
11241133
).trimmingNewLineAndQuotes()
11251134
)
11261135
}
1136+
#endif
11271137

11281138
@Test func testStringErrorOutputExceedsLimit() async throws {
11291139
#if os(Windows)
@@ -1156,6 +1166,7 @@ extension SubprocessIntegrationTests {
11561166
}
11571167
}
11581168

1169+
#if SubprocessFoundation
11591170
@Test func testBytesErrorOutput() async throws {
11601171
#if os(Windows)
11611172
let setup = TestSetup(
@@ -1185,6 +1196,7 @@ extension SubprocessIntegrationTests {
11851196
catResult.standardError == Array(expected)
11861197
)
11871198
}
1199+
#endif
11881200

11891201
@Test func testBytesErrorOutputExceedsLimit() async throws {
11901202
#if os(Windows)
@@ -1757,6 +1769,7 @@ extension SubprocessIntegrationTests {
17571769
try FileManager.default.removeItem(at: testFilePath)
17581770
}
17591771

1772+
#if SubprocessFoundation
17601773
@Test func testCaptureLongStandardOutputAndError() async throws {
17611774
let string = String(repeating: "X", count: 100_000)
17621775
#if os(Windows)
@@ -1791,6 +1804,7 @@ extension SubprocessIntegrationTests {
17911804
try await group.waitForAll()
17921805
}
17931806
}
1807+
#endif
17941808

17951809
@Test func stressTestCancelProcessVeryEarlyOn() async throws {
17961810

Tests/SubprocessTests/UnixTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ internal func assertNewSessionCreated(
467467

468468
// MARK: - Performance Tests
469469
extension SubprocessUnixTests {
470+
#if SubprocessFoundation
470471
@Test(.requiresBash) func testConcurrentRun() async throws {
471472
// Launch as many processes as we can
472473
// Figure out the max open file limit
@@ -520,6 +521,7 @@ extension SubprocessUnixTests {
520521
try await group.waitForAll()
521522
}
522523
}
524+
#endif
523525
}
524526

525527
#endif // canImport(Darwin) || canImport(Glibc)

0 commit comments

Comments
 (0)