Skip to content

Commit 1750a26

Browse files
authored
remove the use of async/await in commands (#6254)
motivation: async-await does not work on our CI systems :( changes: * make all commands sync * changes signing APIs to sync
1 parent 748978f commit 1750a26

File tree

7 files changed

+50
-96
lines changed

7 files changed

+50
-96
lines changed

Sources/PackageRegistryTool/PackageRegistryTool+Auth.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private func getpass(_ prompt: String) -> UnsafePointer<CChar> {
5858
#endif
5959

6060
extension SwiftPackageRegistryTool {
61-
struct Login: AsyncSwiftCommand {
61+
struct Login: SwiftCommand {
6262
static let configuration = CommandConfiguration(
6363
abstract: "Log in to a registry"
6464
)
@@ -87,7 +87,7 @@ extension SwiftPackageRegistryTool {
8787

8888
private static let PLACEHOLDER_TOKEN_USER = "token"
8989

90-
func run(_ swiftTool: SwiftTool) async throws {
90+
func run(_ swiftTool: SwiftTool) throws {
9191
let configuration = try getRegistriesConfig(swiftTool)
9292

9393
// compute and validate registry URL
@@ -257,7 +257,7 @@ extension SwiftPackageRegistryTool {
257257
}
258258
}
259259

260-
struct Logout: AsyncSwiftCommand {
260+
struct Logout: SwiftCommand {
261261
static let configuration = CommandConfiguration(
262262
abstract: "Log out from a registry"
263263
)
@@ -272,7 +272,7 @@ extension SwiftPackageRegistryTool {
272272
self.url
273273
}
274274

275-
func run(_ swiftTool: SwiftTool) async throws {
275+
func run(_ swiftTool: SwiftTool) throws {
276276
let configuration = try getRegistriesConfig(swiftTool)
277277

278278
// compute and validate registry URL

Sources/PackageRegistryTool/PackageRegistryTool+Publish.swift

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import _Concurrency
1413
import ArgumentParser
1514
import Basics
1615
import Commands
@@ -25,8 +24,7 @@ import Workspace
2524
import struct TSCUtility.Version
2625

2726
extension SwiftPackageRegistryTool {
28-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
29-
struct Publish: AsyncSwiftCommand {
27+
struct Publish: SwiftCommand {
3028
static let metadataFilename = "package-metadata.json"
3129

3230
static let configuration = CommandConfiguration(
@@ -78,7 +76,7 @@ extension SwiftPackageRegistryTool {
7876
@Flag(help: "Dry run only; prepare the archive and sign it but do not publish to the registry.")
7977
var dryRun: Bool = false
8078

81-
func run(_ swiftTool: SwiftTool) async throws {
79+
func run(_ swiftTool: SwiftTool) throws {
8280
let configuration = try getRegistriesConfig(swiftTool).configuration
8381

8482
// validate package location
@@ -194,7 +192,7 @@ extension SwiftPackageRegistryTool {
194192
swiftTool.observabilityScope.emit(info: "signing the archive at '\(archivePath)'")
195193
let signaturePath = workingDirectory
196194
.appending("\(self.packageIdentity)-\(self.packageVersion).sig")
197-
signature = try await PackageArchiveSigner.sign(
195+
signature = try PackageArchiveSigner.sign(
198196
archivePath: archivePath,
199197
signaturePath: signaturePath,
200198
mode: signingMode,
@@ -214,17 +212,21 @@ extension SwiftPackageRegistryTool {
214212

215213
swiftTool.observabilityScope
216214
.emit(info: "publishing '\(self.packageIdentity)' archive at '\(archivePath)' to '\(registryURL)'")
217-
let result = try await registryClient.publish(
218-
registryURL: registryURL,
219-
packageIdentity: self.packageIdentity,
220-
packageVersion: self.packageVersion,
221-
packageArchive: archivePath,
222-
packageMetadata: self.customMetadataPath,
223-
signature: signature,
224-
signatureFormat: self.signatureFormat,
225-
fileSystem: localFileSystem,
226-
observabilityScope: swiftTool.observabilityScope
227-
)
215+
let result = try tsc_await {
216+
registryClient.publish(
217+
registryURL: registryURL,
218+
packageIdentity: self.packageIdentity,
219+
packageVersion: self.packageVersion,
220+
packageArchive: archivePath,
221+
packageMetadata: self.customMetadataPath,
222+
signature: signature,
223+
signatureFormat: self.signatureFormat,
224+
fileSystem: localFileSystem,
225+
observabilityScope: swiftTool.observabilityScope,
226+
callbackQueue: .sharedConcurrent,
227+
completion: $0
228+
)
229+
}
228230

229231
switch result {
230232
case .published(.none):
@@ -289,36 +291,3 @@ enum MetadataLocation {
289291
}
290292
}
291293
}
292-
293-
// TODO: migrate registry client to async
294-
extension RegistryClient {
295-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
296-
public func publish(
297-
registryURL: URL,
298-
packageIdentity: PackageIdentity,
299-
packageVersion: Version,
300-
packageArchive: AbsolutePath,
301-
packageMetadata: AbsolutePath?,
302-
signature: [UInt8]?,
303-
signatureFormat: SignatureFormat?,
304-
timeout: DispatchTimeInterval? = .none,
305-
fileSystem: FileSystem,
306-
observabilityScope: ObservabilityScope
307-
) async throws -> PublishResult {
308-
try await withCheckedThrowingContinuation { continuation in
309-
self.publish(
310-
registryURL: registryURL,
311-
packageIdentity: packageIdentity,
312-
packageVersion: packageVersion,
313-
packageArchive: packageArchive,
314-
packageMetadata: packageMetadata,
315-
signature: signature,
316-
signatureFormat: signatureFormat,
317-
fileSystem: fileSystem,
318-
observabilityScope: observabilityScope,
319-
callbackQueue: .sharedConcurrent,
320-
completion: continuation.resume(with:)
321-
)
322-
}
323-
}
324-
}

Sources/PackageRegistryTool/PackageRegistryTool+Sign.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import _Concurrency
14-
1513
import ArgumentParser
1614
import Basics
1715
import CoreCommands
1816
import PackageSigning
1917
import TSCBasic
2018
@_implementationOnly import X509 // FIXME: need this import or else SwiftSigningIdentity init at L139 fails
2119

20+
import struct Foundation.Data
21+
2222
extension SwiftPackageRegistryTool {
23-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
24-
struct Sign: AsyncSwiftCommand {
23+
struct Sign: SwiftCommand {
2524
static let configuration = CommandConfiguration(
2625
abstract: "Sign a package source archive"
2726
)
@@ -56,7 +55,7 @@ extension SwiftPackageRegistryTool {
5655
)
5756
var certificateChainPaths: [AbsolutePath] = []
5857

59-
func run(_ swiftTool: SwiftTool) async throws {
58+
func run(_ swiftTool: SwiftTool) throws {
6059
// Validate source archive path
6160
guard localFileSystem.exists(self.sourceArchivePath) else {
6261
throw StringError("Source archive not found at '\(self.sourceArchivePath)'.")
@@ -90,7 +89,7 @@ extension SwiftPackageRegistryTool {
9089
}
9190

9291
swiftTool.observabilityScope.emit(info: "signing the archive at '\(self.sourceArchivePath)'")
93-
try await PackageArchiveSigner.sign(
92+
try PackageArchiveSigner.sign(
9493
archivePath: self.sourceArchivePath,
9594
signaturePath: self.signaturePath,
9695
mode: signingMode,
@@ -108,7 +107,6 @@ extension SignatureFormat: ExpressibleByArgument {
108107
}
109108
}
110109

111-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
112110
public enum PackageArchiveSigner {
113111
@discardableResult
114112
public static func sign(
@@ -118,15 +116,15 @@ public enum PackageArchiveSigner {
118116
signatureFormat: SignatureFormat,
119117
fileSystem: FileSystem,
120118
observabilityScope: ObservabilityScope
121-
) async throws -> [UInt8] {
119+
) throws -> [UInt8] {
122120
let archiveData = try fileSystem.readFileContents(archivePath)
123121

124122
let signingIdentity: SigningIdentity
125123
let intermediateCertificates: [[UInt8]]
126124
switch mode {
127125
case .identityStore(let label, let intermediateCertPaths):
128126
let signingIdentityStore = SigningIdentityStore(observabilityScope: observabilityScope)
129-
let matches = await signingIdentityStore.find(by: label)
127+
let matches = signingIdentityStore.find(by: label)
130128
guard let identity = matches.first else {
131129
throw StringError("'\(label)' not found in the system identity store.")
132130
}
@@ -144,7 +142,7 @@ public enum PackageArchiveSigner {
144142
intermediateCertificates = try intermediateCertPaths.map { try fileSystem.readFileContents($0).contents }
145143
}
146144

147-
let signature = try await SignatureProvider.sign(
145+
let signature = try SignatureProvider.sign(
148146
content: archiveData.contents,
149147
identity: signingIdentity,
150148
intermediateCertificates: intermediateCertificates,

Sources/PackageRegistryTool/PackageRegistryTool.swift

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,30 @@ import TSCBasic
2020
import Workspace
2121

2222
@available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13, watchOS 6, *)
23-
public struct SwiftPackageRegistryTool: AsyncParsableCommand {
23+
public struct SwiftPackageRegistryTool: ParsableCommand {
2424
public static var configuration = CommandConfiguration(
2525
commandName: "package-registry",
2626
_superCommandName: "swift",
2727
abstract: "Interact with package registry and manage related configuration",
2828
discussion: "SEE ALSO: swift package",
2929
version: SwiftVersion.current.completeDisplayString,
30-
subcommands: Self.subcommands,
30+
subcommands:[
31+
Set.self,
32+
Unset.self,
33+
Login.self,
34+
Logout.self,
35+
Publish.self,
36+
Sign.self,
37+
],
3138
helpNames: [.short, .long, .customLong("help", withSingleDash: true)]
3239
)
3340

34-
private static var subcommands: [ParsableCommand.Type] {
35-
if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) {
36-
return [
37-
Set.self,
38-
Unset.self,
39-
Login.self,
40-
Logout.self,
41-
Publish.self,
42-
Sign.self,
43-
] as [ParsableCommand.Type]
44-
} else {
45-
return [
46-
Set.self,
47-
Unset.self,
48-
Login.self,
49-
Logout.self,
50-
] as [ParsableCommand.Type]
51-
}
52-
}
53-
5441
@OptionGroup()
5542
var globalOptions: GlobalOptions
5643

5744
public init() {}
5845

59-
struct Set: AsyncSwiftCommand {
46+
struct Set: SwiftCommand {
6047
static let configuration = CommandConfiguration(
6148
abstract: "Set a custom registry"
6249
)
@@ -77,7 +64,7 @@ public struct SwiftPackageRegistryTool: AsyncParsableCommand {
7764
self.url
7865
}
7966

80-
func run(_ swiftTool: SwiftTool) async throws {
67+
func run(_ swiftTool: SwiftTool) throws {
8168
try self.registryURL.validateRegistryURL()
8269

8370
let scope = try scope.map(PackageIdentity.Scope.init(validating:))
@@ -99,7 +86,7 @@ public struct SwiftPackageRegistryTool: AsyncParsableCommand {
9986
}
10087
}
10188

102-
struct Unset: AsyncSwiftCommand {
89+
struct Unset: SwiftCommand {
10390
static let configuration = CommandConfiguration(
10491
abstract: "Remove a configured registry"
10592
)
@@ -113,7 +100,7 @@ public struct SwiftPackageRegistryTool: AsyncParsableCommand {
113100
@Option(help: "Associate the registry with a given scope")
114101
var scope: String?
115102

116-
func run(_ swiftTool: SwiftTool) async throws {
103+
func run(_ swiftTool: SwiftTool) throws {
117104
let scope = try scope.map(PackageIdentity.Scope.init(validating:))
118105

119106
let unset: (inout RegistryConfiguration) throws -> Void = { configuration in

Sources/PackageSigning/SignatureProvider.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public enum SignatureProvider {
2727
intermediateCertificates: [[UInt8]],
2828
format: SignatureFormat,
2929
observabilityScope: ObservabilityScope
30-
) async throws -> [UInt8] {
30+
) throws -> [UInt8] {
3131
let provider = format.provider
32-
return try await provider.sign(
32+
return try provider.sign(
3333
content: content,
3434
identity: identity,
3535
intermediateCertificates: intermediateCertificates,
@@ -141,7 +141,7 @@ protocol SignatureProviderProtocol {
141141
identity: SigningIdentity,
142142
intermediateCertificates: [[UInt8]],
143143
observabilityScope: ObservabilityScope
144-
) async throws -> [UInt8]
144+
) throws -> [UInt8]
145145

146146
func status(
147147
signature: [UInt8],
@@ -165,7 +165,7 @@ struct CMSSignatureProvider: SignatureProviderProtocol {
165165
identity: SigningIdentity,
166166
intermediateCertificates: [[UInt8]],
167167
observabilityScope: ObservabilityScope
168-
) async throws -> [UInt8] {
168+
) throws -> [UInt8] {
169169
#if canImport(Security)
170170
if CFGetTypeID(identity as CFTypeRef) == SecIdentityGetTypeID() {
171171
let secIdentity = identity as! SecIdentity // !-safe because we ensure type above

Sources/PackageSigning/SigningIdentity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public struct SigningIdentityStore {
7979
self.observabilityScope = observabilityScope
8080
}
8181

82-
public func find(by label: String) async -> [SigningIdentity] {
82+
public func find(by label: String) -> [SigningIdentity] {
8383
#if os(macOS)
8484
// Find in Keychain
8585
let query: [String: Any] = [

Sources/swift-package-registry/runner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import PackageRegistryTool
1515

1616
@main
1717
struct Runner {
18-
static func main() async {
19-
await SwiftPackageRegistryTool.main()
18+
static func main() {
19+
SwiftPackageRegistryTool.main()
2020
}
2121
}

0 commit comments

Comments
 (0)