Skip to content

Commit e928031

Browse files
committed
Deprecate temp_await and being moving to async/await across multiple commands
1 parent 54652f6 commit e928031

File tree

10 files changed

+375
-374
lines changed

10 files changed

+375
-374
lines changed

Sources/Basics/Concurrency/ConcurrencyHelpers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public enum Concurrency {
2525
}
2626

2727
// FIXME: mark as deprecated once async/await is available
28-
// @available(*, deprecated, message: "replace with async/await when available")
28+
@available(*, deprecated, message: "replace with async/await when available")
2929
@inlinable
3030
public func temp_await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
3131
try tsc_await(body)
3232
}
3333

3434
// FIXME: mark as deprecated once async/await is available
35-
// @available(*, deprecated, message: "replace with async/await when available")
35+
@available(*, deprecated, message: "replace with async/await when available")
3636
@inlinable
3737
public func temp_await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
3838
tsc_await(body)

Sources/Commands/PackageCommands/ArchiveSource.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import CoreCommands
1616
import SourceControl
1717

1818
extension SwiftPackageCommand {
19-
struct ArchiveSource: SwiftCommand {
19+
struct ArchiveSource: AsyncSwiftCommand {
2020
static let configuration = CommandConfiguration(
2121
commandName: "archive-source",
2222
abstract: "Create a source archive for the package"
@@ -31,7 +31,7 @@ extension SwiftPackageCommand {
3131
)
3232
var output: AbsolutePath?
3333

34-
func run(_ swiftCommandState: SwiftCommandState) throws {
34+
func run(_ swiftCommandState: SwiftCommandState) async throws {
3535
let packageDirectory = try globalOptions.locations.packageDirectory ?? swiftCommandState.getPackageRoot()
3636

3737
let archivePath: AbsolutePath
@@ -43,7 +43,7 @@ extension SwiftPackageCommand {
4343
archivePath = packageDirectory.appending("\(packageName).zip")
4444
}
4545

46-
try SwiftPackageCommand.archiveSource(
46+
try await SwiftPackageCommand.archiveSource(
4747
at: packageDirectory,
4848
to: archivePath,
4949
fileSystem: localFileSystem,
@@ -64,15 +64,15 @@ extension SwiftPackageCommand {
6464
to archivePath: AbsolutePath,
6565
fileSystem: FileSystem,
6666
cancellator: Cancellator?
67-
) throws {
67+
) async throws {
6868
let gitRepositoryProvider = GitRepositoryProvider()
6969
if gitRepositoryProvider.repositoryExists(at: packageDirectory) &&
7070
(try? gitRepositoryProvider.isValidDirectory(packageDirectory)) == true {
7171
let repository = GitRepository(path: packageDirectory, cancellator: cancellator)
7272
try repository.archive(to: archivePath)
7373
} else {
7474
let zipArchiver = ZipArchiver(fileSystem: fileSystem, cancellator: cancellator)
75-
try temp_await {
75+
try await safe_async {
7676
zipArchiver.compress(directory: packageDirectory, to: archivePath, completion: $0)
7777
}
7878
}

Sources/Commands/PackageCommands/PluginCommand.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import PackageGraph
1919

2020
import PackageModel
2121

22-
struct PluginCommand: SwiftCommand {
22+
struct PluginCommand: AsyncSwiftCommand {
2323
static let configuration = CommandConfiguration(
2424
commandName: "plugin",
2525
abstract: "Invoke a command plugin or perform other actions on command plugins"
@@ -137,7 +137,7 @@ struct PluginCommand: SwiftCommand {
137137
)
138138
var arguments: [String] = []
139139

140-
func run(_ swiftCommandState: SwiftCommandState) throws {
140+
func run(_ swiftCommandState: SwiftCommandState) async throws {
141141
// Check for a missing plugin command verb.
142142
if self.command == "" && !self.listCommands {
143143
throw ValidationError("Missing expected plugin command")
@@ -166,7 +166,7 @@ struct PluginCommand: SwiftCommand {
166166
return
167167
}
168168

169-
try Self.run(
169+
try await Self.run(
170170
command: self.command,
171171
options: self.pluginOptions,
172172
arguments: self.arguments,
@@ -179,7 +179,7 @@ struct PluginCommand: SwiftCommand {
179179
options: PluginOptions,
180180
arguments: [String],
181181
swiftCommandState: SwiftCommandState
182-
) throws {
182+
) async throws {
183183
// Load the workspace and resolve the package graph.
184184
let packageGraph = try swiftCommandState.loadPackageGraph()
185185

@@ -203,7 +203,7 @@ struct PluginCommand: SwiftCommand {
203203
.shouldDisableSandbox
204204

205205
// At this point we know we found exactly one command plugin, so we run it. In SwiftPM CLI, we have only one root package.
206-
try PluginCommand.run(
206+
try await PluginCommand.run(
207207
plugin: matchingPlugins[0],
208208
package: packageGraph.rootPackages[packageGraph.rootPackages.startIndex],
209209
packageGraph: packageGraph,
@@ -220,7 +220,7 @@ struct PluginCommand: SwiftCommand {
220220
options: PluginOptions,
221221
arguments: [String],
222222
swiftCommandState: SwiftCommandState
223-
) throws {
223+
) async throws {
224224
let pluginTarget = plugin.underlying as! PluginModule
225225

226226
swiftCommandState.observabilityScope
@@ -355,7 +355,7 @@ struct PluginCommand: SwiftCommand {
355355

356356
// Run the command plugin.
357357
let buildEnvironment = buildParameters.buildEnvironment
358-
let _ = try temp_await { pluginTarget.invoke(
358+
let _ = try await safe_async { pluginTarget.invoke(
359359
action: .performCommand(package: package, arguments: arguments),
360360
buildEnvironment: buildEnvironment,
361361
scriptRunner: pluginScriptRunner,

Sources/Commands/PackageCommands/SwiftPackageCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public struct SwiftPackageCommand: AsyncParsableCommand {
8686
extension SwiftPackageCommand {
8787
// This command is the default when no other subcommand is passed. It is not shown in the help and is never invoked
8888
// directly.
89-
struct DefaultCommand: SwiftCommand {
89+
struct DefaultCommand: AsyncSwiftCommand {
9090
static let configuration = CommandConfiguration(
9191
commandName: nil,
9292
shouldDisplay: false
@@ -101,7 +101,7 @@ extension SwiftPackageCommand {
101101
@Argument(parsing: .captureForPassthrough)
102102
var remaining: [String] = []
103103

104-
func run(_ swiftCommandState: SwiftCommandState) throws {
104+
func run(_ swiftCommandState: SwiftCommandState) async throws {
105105
// See if have a possible plugin command.
106106
guard let command = remaining.first else {
107107
print(SwiftPackageCommand.helpMessage())
@@ -116,7 +116,7 @@ extension SwiftPackageCommand {
116116
}
117117

118118
// Otherwise see if we can find a plugin.
119-
try PluginCommand.run(
119+
try await PluginCommand.run(
120120
command: command,
121121
options: self.pluginOptions,
122122
arguments: self.remaining,

Sources/Commands/SwiftTestCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
391391
}
392392

393393
if self.options.shouldPrintCodeCovPath {
394-
try printCodeCovPath(swiftCommandState)
394+
try await printCodeCovPath(swiftCommandState)
395395
} else if self.options._deprecated_shouldListTests {
396396
// backward compatibility 6/2022 for deprecation of flag into a subcommand
397397
let command = try List.parse()
@@ -610,10 +610,10 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
610610
}
611611

612612
extension SwiftTestCommand {
613-
func printCodeCovPath(_ swiftCommandState: SwiftCommandState) throws {
613+
func printCodeCovPath(_ swiftCommandState: SwiftCommandState) async throws {
614614
let workspace = try swiftCommandState.getActiveWorkspace()
615615
let root = try swiftCommandState.getWorkspaceRoot()
616-
let rootManifests = try temp_await {
616+
let rootManifests = try await safe_async {
617617
workspace.loadRootManifests(
618618
packages: root.packages,
619619
observabilityScope: swiftCommandState.observabilityScope,

Sources/PackageRegistryCommand/PackageRegistryCommand+Publish.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ extension PackageRegistryCommand {
171171
certificateChainPaths: self.certificateChainPaths
172172
)
173173

174-
let result = try PackageArchiveSigner.prepareArchiveAndSign(
174+
let result = try await PackageArchiveSigner.prepareArchiveAndSign(
175175
packageIdentity: packageIdentity,
176176
packageVersion: packageVersion,
177177
packageDirectory: packageDirectory,
@@ -190,7 +190,7 @@ extension PackageRegistryCommand {
190190
// step 2: generate source archive for the package release
191191
// step 3: signing not required
192192
swiftCommandState.observabilityScope.emit(info: "archiving the source at '\(packageDirectory)'")
193-
archivePath = try PackageArchiver.archive(
193+
archivePath = try await PackageArchiver.archive(
194194
packageIdentity: self.packageIdentity,
195195
packageVersion: self.packageVersion,
196196
packageDirectory: packageDirectory,
@@ -314,7 +314,7 @@ enum PackageArchiveSigner {
314314
cancellator: Cancellator?,
315315
fileSystem: FileSystem,
316316
observabilityScope: ObservabilityScope
317-
) throws -> ArchiveAndSignResult {
317+
) async throws -> ArchiveAndSignResult {
318318
// signing identity
319319
let (signingIdentity, intermediateCertificates) = try Self.signingIdentityAndIntermediateCertificates(
320320
mode: mode,
@@ -349,7 +349,7 @@ enum PackageArchiveSigner {
349349

350350
// create the archive
351351
observabilityScope.emit(info: "archiving the source at '\(packageDirectory)'")
352-
let archivePath = try PackageArchiver.archive(
352+
let archivePath = try await PackageArchiver.archive(
353353
packageIdentity: packageIdentity,
354354
packageVersion: packageVersion,
355355
packageDirectory: packageDirectory,
@@ -473,7 +473,7 @@ enum PackageArchiver {
473473
workingFilesToCopy: [String],
474474
cancellator: Cancellator?,
475475
observabilityScope: ObservabilityScope
476-
) throws -> AbsolutePath {
476+
) async throws -> AbsolutePath {
477477
let archivePath = workingDirectory.appending("\(packageIdentity)-\(packageVersion).zip")
478478

479479
// create temp location for sources
@@ -500,7 +500,7 @@ enum PackageArchiver {
500500
try localFileSystem.writeFileContents(toBeReplacedPath, bytes: replacement)
501501
}
502502

503-
try SwiftPackageCommand.archiveSource(
503+
try await SwiftPackageCommand.archiveSource(
504504
at: sourceDirectory,
505505
to: archivePath,
506506
fileSystem: localFileSystem,

Sources/_InternalTestSupport/MockWorkspace.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public final class MockWorkspace {
8686
skipDependenciesUpdates: Bool = false,
8787
sourceControlToRegistryDependencyTransformation: WorkspaceConfiguration.SourceControlToRegistryDependencyTransformation = .disabled,
8888
defaultRegistry: Registry? = .none
89-
) throws {
89+
) async throws {
9090
try fileSystem.createMockToolchain()
9191

9292
self.sandbox = sandbox
@@ -121,7 +121,7 @@ public final class MockWorkspace {
121121
archiver: MockArchiver()
122122
)
123123
self.customHostToolchain = try UserToolchain.mockHostToolchain(fileSystem)
124-
try self.create()
124+
try await self.create()
125125
}
126126

127127
public var rootsDir: AbsolutePath {
@@ -148,7 +148,7 @@ public final class MockWorkspace {
148148
return try AbsolutePath(validating: name, relativeTo: self.packagesDir)
149149
}
150150

151-
private func create() throws {
151+
private func create() async throws {
152152
// Remove the sandbox if present.
153153
try self.fileSystem.removeFileTree(self.sandbox)
154154

@@ -159,7 +159,7 @@ public final class MockWorkspace {
159159

160160
var manifests: [MockManifestLoader.Key: Manifest] = [:]
161161

162-
func create(package: MockPackage, basePath: AbsolutePath, isRoot: Bool) throws {
162+
func create(package: MockPackage, basePath: AbsolutePath, isRoot: Bool) async throws {
163163
let packagePath: AbsolutePath
164164
switch package.location {
165165
case .fileSystem(let path):
@@ -168,7 +168,7 @@ public final class MockWorkspace {
168168
if let containerProvider = customPackageContainerProvider {
169169
let observability = ObservabilitySystem.makeForTesting()
170170
let packageRef = PackageReference(identity: PackageIdentity(url: url), kind: .remoteSourceControl(url))
171-
let container = try temp_await {
171+
let container = try await safe_async {
172172
containerProvider.getContainer(
173173
for: packageRef,
174174
updateStrategy: .never,
@@ -289,12 +289,12 @@ public final class MockWorkspace {
289289

290290
// Create root packages.
291291
for package in self.roots {
292-
try create(package: package, basePath: self.rootsDir, isRoot: true)
292+
try await create(package: package, basePath: self.rootsDir, isRoot: true)
293293
}
294294

295295
// Create dependency packages.
296296
for package in self.packages {
297-
try create(package: package, basePath: self.packagesDir, isRoot: false)
297+
try await create(package: package, basePath: self.packagesDir, isRoot: false)
298298
}
299299

300300
self.manifestLoader = MockManifestLoader(manifests: manifests)
@@ -771,14 +771,14 @@ public final class MockWorkspace {
771771
roots: [String] = [],
772772
deps: [MockDependency] = [],
773773
_ result: (Workspace.DependencyManifests, [Basics.Diagnostic]) -> Void
774-
) throws {
774+
) async throws {
775775
let observability = ObservabilitySystem.makeForTesting()
776776
let dependencies = try deps.map { try $0.convert(baseURL: packagesDir, identityResolver: self.identityResolver) }
777777
let workspace = try self.getOrCreateWorkspace()
778778
let rootInput = PackageGraphRootInput(
779779
packages: try rootPaths(for: roots), dependencies: dependencies
780780
)
781-
let rootManifests = try temp_await { workspace.loadRootManifests(packages: rootInput.packages, observabilityScope: observability.topScope, completion: $0) }
781+
let rootManifests = try await safe_async { workspace.loadRootManifests(packages: rootInput.packages, observabilityScope: observability.topScope, completion: $0) }
782782
let graphRoot = PackageGraphRoot(input: rootInput, manifests: rootManifests, observabilityScope: observability.topScope)
783783
let manifests = try workspace.loadDependencyManifests(
784784
root: graphRoot,

Tests/CommandsTests/PackageRegistryCommandTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ final class PackageRegistryCommandTests: CommandsTestCase {
358358

359359
let workingDirectory = temporaryDirectory.appending(component: UUID().uuidString)
360360

361-
let archivePath = try PackageArchiver.archive(
361+
let archivePath = try await PackageArchiver.archive(
362362
packageIdentity: packageIdentity,
363363
packageVersion: "1.3.5",
364364
packageDirectory: packageDirectory,
@@ -388,7 +388,7 @@ final class PackageRegistryCommandTests: CommandsTestCase {
388388

389389
let workingDirectory = temporaryDirectory.appending(component: UUID().uuidString)
390390

391-
let archivePath = try PackageArchiver.archive(
391+
let archivePath = try await PackageArchiver.archive(
392392
packageIdentity: packageIdentity,
393393
packageVersion: "1.5.4",
394394
packageDirectory: packageDirectory,
@@ -423,7 +423,7 @@ final class PackageRegistryCommandTests: CommandsTestCase {
423423

424424
let workingDirectory = temporaryDirectory.appending(component: UUID().uuidString)
425425

426-
let archivePath = try PackageArchiver.archive(
426+
let archivePath = try await PackageArchiver.archive(
427427
packageIdentity: packageIdentity,
428428
packageVersion: "0.3.1",
429429
packageDirectory: packageDirectory,

Tests/PackageGraphTests/PubgrubTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,13 @@ final class PubgrubTests: XCTestCase {
360360
XCTAssertThrowsError(try solver1.resolve(state: state1, conflict: notRoot))
361361
}
362362

363-
func testResolverDecisionMaking() throws {
363+
func testResolverDecisionMaking() async throws {
364364
let solver1 = PubGrubDependencyResolver(provider: emptyProvider, observabilityScope: ObservabilitySystem.NOOP)
365365
let state1 = PubGrubDependencyResolver.State(root: rootNode)
366366

367367
// No decision can be made if no unsatisfied terms are available.
368-
XCTAssertNil(try temp_await { solver1.makeDecision(state: state1, completion: $0) })
368+
let decisionNil = try await safe_async { solver1.makeDecision(state: state1, completion: $0) }
369+
XCTAssertNil(decisionNil)
369370

370371
let a = MockContainer(package: aRef, dependenciesByVersion: [
371372
"0.0.0": [:],
@@ -381,7 +382,7 @@ final class PubgrubTests: XCTestCase {
381382

382383
XCTAssertEqual(state2.incompatibilities.count, 0)
383384

384-
let decision = try temp_await { solver2.makeDecision(state: state2, completion: $0) }
385+
let decision = try await safe_async {solver2.makeDecision(state: state2, completion: $0) }
385386
XCTAssertEqual(decision, .product("a", package: "a"))
386387

387388
XCTAssertEqual(state2.incompatibilities.count, 3)

0 commit comments

Comments
 (0)