Skip to content

Commit 6e0e7ff

Browse files
committed
Migrate Linux code paths
1 parent e1d85bc commit 6e0e7ff

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public struct Linux: Platform {
323323
}
324324
}
325325

326-
public func install(_ ctx: SwiftlyCoreContext, from tmpFile: URL, version: ToolchainVersion, verbose: Bool) throws {
326+
public func install(_ ctx: SwiftlyCoreContext, from tmpFile: URL, version: ToolchainVersion, verbose: Bool) async throws {
327327
guard tmpFile.fileExists() else {
328328
throw SwiftlyError(message: "\(tmpFile) doesn't exist")
329329
}
@@ -332,7 +332,7 @@ public struct Linux: Platform {
332332
try FileManager.default.createDirectory(at: self.swiftlyToolchainsDir(ctx), withIntermediateDirectories: false)
333333
}
334334

335-
ctx.print("Extracting toolchain...")
335+
await ctx.print("Extracting toolchain...")
336336
let toolchainDir = self.swiftlyToolchainsDir(ctx).appendingPathComponent(version.name)
337337

338338
if toolchainDir.fileExists() {
@@ -347,15 +347,18 @@ public struct Linux: Platform {
347347
let destination = toolchainDir.appendingPathComponent(String(relativePath))
348348

349349
if verbose {
350-
ctx.print("\(destination.path)")
350+
// To avoid having to make extractArchive async this is a regular print
351+
// to stdout. Note that it is unlikely that the test mocking will require
352+
// capturing this output.
353+
print("\(destination.path)")
351354
}
352355

353356
// prepend /path/to/swiftlyHomeDir/toolchains/<toolchain> to each file name
354357
return destination
355358
}
356359
}
357360

358-
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: URL) throws {
361+
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: URL) async throws {
359362
guard archive.fileExists() else {
360363
throw SwiftlyError(message: "\(archive) doesn't exist")
361364
}
@@ -366,7 +369,7 @@ public struct Linux: Platform {
366369
}
367370
try FileManager.default.createDirectory(atPath: tmpDir.path, withIntermediateDirectories: true)
368371

369-
ctx.print("Extracting new swiftly...")
372+
await ctx.print("Extracting new swiftly...")
370373
try extractArchive(atPath: archive) { name in
371374
// Extract to the temporary directory
372375
tmpDir.appendingPathComponent(String(name))
@@ -392,7 +395,7 @@ public struct Linux: Platform {
392395

393396
public func verifySignature(_ ctx: SwiftlyCoreContext, archiveDownloadURL: URL, archive: URL, verbose: Bool) async throws {
394397
if verbose {
395-
ctx.print("Downloading toolchain signature...")
398+
await ctx.print("Downloading toolchain signature...")
396399
}
397400

398401
let sigFile = self.getTempFilePath()
@@ -406,7 +409,7 @@ public struct Linux: Platform {
406409
to: sigFile
407410
)
408411

409-
ctx.print("Verifying toolchain signature...")
412+
await ctx.print("Verifying toolchain signature...")
410413
do {
411414
if let mockedHomeDir = ctx.mockedHomeDir {
412415
try self.runProgram("gpg", "--verify", sigFile.path, archive.path, quiet: false, env: ["GNUPGHOME": mockedHomeDir.appendingPathComponent(".gnupg").path])
@@ -434,7 +437,7 @@ public struct Linux: Platform {
434437
\(selections)
435438
""")
436439

437-
let choice = ctx.readLine(prompt: "Pick one of the available selections [0-\(self.linuxPlatforms.count)] ") ?? "0"
440+
let choice = await ctx.readLine(prompt: "Pick one of the available selections [0-\(self.linuxPlatforms.count)] ") ?? "0"
438441

439442
guard let choiceNum = Int(choice) else {
440443
fatalError("Installation canceled")

Tests/SwiftlyTests/PlatformTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Testing
1111
let tmpDir = Swiftly.currentPlatform.getTempFilePath()
1212
try! FileManager.default.createDirectory(at: tmpDir, withIntermediateDirectories: true)
1313
let mockedToolchainFile = tmpDir.appendingPathComponent("swift-\(version).\(ext)")
14-
let mockedToolchain = try mockDownloader.makeMockedToolchain(toolchain: version, name: tmpDir.path)
14+
let mockedToolchain = try await mockDownloader.makeMockedToolchain(toolchain: version, name: tmpDir.path)
1515
try mockedToolchain.write(to: mockedToolchainFile)
1616

1717
return (mockedToolchainFile, version, tmpDir)

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public struct SwiftExecutable {
507507

508508
/// An `HTTPRequestExecutor` which will return a mocked response to any toolchain download requests.
509509
/// All other requests are performed using an actual HTTP client.
510-
public final class MockToolchainDownloader: HTTPRequestExecutor {
510+
public final actor MockToolchainDownloader: HTTPRequestExecutor {
511511
private static func releaseURLRegex() -> Regex<(Substring, Substring, Substring, Substring?)> {
512512
try! Regex("swift-(\\d+)\\.(\\d+)(?:\\.(\\d+))?-RELEASE")
513513
}

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
478478
try runProgram("productbuild", "--synthesize", "--package", pkgFile.path, distFile.path)
479479

480480
var distFileContents = try String(contentsOf: distFile, encoding: .utf8)
481-
distFileContents = distFileContents.replacingOccurrences(of: "<choices-outline>", with: "<domains enable_anywhere=\"false\" enable_currentUserHome=\"true\" enable_localSystem=\"false\"/><choices-outline>")
481+
distFileContents = distFileContents.replacingOccurrences(of: "<choices-outline>", with: "<title>swiftly</title><domains enable_anywhere=\"false\" enable_currentUserHome=\"true\" enable_localSystem=\"false\"/><choices-outline>")
482482
try distFileContents.write(to: distFile, atomically: true, encoding: .utf8)
483483

484484
if let cert = cert {

0 commit comments

Comments
 (0)