11import Foundation
22import Subprocess
33import SwiftlyCore
4- import System
54import SystemPackage
65
76typealias sys = SwiftlyCore . SystemCommand
@@ -19,21 +18,21 @@ public struct SwiftPkgInfo: Codable {
1918public struct MacOS: Platform {
2019 public init ( ) { }
2120
22- public var defaultSwiftlyHomeDir : SystemPackage . FilePath {
21+ public var defaultSwiftlyHomeDir : FilePath {
2322 fs. home / " .swiftly "
2423 }
2524
26- public var defaultToolchainsDirectory : SystemPackage . FilePath {
25+ public var defaultToolchainsDirectory : FilePath {
2726 fs. home / " Library/Developer/Toolchains "
2827 }
2928
30- public func swiftlyBinDir( _ ctx: SwiftlyCoreContext ) -> SystemPackage . FilePath {
29+ public func swiftlyBinDir( _ ctx: SwiftlyCoreContext ) -> FilePath {
3130 ctx. mockedHomeDir. map { $0 / " bin " }
3231 ?? ProcessInfo . processInfo. environment [ " SWIFTLY_BIN_DIR " ] . map { FilePath ( $0) }
3332 ?? fs. home / " .swiftly/bin "
3433 }
3534
36- public func swiftlyToolchainsDir( _ ctx: SwiftlyCoreContext ) -> SystemPackage . FilePath {
35+ public func swiftlyToolchainsDir( _ ctx: SwiftlyCoreContext ) -> FilePath {
3736 ctx. mockedHomeDir. map { $0 / " Toolchains " }
3837 ?? ProcessInfo . processInfo. environment [ " SWIFTLY_TOOLCHAINS_DIR " ] . map { FilePath ( $0) }
3938 // This is where the installer will put the toolchains, and where Xcode can find them
@@ -57,7 +56,7 @@ public struct MacOS: Platform {
5756 }
5857
5958 public func install(
60- _ ctx: SwiftlyCoreContext , from tmpFile: SystemPackage . FilePath , version: ToolchainVersion , verbose: Bool
59+ _ ctx: SwiftlyCoreContext , from tmpFile: FilePath , version: ToolchainVersion , verbose: Bool
6160 ) async throws {
6261 guard try await fs. exists ( atPath: tmpFile) else {
6362 throw SwiftlyError ( message: " \( tmpFile) doesn't exist " )
@@ -110,7 +109,7 @@ public struct MacOS: Platform {
110109 }
111110 }
112111
113- public func extractSwiftlyAndInstall( _ ctx: SwiftlyCoreContext , from archive: SystemPackage . FilePath ) async throws {
112+ public func extractSwiftlyAndInstall( _ ctx: SwiftlyCoreContext , from archive: FilePath ) async throws {
114113 guard try await fs. exists ( atPath: archive) else {
115114 throw SwiftlyError ( message: " \( archive) doesn't exist " )
116115 }
@@ -144,7 +143,13 @@ public struct MacOS: Platform {
144143 try await sys. tar ( . directory( installDir) ) . extract ( . verbose, . archive( payload) ) . run ( quiet: false )
145144 }
146145
147- _ = try await run ( . path( System . FilePath ( ( userHomeDir / " .swiftly/bin/swiftly " ) . string) ) , arguments: [ " init " ] , input: . standardInput, output: . standardOutput, error: . standardError)
146+ let config = Configuration (
147+ . path( FilePath ( ( userHomeDir / " .swiftly/bin/swiftly " ) . string) ) , arguments: [ " init " ]
148+ )
149+ let result = try await run ( config, input: . standardInput, output: . standardOutput, error: . standardError)
150+ if !result. terminationStatus. isSuccess {
151+ throw RunProgramError ( terminationStatus: result. terminationStatus, config: config)
152+ }
148153 }
149154
150155 public func uninstall( _ ctx: SwiftlyCoreContext , _ toolchain: ToolchainVersion , verbose: Bool )
@@ -174,14 +179,14 @@ public struct MacOS: Platform {
174179 }
175180
176181 public func verifyToolchainSignature(
177- _: SwiftlyCoreContext , toolchainFile _: ToolchainFile , archive _: SystemPackage . FilePath , verbose _: Bool
182+ _: SwiftlyCoreContext , toolchainFile _: ToolchainFile , archive _: FilePath , verbose _: Bool
178183 ) async throws {
179184 // No signature verification is required on macOS since the pkg files have their own signing
180185 // mechanism and the swift.org downloadables are trusted by stock macOS installations.
181186 }
182187
183188 public func verifySwiftlySignature(
184- _: SwiftlyCoreContext , archiveDownloadURL _: URL , archive _: SystemPackage . FilePath , verbose _: Bool
189+ _: SwiftlyCoreContext , archiveDownloadURL _: URL , archive _: FilePath , verbose _: Bool
185190 ) async throws {
186191 // No signature verification is required on macOS since the pkg files have their own signing
187192 // mechanism and the swift.org downloadables are trusted by stock macOS installations.
@@ -203,11 +208,11 @@ public struct MacOS: Platform {
203208 return " /bin/zsh "
204209 }
205210
206- public func findToolchainLocation( _ ctx: SwiftlyCoreContext , _ toolchain: ToolchainVersion ) async throws -> SystemPackage . FilePath
211+ public func findToolchainLocation( _ ctx: SwiftlyCoreContext , _ toolchain: ToolchainVersion ) async throws -> FilePath
207212 {
208213 if toolchain == . xcodeVersion {
209214 // Print the toolchain location with the help of xcrun
210- if let xcrunLocation = try ? await run ( . path( SystemPackage . FilePath ( " /usr/bin/xcrun " ) ) , arguments: [ " -f " , " swift " ] , output: . string( limit: 1024 * 10 ) ) . standardOutput {
215+ if let xcrunLocation = try ? await run ( . path( FilePath ( " /usr/bin/xcrun " ) ) , arguments: [ " -f " , " swift " ] , output: . string( limit: 1024 * 10 ) ) . standardOutput {
211216 return FilePath ( xcrunLocation. replacingOccurrences ( of: " \n " , with: " " ) ) . removingLastComponent ( ) . removingLastComponent ( ) . removingLastComponent ( )
212217 }
213218 }
0 commit comments