Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import PackagePlugin
@preconcurrency import PackagePlugin

@preconcurrency
enum GenerateDocsReferencePluginError: Error {
case unknownBuildConfiguration(String)
case buildFailed(String)
Expand Down
23 changes: 13 additions & 10 deletions Sources/LinuxPlatform/Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public struct Linux: Platform {

public func install(
_ ctx: SwiftlyCoreContext, from tmpFile: URL, version: ToolchainVersion, verbose: Bool
) throws {
) async throws {
guard tmpFile.fileExists() else {
throw SwiftlyError(message: "\(tmpFile) doesn't exist")
}
Expand All @@ -345,7 +345,7 @@ public struct Linux: Platform {
)
}

ctx.print("Extracting toolchain...")
await ctx.print("Extracting toolchain...")
let toolchainDir = self.swiftlyToolchainsDir(ctx).appendingPathComponent(version.name)

if toolchainDir.fileExists() {
Expand All @@ -360,15 +360,18 @@ public struct Linux: Platform {
let destination = toolchainDir.appendingPathComponent(String(relativePath))

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

// prepend /path/to/swiftlyHomeDir/toolchains/<toolchain> to each file name
return destination
}
}

public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: URL) throws {
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: URL) async throws {
guard archive.fileExists() else {
throw SwiftlyError(message: "\(archive) doesn't exist")
}
Expand All @@ -379,7 +382,7 @@ public struct Linux: Platform {
}
try FileManager.default.createDirectory(atPath: tmpDir.path, withIntermediateDirectories: true)

ctx.print("Extracting new swiftly...")
await ctx.print("Extracting new swiftly...")
try extractArchive(atPath: archive) { name in
// Extract to the temporary directory
tmpDir.appendingPathComponent(String(name))
Expand Down Expand Up @@ -409,7 +412,7 @@ public struct Linux: Platform {
_ ctx: SwiftlyCoreContext, toolchainFile: ToolchainFile, archive: URL, verbose: Bool
) async throws {
if verbose {
ctx.print("Downloading toolchain signature...")
await ctx.print("Downloading toolchain signature...")
}

let sigFile = self.getTempFilePath()
Expand All @@ -420,7 +423,7 @@ public struct Linux: Platform {

try await ctx.httpClient.getSwiftToolchainFileSignature(toolchainFile).download(to: sigFile)

ctx.print("Verifying toolchain signature...")
await ctx.print("Verifying toolchain signature...")
do {
if let mockedHomeDir = ctx.mockedHomeDir {
try self.runProgram(
Expand All @@ -439,7 +442,7 @@ public struct Linux: Platform {
_ ctx: SwiftlyCoreContext, archiveDownloadURL: URL, archive: URL, verbose: Bool
) async throws {
if verbose {
ctx.print("Downloading swiftly signature...")
await ctx.print("Downloading swiftly signature...")
}

let sigFile = self.getTempFilePath()
Expand All @@ -452,7 +455,7 @@ public struct Linux: Platform {
url: archiveDownloadURL.appendingPathExtension("sig")
).download(to: sigFile)

ctx.print("Verifying swiftly signature...")
await ctx.print("Verifying swiftly signature...")
do {
if let mockedHomeDir = ctx.mockedHomeDir {
try self.runProgram(
Expand Down Expand Up @@ -492,7 +495,7 @@ public struct Linux: Platform {
""")

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

guard let choiceNum = Int(choice) else {
Expand Down
18 changes: 9 additions & 9 deletions Sources/MacOSPlatform/MacOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct MacOS: Platform {

public func install(
_ ctx: SwiftlyCoreContext, from tmpFile: URL, version: ToolchainVersion, verbose: Bool
) throws {
) async throws {
guard tmpFile.fileExists() else {
throw SwiftlyError(message: "\(tmpFile) doesn't exist")
}
Expand All @@ -63,15 +63,15 @@ public struct MacOS: Platform {
}

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

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

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

ctx.print("Extracting the swiftly package...")
await ctx.print("Extracting the swiftly package...")
try runProgram("installer", "-pkg", archive.path, "-target", "CurrentUserHomeDirectory")
try? runProgram("pkgutil", "--volume", homeDir.path, "--forget", "org.swift.swiftly")
} else {
Expand All @@ -127,17 +127,17 @@ public struct MacOS: Platform {
throw SwiftlyError(message: "Payload file could not be found at \(tmpDir).")
}

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

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

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

let toolchainDir = self.swiftlyToolchainsDir(ctx).appendingPathComponent(
"\(toolchain.identifier).xctoolchain", isDirectory: true
Expand Down
20 changes: 10 additions & 10 deletions Sources/Swiftly/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import SwiftlyCore

struct Init: SwiftlyCommand {
public static var configuration = CommandConfiguration(
public static let configuration = CommandConfiguration(
abstract: "Perform swiftly initialization into your user account."
)

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

// Move our executable over to the correct place
try Swiftly.currentPlatform.installSwiftlyBin(ctx)
try await Swiftly.currentPlatform.installSwiftlyBin(ctx)

// Update and save the version
config.version = SwiftlyCore.version
Expand Down Expand Up @@ -113,9 +113,9 @@ struct Init: SwiftlyCommand {
"""
}

ctx.print(msg)
await ctx.print(msg)

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

// Move our executable over to the correct place
try Swiftly.currentPlatform.installSwiftlyBin(ctx)
try await Swiftly.currentPlatform.installSwiftlyBin(ctx)

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

if !noModifyProfile {
ctx.print("Updating profile...")
await ctx.print("Updating profile...")

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

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

if !quietShellFollowup {
ctx.print("""
await ctx.print("""
To begin using installed swiftly from your current shell, first run the following command:
\(sourceLine)

Expand All @@ -272,7 +272,7 @@ struct Init: SwiftlyCommand {

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

if let postInstall {
ctx.print("""
await ctx.print("""
There are some dependencies that should be installed before using this toolchain.
You can run the following script as the system administrator (e.g. root) to prepare
your system:
Expand Down
30 changes: 15 additions & 15 deletions Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import _StringProcessing
import ArgumentParser
import Foundation
import SwiftlyCore
import TSCBasic
@preconcurrency import TSCBasic
import TSCUtility

struct Install: SwiftlyCommand {
public static var configuration = CommandConfiguration(
public static let configuration = CommandConfiguration(
abstract: "Install a new toolchain."
)

Expand Down Expand Up @@ -129,7 +129,7 @@ struct Install: SwiftlyCommand {

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

Expand All @@ -182,7 +182,7 @@ struct Install: SwiftlyCommand {
requireSignatureValidation: verifySignature
)

ctx.print("Installing \(version)")
await ctx.print("Installing \(version)")

let tmpFile = Swiftly.currentPlatform.getTempFilePath()
FileManager.default.createFile(atPath: tmpFile.path, contents: nil)
Expand Down Expand Up @@ -272,7 +272,7 @@ struct Install: SwiftlyCommand {
)
}

try Swiftly.currentPlatform.install(ctx, from: tmpFile, version: version, verbose: verbose)
try await Swiftly.currentPlatform.install(ctx, from: tmpFile, version: version, verbose: verbose)

var pathChanged = false

Expand All @@ -297,19 +297,19 @@ struct Install: SwiftlyCommand {
let overwrite = Set(toolchainBinDirContents).subtracting(existingProxies).intersection(
swiftlyBinDirContents)
if !overwrite.isEmpty && !assumeYes {
ctx.print("The following existing executables will be overwritten:")
await ctx.print("The following existing executables will be overwritten:")

for executable in overwrite {
ctx.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
await ctx.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
}

guard ctx.promptForConfirmation(defaultBehavior: false) else {
guard await ctx.promptForConfirmation(defaultBehavior: false) else {
throw SwiftlyError(message: "Toolchain installation has been cancelled")
}
}

if verbose {
ctx.print("Setting up toolchain proxies...")
await ctx.print("Setting up toolchain proxies...")
}

let proxiesToCreate = Set(toolchainBinDirContents).subtracting(swiftlyBinDirContents).union(
Expand Down Expand Up @@ -346,10 +346,10 @@ struct Install: SwiftlyCommand {
if config.inUse == nil {
config.inUse = version
try config.save(ctx)
ctx.print("The global default toolchain has been set to `\(version)`")
await ctx.print("The global default toolchain has been set to `\(version)`")
}

ctx.print("\(version) installed successfully!")
await ctx.print("\(version) installed successfully!")
return (postInstallScript, pathChanged)
}

Expand All @@ -359,7 +359,7 @@ struct Install: SwiftlyCommand {
{
switch selector {
case .latest:
ctx.print("Fetching the latest stable Swift release...")
await ctx.print("Fetching the latest stable Swift release...")

guard
let release = try await ctx.httpClient.getReleaseToolchains(
Expand All @@ -382,7 +382,7 @@ struct Install: SwiftlyCommand {
return .stable(ToolchainVersion.StableRelease(major: major, minor: minor, patch: patch))
}

ctx.print("Fetching the latest stable Swift \(major).\(minor) release...")
await ctx.print("Fetching the latest stable Swift \(major).\(minor) release...")
// If a patch was not provided, perform a lookup to get the latest patch release
// of the provided major/minor version pair.
let toolchain = try await ctx.httpClient.getReleaseToolchains(
Expand All @@ -402,7 +402,7 @@ struct Install: SwiftlyCommand {
return ToolchainVersion(snapshotBranch: branch, date: date)
}

ctx.print("Fetching the latest \(branch) branch snapshot...")
await ctx.print("Fetching the latest \(branch) branch snapshot...")

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