Skip to content

Commit 436c042

Browse files
committed
Add in several missing noasync annotations
Helps make async client code safer by warning about use of blocking overloads.
1 parent f4fa0a8 commit 436c042

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

Sources/TSCBasic/Await.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414
/// should be passed to the async method's completion handler.
1515
/// - Returns: The value wrapped by the async method's result.
1616
/// - Throws: The error wrapped by the async method's result
17-
//#if compiler(>=5.8)
18-
//@available(*, noasync)
19-
//#endif
17+
@available(*, noasync)
2018
public func tsc_await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
2119
return try tsc_await(body).get()
2220
}
2321

24-
//#if compiler(>=5.8)
25-
//@available(*, noasync)
26-
//#endif
22+
@available(*, noasync)
2723
public func tsc_await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
2824
let condition = Condition()
2925
var result: T? = nil

Sources/TSCBasic/Process/Process.swift

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ public final class Process {
324324

325325
/// The result of the process execution. Available after process is terminated.
326326
/// This will block while the process is awaiting result
327+
@available(*, noasync)
327328
@available(*, deprecated, message: "use waitUntilExit instead")
328329
public var result: ProcessResult? {
329330
return self.stateLock.withLock {
@@ -856,7 +857,9 @@ public final class Process {
856857
public func waitUntilExit() async throws -> ProcessResult {
857858
try await withCheckedThrowingContinuation { continuation in
858859
DispatchQueue.processConcurrent.async {
859-
self.waitUntilExit(continuation.resume(with:))
860+
self.waitUntilExit {
861+
continuation.resume(with: $0)
862+
}
860863
}
861864
}
862865
}
@@ -1127,9 +1130,7 @@ extension Process {
11271130
/// - loggingHandler: Handler for logging messages
11281131
/// - queue: Queue to use for callbacks
11291132
/// - completion: A completion handler to return the process result
1130-
// #if compiler(>=5.8)
1131-
// @available(*, noasync)
1132-
// #endif
1133+
@available(*, noasync)
11331134
static public func popen(
11341135
arguments: [String],
11351136
environmentBlock: ProcessEnvironmentBlock = ProcessEnv.block,
@@ -1157,6 +1158,7 @@ extension Process {
11571158
}
11581159

11591160
@_disfavoredOverload
1161+
@available(*, noasync)
11601162
@available(*, deprecated, renamed: "popen(arguments:environmentBlock:loggingHandler:queue:completion:)")
11611163
static public func popen(
11621164
arguments: [String],
@@ -1182,9 +1184,7 @@ extension Process {
11821184
/// will be inherited.
11831185
/// - loggingHandler: Handler for logging messages
11841186
/// - Returns: The process result.
1185-
// #if compiler(>=5.8)
1186-
// @available(*, noasync)
1187-
// #endif
1187+
@available(*, noasync)
11881188
@discardableResult
11891189
static public func popen(
11901190
arguments: [String],
@@ -1202,6 +1202,7 @@ extension Process {
12021202
}
12031203

12041204
@_disfavoredOverload
1205+
@available(*, noasync)
12051206
@available(*, deprecated, renamed: "popen(arguments:environmentBlock:loggingHandler:)")
12061207
@discardableResult
12071208
static public func popen(
@@ -1220,9 +1221,7 @@ extension Process {
12201221
/// will be inherited.
12211222
/// - loggingHandler: Handler for logging messages
12221223
/// - Returns: The process result.
1223-
// #if compiler(>=5.8)
1224-
// @available(*, noasync)
1225-
// #endif
1224+
@available(*, noasync)
12261225
@discardableResult
12271226
static public func popen(
12281227
args: String...,
@@ -1233,6 +1232,7 @@ extension Process {
12331232
}
12341233

12351234
@_disfavoredOverload
1235+
@available(*, noasync)
12361236
@available(*, deprecated, renamed: "popen(args:environmentBlock:loggingHandler:)")
12371237
@discardableResult
12381238
static public func popen(
@@ -1251,9 +1251,7 @@ extension Process {
12511251
/// will be inherited.
12521252
/// - loggingHandler: Handler for logging messages
12531253
/// - Returns: The process output (stdout + stderr).
1254-
// #if compiler(>=5.8)
1255-
// @available(*, noasync)
1256-
// #endif
1254+
@available(*, noasync)
12571255
@discardableResult
12581256
static public func checkNonZeroExit(
12591257
arguments: [String],
@@ -1276,6 +1274,7 @@ extension Process {
12761274
}
12771275

12781276
@_disfavoredOverload
1277+
@available(*, noasync)
12791278
@available(*, deprecated, renamed: "checkNonZeroExit(arguments:environmentBlock:loggingHandler:)")
12801279
@discardableResult
12811280
static public func checkNonZeroExit(
@@ -1294,9 +1293,7 @@ extension Process {
12941293
/// will be inherited.
12951294
/// - loggingHandler: Handler for logging messages
12961295
/// - Returns: The process output (stdout + stderr).
1297-
// #if compiler(>=5.8)
1298-
// @available(*, noasync)
1299-
// #endif
1296+
@available(*, noasync)
13001297
@discardableResult
13011298
static public func checkNonZeroExit(
13021299
args: String...,
@@ -1307,6 +1304,7 @@ extension Process {
13071304
}
13081305

13091306
@_disfavoredOverload
1307+
@available(*, noasync)
13101308
@available(*, deprecated, renamed: "checkNonZeroExit(args:environmentBlock:loggingHandler:)")
13111309
@discardableResult
13121310
static public func checkNonZeroExit(

Sources/TSCBasic/Process/ProcessSet.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public final class ProcessSet {
6565
/// Terminate all the processes. This method blocks until all processes in the set are terminated.
6666
///
6767
/// A process set cannot be used once it has been asked to terminate.
68-
// #if compiler(>=5.8)
69-
// @available(*, noasync)
70-
// #endif
68+
@available(*, noasync)
7169
public func terminate() {
7270
// Mark a process set as cancelled.
7371
serialQueue.sync {

Sources/TSCTestSupport/misc.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ public func testWithTemporaryDirectory(
4444
}
4545
}
4646

47+
@available(*, noasync)
48+
@available(*, deprecated, message: "Use Process.checkNonZeroExit(arguments:) instead.")
4749
public func systemQuietly(_ args: [String]) throws {
4850
// Discard the output, by default.
4951
//
5052
// FIXME: Find a better default behavior here.
5153
try Process.checkNonZeroExit(arguments: args)
5254
}
5355

56+
@available(*, noasync)
57+
@available(*, deprecated, message: "Use Process.checkNonZeroExit(_:) instead.")
5458
public func systemQuietly(_ args: String...) throws {
5559
try systemQuietly(args)
5660
}

Tests/TSCBasicTests/ProcessTests.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,7 @@ fileprivate extension Process {
478478
self.init(arguments: [Self.script(scriptName)] + arguments, environment: Self.env(), outputRedirection: outputRedirection)
479479
}
480480

481-
// #if compiler(>=5.8)
482-
// @available(*, noasync)
483-
// #endif
481+
@available(*, noasync)
484482
static func checkNonZeroExit(
485483
scriptName: String,
486484
environment: [String: String] = ProcessEnv.vars,
@@ -498,9 +496,7 @@ fileprivate extension Process {
498496
return try await checkNonZeroExit(args: script(scriptName), environment: environment, loggingHandler: loggingHandler)
499497
}
500498

501-
// #if compiler(>=5.8)
502-
// @available(*, noasync)
503-
// #endif
499+
@available(*, noasync)
504500
@discardableResult
505501
static func popen(
506502
scriptName: String,

0 commit comments

Comments
 (0)