Skip to content

Commit 16f2963

Browse files
authored
Merge pull request #59 from apple/vendor-async-process
Vendor in swift-async-process.
2 parents 7f27ae5 + 4439473 commit 16f2963

File tree

77 files changed

+7764
-1161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+7764
-1161
lines changed

.swift-format

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentConditionalCompilationBlocks" : true,
6+
"indentSwitchCaseLabels" : false,
7+
"indentation" : {
8+
"spaces" : 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineBreakBetweenDeclarationAttributes" : false,
15+
"lineLength" : 100,
16+
"maximumBlankLines" : 1,
17+
"multiElementCollectionTrailingCommas" : true,
18+
"noAssignmentInExpressions" : {
19+
"allowedFunctions" : [
20+
"XCTAssertNoThrow"
21+
]
22+
},
23+
"prioritizeKeepingFunctionOutputTogether" : false,
24+
"reflowMultilineStringLiterals" : "never",
25+
"respectsExistingLineBreaks" : true,
26+
"rules" : {
27+
"AllPublicDeclarationsHaveDocumentation" : false,
28+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
29+
"AlwaysUseLowerCamelCase" : true,
30+
"AmbiguousTrailingClosureOverload" : true,
31+
"AvoidRetroactiveConformances" : true,
32+
"BeginDocumentationCommentWithOneLineSummary" : false,
33+
"DoNotUseSemicolons" : true,
34+
"DontRepeatTypeInStaticProperties" : true,
35+
"FileScopedDeclarationPrivacy" : true,
36+
"FullyIndirectEnum" : true,
37+
"GroupNumericLiterals" : true,
38+
"IdentifiersMustBeASCII" : true,
39+
"NeverForceUnwrap" : false,
40+
"NeverUseForceTry" : false,
41+
"NeverUseImplicitlyUnwrappedOptionals" : false,
42+
"NoAccessLevelOnExtensionDeclaration" : true,
43+
"NoAssignmentInExpressions" : true,
44+
"NoBlockComments" : true,
45+
"NoCasesWithOnlyFallthrough" : true,
46+
"NoEmptyLinesOpeningClosingBraces" : false,
47+
"NoEmptyTrailingClosureParentheses" : true,
48+
"NoLabelsInCasePatterns" : true,
49+
"NoLeadingUnderscores" : false,
50+
"NoParensAroundConditions" : true,
51+
"NoPlaygroundLiterals" : true,
52+
"NoVoidReturnOnFunctionSignature" : true,
53+
"OmitExplicitReturns" : false,
54+
"OneCasePerLine" : true,
55+
"OneVariableDeclarationPerLine" : true,
56+
"OnlyOneTrailingClosureArgument" : true,
57+
"OrderedImports" : true,
58+
"ReplaceForEachWithForLoop" : true,
59+
"ReturnVoidInsteadOfEmptyTuple" : true,
60+
"TypeNamesShouldBeCapitalized" : true,
61+
"UseEarlyExits" : false,
62+
"UseExplicitNilCheckInConditions" : true,
63+
"UseLetInEveryBoundCaseVariable" : true,
64+
"UseShorthandTypeNames" : true,
65+
"UseSingleLinePropertyGetter" : true,
66+
"UseSynthesizedInitializer" : true,
67+
"UseTripleSlashForDocumentationComments" : true,
68+
"UseWhereClausesInForLoops" : false,
69+
"ValidateDocumentationComments" : false
70+
},
71+
"spacesAroundRangeFormationOperators" : false,
72+
"spacesBeforeEndOfLineComments" : 2,
73+
"tabWidth" : 8,
74+
"version" : 1
75+
}

Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// swift-tools-version:5.5
22
import PackageDescription
3+
34
import class Foundation.ProcessInfo
45

56
let macOSPlatform: SupportedPlatform
@@ -19,43 +20,92 @@ let package = Package(
1920
name: "swift-tools-support-async",
2021
platforms: [
2122
macOSPlatform,
22-
iOSPlatform
23+
iOSPlatform,
2324
],
2425
products: [
2526
.library(
2627
name: "SwiftToolsSupportAsync",
27-
targets: ["TSFFutures", "TSFUtility"]),
28+
targets: ["TSFFutures", "TSFUtility", "TSFAsyncProcess"]),
2829
.library(
2930
name: "SwiftToolsSupportCAS",
3031
targets: ["TSFCAS", "TSFCASFileTree", "TSFCASUtilities"]),
3132
],
3233
dependencies: [
34+
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.4"),
35+
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0"),
36+
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.0"),
37+
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.2"),
3338
.package(url: "https://github.com/apple/swift-nio.git", from: "2.68.0"),
3439
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.28.0"),
35-
.package(url: "https://github.com/apple/swift-tools-support-core.git", "0.5.8" ..< "0.8.0"),
40+
.package(url: "https://github.com/apple/swift-system.git", from: "1.1.1"),
41+
.package(url: "https://github.com/apple/swift-tools-support-core.git", "0.5.8"..<"0.8.0"),
3642
],
3743
targets: [
3844
// BLAKE3 hash support
3945
.target(
4046
name: "CBLAKE3",
4147
dependencies: [],
4248
cSettings: [
43-
.headerSearchPath("./"),
49+
.headerSearchPath("./")
50+
]
51+
),
52+
53+
// Async Process vendored library
54+
.target(
55+
name: "TSFAsyncProcess",
56+
dependencies: [
57+
"TSFProcessSpawnSync",
58+
.product(name: "Atomics", package: "swift-atomics"),
59+
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
60+
.product(name: "Logging", package: "swift-log"),
61+
.product(name: "NIO", package: "swift-nio"),
62+
.product(name: "DequeModule", package: "swift-collections"),
63+
.product(name: "SystemPackage", package: "swift-system"),
64+
],
65+
path: "Sources/AsyncProcess"
66+
),
67+
.testTarget(
68+
name: "TSFAsyncProcessTests",
69+
dependencies: [
70+
"TSFAsyncProcess",
71+
.product(name: "Atomics", package: "swift-atomics"),
72+
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
73+
.product(name: "NIO", package: "swift-nio"),
74+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
75+
.product(name: "Logging", package: "swift-log"),
76+
.product(name: "_NIOFileSystem", package: "swift-nio"),
77+
],
78+
path: "Tests/AsyncProcessTests"
79+
),
80+
.target(
81+
name: "TSFCProcessSpawnSync",
82+
path: "Sources/CProcessSpawnSync",
83+
cSettings: [
84+
.define("_GNU_SOURCE")
4485
]
4586
),
87+
.target(
88+
name: "TSFProcessSpawnSync",
89+
dependencies: [
90+
"TSFCProcessSpawnSync",
91+
.product(name: "Atomics", package: "swift-atomics"),
92+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
93+
],
94+
path: "Sources/ProcessSpawnSync"
95+
),
4696

4797
.target(
4898
name: "TSFFutures",
4999
dependencies: [
50100
.product(name: "NIO", package: "swift-nio"),
51101
.product(name: "NIOFoundationCompat", package: "swift-nio"),
52-
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core")
102+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
53103
]
54104
),
55105
.testTarget(
56106
name: "TSFFuturesTests",
57107
dependencies: [
58-
"TSFFutures",
108+
"TSFFutures"
59109
]
60110
),
61111
.target(
@@ -72,7 +122,7 @@ let package = Package(
72122
name: "TSFCAS",
73123
dependencies: [
74124
"TSFFutures", "TSFUtility", "CBLAKE3",
75-
.product(name: "SwiftProtobuf", package: "swift-protobuf")
125+
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
76126
]
77127
),
78128
.target(
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// DO NOT EDIT - Make any changes in the upstream swift-async-process package, then re-run the vendoring script.
14+
15+
import NIO
16+
17+
#if os(Linux) || os(Android) || os(Windows)
18+
@preconcurrency import Foundation
19+
#else
20+
import Foundation
21+
#endif
22+
23+
public struct IllegalStreamConsumptionError: Error {
24+
var description: String
25+
}
26+
27+
public struct ChunkSequence: AsyncSequence & Sendable {
28+
private let contentStream: FileContentStream?
29+
30+
public init(
31+
takingOwnershipOfFileHandle fileHandle: FileHandle,
32+
group: EventLoopGroup
33+
) async throws {
34+
// This will close the fileHandle
35+
let contentStream = try await fileHandle.fileContentStream(eventLoop: group.any())
36+
self.init(contentStream: contentStream)
37+
}
38+
39+
internal func isSameAs(_ other: ChunkSequence) -> Bool {
40+
guard let myContentStream = self.contentStream else {
41+
return other.contentStream == nil
42+
}
43+
guard let otherContentStream = other.contentStream else {
44+
return self.contentStream == nil
45+
}
46+
return myContentStream.isSameAs(otherContentStream)
47+
}
48+
49+
public func close() async throws {
50+
try await self.contentStream?.close()
51+
}
52+
53+
private init(contentStream: FileContentStream?) {
54+
self.contentStream = contentStream
55+
}
56+
57+
public static func makeEmptyStream() -> Self {
58+
return Self.init(contentStream: nil)
59+
}
60+
61+
public func makeAsyncIterator() -> AsyncIterator {
62+
return AsyncIterator(self.contentStream)
63+
}
64+
65+
public typealias Element = ByteBuffer
66+
public struct AsyncIterator: AsyncIteratorProtocol {
67+
public typealias Element = ByteBuffer
68+
internal typealias UnderlyingSequence = FileContentStream
69+
70+
private var underlyingIterator: UnderlyingSequence.AsyncIterator?
71+
72+
internal init(_ underlyingSequence: UnderlyingSequence?) {
73+
self.underlyingIterator = underlyingSequence?.makeAsyncIterator()
74+
}
75+
76+
public mutating func next() async throws -> Element? {
77+
if self.underlyingIterator != nil {
78+
return try await self.underlyingIterator!.next()
79+
} else {
80+
throw IllegalStreamConsumptionError(
81+
description: """
82+
Either `.discard`ed, `.inherit`ed or redirected this stream to a `.fileHandle`,
83+
cannot also consume it. To consume, please `.stream` it.
84+
"""
85+
)
86+
}
87+
}
88+
}
89+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// DO NOT EDIT - Make any changes in the upstream swift-async-process package, then re-run the vendoring script.
14+
15+
public struct EOFSequence<Element>: AsyncSequence & Sendable {
16+
public typealias Element = Element
17+
18+
public struct AsyncIterator: AsyncIteratorProtocol {
19+
public mutating func next() async throws -> Element? {
20+
return nil
21+
}
22+
}
23+
24+
public init(of type: Element.Type = Element.self) {}
25+
26+
public func makeAsyncIterator() -> AsyncIterator {
27+
return AsyncIterator()
28+
}
29+
}

0 commit comments

Comments
 (0)