Skip to content

Commit e1d85bc

Browse files
committed
Migrate swiftly to Swift 6 with concurrency checks
1 parent 46fb64f commit e1d85bc

21 files changed

+177
-167
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.10
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

Plugins/GenerateDocsReference/GenerateDocsReferenceError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
2-
import PackagePlugin
2+
@preconcurrency import PackagePlugin
33

4+
@preconcurrency
45
enum GenerateDocsReferencePluginError: Error {
56
case unknownBuildConfiguration(String)
67
case buildFailed(String)

Sources/MacOSPlatform/MacOS.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct MacOS: Platform {
4444
nil
4545
}
4646

47-
public func install(_ ctx: SwiftlyCoreContext, from tmpFile: URL, version: ToolchainVersion, verbose: Bool) throws {
47+
public func install(_ ctx: SwiftlyCoreContext, from tmpFile: URL, version: ToolchainVersion, verbose: Bool) async throws {
4848
guard tmpFile.fileExists() else {
4949
throw SwiftlyError(message: "\(tmpFile) doesn't exist")
5050
}
@@ -54,12 +54,12 @@ public struct MacOS: Platform {
5454
}
5555

5656
if ctx.mockedHomeDir == nil {
57-
ctx.print("Installing package in user home directory...")
57+
await ctx.print("Installing package in user home directory...")
5858
try runProgram("installer", "-verbose", "-pkg", tmpFile.path, "-target", "CurrentUserHomeDirectory", quiet: !verbose)
5959
} else {
6060
// In the case of a mock for testing purposes we won't use the installer, perferring a manual process because
6161
// the installer will not install to an arbitrary path, only a volume or user home directory.
62-
ctx.print("Expanding pkg...")
62+
await ctx.print("Expanding pkg...")
6363
let tmpDir = self.getTempFilePath()
6464
let toolchainDir = self.swiftlyToolchainsDir(ctx).appendingPathComponent("\(version.identifier).xctoolchain", isDirectory: true)
6565
if !toolchainDir.fileExists() {
@@ -73,12 +73,12 @@ public struct MacOS: Platform {
7373
payload = tmpDir.appendingPathComponent("\(version.identifier)-osx-package.pkg/Payload")
7474
}
7575

76-
ctx.print("Untarring pkg Payload...")
76+
await ctx.print("Untarring pkg Payload...")
7777
try runProgram("tar", "-C", toolchainDir.path, "-xvf", payload.path, quiet: !verbose)
7878
}
7979
}
8080

81-
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: URL) throws {
81+
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: URL) async throws {
8282
guard archive.fileExists() else {
8383
throw SwiftlyError(message: "\(archive) doesn't exist")
8484
}
@@ -88,7 +88,7 @@ public struct MacOS: Platform {
8888
if ctx.mockedHomeDir == nil {
8989
homeDir = FileManager.default.homeDirectoryForCurrentUser
9090

91-
ctx.print("Extracting the swiftly package...")
91+
await ctx.print("Extracting the swiftly package...")
9292
try runProgram("installer", "-pkg", archive.path, "-target", "CurrentUserHomeDirectory")
9393
try? runProgram("pkgutil", "--volume", homeDir.path, "--forget", "org.swift.swiftly")
9494
} else {
@@ -109,15 +109,15 @@ public struct MacOS: Platform {
109109
throw SwiftlyError(message: "Payload file could not be found at \(tmpDir).")
110110
}
111111

112-
ctx.print("Extracting the swiftly package into \(installDir.path)...")
112+
await ctx.print("Extracting the swiftly package into \(installDir.path)...")
113113
try runProgram("tar", "-C", installDir.path, "-xvf", payload.path, quiet: false)
114114
}
115115

116116
try self.runProgram(homeDir.appendingPathComponent(".swiftly/bin/swiftly").path, "init")
117117
}
118118

119-
public func uninstall(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion, verbose: Bool) throws {
120-
ctx.print("Uninstalling package in user home directory...")
119+
public func uninstall(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion, verbose: Bool) async throws {
120+
await ctx.print("Uninstalling package in user home directory...")
121121

122122
let toolchainDir = self.swiftlyToolchainsDir(ctx).appendingPathComponent("\(toolchain.identifier).xctoolchain", isDirectory: true)
123123

Sources/Swiftly/Init.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
import SwiftlyCore
44

55
struct Init: SwiftlyCommand {
6-
public static var configuration = CommandConfiguration(
6+
public static let configuration = CommandConfiguration(
77
abstract: "Perform swiftly initialization into your user account."
88
)
99

@@ -53,7 +53,7 @@ struct Init: SwiftlyCommand {
5353
// This is a simple upgrade from the 0.4.0 pre-releases, or 1.x
5454

5555
// Move our executable over to the correct place
56-
try Swiftly.currentPlatform.installSwiftlyBin(ctx)
56+
try await Swiftly.currentPlatform.installSwiftlyBin(ctx)
5757

5858
// Update and save the version
5959
config.version = SwiftlyCore.version
@@ -113,9 +113,9 @@ struct Init: SwiftlyCommand {
113113
"""
114114
}
115115

116-
ctx.print(msg)
116+
await ctx.print(msg)
117117

118-
guard ctx.promptForConfirmation(defaultBehavior: true) else {
118+
guard await ctx.promptForConfirmation(defaultBehavior: true) else {
119119
throw SwiftlyError(message: "swiftly installation has been cancelled")
120120
}
121121
}
@@ -177,10 +177,10 @@ struct Init: SwiftlyCommand {
177177
guard var config else { throw SwiftlyError(message: "Configuration could not be set") }
178178

179179
// Move our executable over to the correct place
180-
try Swiftly.currentPlatform.installSwiftlyBin(ctx)
180+
try await Swiftly.currentPlatform.installSwiftlyBin(ctx)
181181

182182
if overwrite || !FileManager.default.fileExists(atPath: envFile.path) {
183-
ctx.print("Creating shell environment file for the user...")
183+
await ctx.print("Creating shell environment file for the user...")
184184
var env = ""
185185
if shell.hasSuffix("fish") {
186186
env = """
@@ -206,7 +206,7 @@ struct Init: SwiftlyCommand {
206206
}
207207

208208
if !noModifyProfile {
209-
ctx.print("Updating profile...")
209+
await ctx.print("Updating profile...")
210210

211211
let userHome = ctx.mockedHomeDir ?? FileManager.default.homeDirectoryForCurrentUser
212212

@@ -262,7 +262,7 @@ struct Init: SwiftlyCommand {
262262
try Data(sourceLine.utf8).append(to: profileHome)
263263

264264
if !quietShellFollowup {
265-
ctx.print("""
265+
await ctx.print("""
266266
To begin using installed swiftly from your current shell, first run the following command:
267267
\(sourceLine)
268268
@@ -272,7 +272,7 @@ struct Init: SwiftlyCommand {
272272

273273
// Fish doesn't have path caching, so this might only be needed for bash/zsh
274274
if pathChanged && !quietShellFollowup && !shell.hasSuffix("fish") {
275-
ctx.print("""
275+
await ctx.print("""
276276
Your shell caches items on your path for better performance. Swiftly has added
277277
items to your path that may not get picked up right away. You can update your
278278
shell's environment by running
@@ -285,7 +285,7 @@ struct Init: SwiftlyCommand {
285285
}
286286

287287
if let postInstall {
288-
ctx.print("""
288+
await ctx.print("""
289289
There are some dependencies that should be installed before using this toolchain.
290290
You can run the following script as the system administrator (e.g. root) to prepare
291291
your system:

Sources/Swiftly/Install.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import _StringProcessing
22
import ArgumentParser
33
import Foundation
4-
import TSCBasic
4+
@preconcurrency import TSCBasic
55
import TSCUtility
66

77
import SwiftlyCore
88

99
struct Install: SwiftlyCommand {
10-
public static var configuration = CommandConfiguration(
10+
public static let configuration = CommandConfiguration(
1111
abstract: "Install a new toolchain."
1212
)
1313

@@ -120,7 +120,7 @@ struct Install: SwiftlyCommand {
120120

121121
// Fish doesn't cache its path, so this instruction is not necessary.
122122
if pathChanged && !shell.hasSuffix("fish") {
123-
ctx.print("""
123+
await ctx.print("""
124124
NOTE: Swiftly has updated some elements in your path and your shell may not yet be
125125
aware of the changes. You can update your shell's environment by running
126126
@@ -157,7 +157,7 @@ struct Install: SwiftlyCommand {
157157
assumeYes: Bool
158158
) async throws -> (postInstall: String?, pathChanged: Bool) {
159159
guard !config.installedToolchains.contains(version) else {
160-
ctx.print("\(version) is already installed.")
160+
await ctx.print("\(version) is already installed.")
161161
return (nil, false)
162162
}
163163

@@ -166,7 +166,7 @@ struct Install: SwiftlyCommand {
166166
// script for the user to run afterwards.
167167
let postInstallScript = try await Swiftly.currentPlatform.verifySystemPrerequisitesForInstall(ctx, platformName: config.platform.name, version: version, requireSignatureValidation: verifySignature)
168168

169-
ctx.print("Installing \(version)")
169+
await ctx.print("Installing \(version)")
170170

171171
let tmpFile = Swiftly.currentPlatform.getTempFilePath()
172172
FileManager.default.createFile(atPath: tmpFile.path, contents: nil)
@@ -258,7 +258,7 @@ struct Install: SwiftlyCommand {
258258
)
259259
}
260260

261-
try Swiftly.currentPlatform.install(ctx, from: tmpFile, version: version, verbose: verbose)
261+
try await Swiftly.currentPlatform.install(ctx, from: tmpFile, version: version, verbose: verbose)
262262

263263
var pathChanged = false
264264

@@ -279,19 +279,19 @@ struct Install: SwiftlyCommand {
279279

280280
let overwrite = Set(toolchainBinDirContents).subtracting(existingProxies).intersection(swiftlyBinDirContents)
281281
if !overwrite.isEmpty && !assumeYes {
282-
ctx.print("The following existing executables will be overwritten:")
282+
await ctx.print("The following existing executables will be overwritten:")
283283

284284
for executable in overwrite {
285-
ctx.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
285+
await ctx.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
286286
}
287287

288-
guard ctx.promptForConfirmation(defaultBehavior: false) else {
288+
guard await ctx.promptForConfirmation(defaultBehavior: false) else {
289289
throw SwiftlyError(message: "Toolchain installation has been cancelled")
290290
}
291291
}
292292

293293
if verbose {
294-
ctx.print("Setting up toolchain proxies...")
294+
await ctx.print("Setting up toolchain proxies...")
295295
}
296296

297297
let proxiesToCreate = Set(toolchainBinDirContents).subtracting(swiftlyBinDirContents).union(overwrite)
@@ -327,18 +327,18 @@ struct Install: SwiftlyCommand {
327327
if config.inUse == nil {
328328
config.inUse = version
329329
try config.save(ctx)
330-
ctx.print("The global default toolchain has been set to `\(version)`")
330+
await ctx.print("The global default toolchain has been set to `\(version)`")
331331
}
332332

333-
ctx.print("\(version) installed successfully!")
333+
await ctx.print("\(version) installed successfully!")
334334
return (postInstallScript, pathChanged)
335335
}
336336

337337
/// Utilize the swift.org API along with the provided selector to select a toolchain for install.
338338
public static func resolve(_ ctx: SwiftlyCoreContext, config: Config, selector: ToolchainSelector) async throws -> ToolchainVersion {
339339
switch selector {
340340
case .latest:
341-
ctx.print("Fetching the latest stable Swift release...")
341+
await ctx.print("Fetching the latest stable Swift release...")
342342

343343
guard let release = try await ctx.httpClient.getReleaseToolchains(platform: config.platform, limit: 1).first else {
344344
throw SwiftlyError(message: "couldn't get latest releases")
@@ -356,7 +356,7 @@ struct Install: SwiftlyCommand {
356356
return .stable(ToolchainVersion.StableRelease(major: major, minor: minor, patch: patch))
357357
}
358358

359-
ctx.print("Fetching the latest stable Swift \(major).\(minor) release...")
359+
await ctx.print("Fetching the latest stable Swift \(major).\(minor) release...")
360360
// If a patch was not provided, perform a lookup to get the latest patch release
361361
// of the provided major/minor version pair.
362362
let toolchain = try await ctx.httpClient.getReleaseToolchains(platform: config.platform, limit: 1) { release in
@@ -374,7 +374,7 @@ struct Install: SwiftlyCommand {
374374
return ToolchainVersion(snapshotBranch: branch, date: date)
375375
}
376376

377-
ctx.print("Fetching the latest \(branch) branch snapshot...")
377+
await ctx.print("Fetching the latest \(branch) branch snapshot...")
378378

379379
// If a date was not provided, perform a lookup to find the most recent snapshot
380380
// for the given branch.

Sources/Swiftly/List.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import SwiftlyCore
33

44
struct List: SwiftlyCommand {
5-
public static var configuration = CommandConfiguration(
5+
public static let configuration = CommandConfiguration(
66
abstract: "List installed toolchains."
77
)
88

@@ -56,7 +56,7 @@ struct List: SwiftlyCommand {
5656
if toolchain == config.inUse {
5757
message += " (default)"
5858
}
59-
ctx.print(message)
59+
await ctx.print(message)
6060
}
6161

6262
if let selector {
@@ -76,26 +76,26 @@ struct List: SwiftlyCommand {
7676
}
7777

7878
let message = "Installed \(modifier) toolchains"
79-
ctx.print(message)
80-
ctx.print(String(repeating: "-", count: message.count))
79+
await ctx.print(message)
80+
await ctx.print(String(repeating: "-", count: message.count))
8181
for toolchain in toolchains {
82-
printToolchain(toolchain)
82+
await printToolchain(toolchain)
8383
}
8484
} else {
85-
ctx.print("Installed release toolchains")
86-
ctx.print("----------------------------")
85+
await ctx.print("Installed release toolchains")
86+
await ctx.print("----------------------------")
8787
for toolchain in toolchains {
8888
guard toolchain.isStableRelease() else {
8989
continue
9090
}
91-
printToolchain(toolchain)
91+
await printToolchain(toolchain)
9292
}
9393

94-
ctx.print("")
95-
ctx.print("Installed snapshot toolchains")
96-
ctx.print("-----------------------------")
94+
await ctx.print("")
95+
await ctx.print("Installed snapshot toolchains")
96+
await ctx.print("-----------------------------")
9797
for toolchain in toolchains where toolchain.isSnapshot() {
98-
printToolchain(toolchain)
98+
await printToolchain(toolchain)
9999
}
100100
}
101101
}

Sources/Swiftly/ListAvailable.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import SwiftlyCore
33

44
struct ListAvailable: SwiftlyCommand {
5-
public static var configuration = CommandConfiguration(
5+
public static let configuration = CommandConfiguration(
66
abstract: "List toolchains available for install."
77
)
88

@@ -80,7 +80,7 @@ struct ListAvailable: SwiftlyCommand {
8080
} else if installedToolchains.contains(toolchain) {
8181
message += " (installed)"
8282
}
83-
ctx.print(message)
83+
await ctx.print(message)
8484
}
8585

8686
if let selector {
@@ -100,16 +100,16 @@ struct ListAvailable: SwiftlyCommand {
100100
}
101101

102102
let message = "Available \(modifier) toolchains"
103-
ctx.print(message)
104-
ctx.print(String(repeating: "-", count: message.count))
103+
await ctx.print(message)
104+
await ctx.print(String(repeating: "-", count: message.count))
105105
for toolchain in toolchains {
106-
printToolchain(toolchain)
106+
await printToolchain(toolchain)
107107
}
108108
} else {
109109
print("Available release toolchains")
110110
print("----------------------------")
111111
for toolchain in toolchains where toolchain.isStableRelease() {
112-
printToolchain(toolchain)
112+
await printToolchain(toolchain)
113113
}
114114
}
115115
}

Sources/Swiftly/Proxy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public enum Proxy {
6868
} catch let terminated as RunProgramError {
6969
exit(terminated.exitCode)
7070
} catch let error as SwiftlyError {
71-
ctx.print(error.message)
71+
await ctx.print(error.message)
7272
exit(1)
7373
} catch {
74-
ctx.print("\(error)")
74+
await ctx.print("\(error)")
7575
exit(1)
7676
}
7777
}

0 commit comments

Comments
 (0)