11import Foundation
2+ import Subprocess
23import SwiftlyCore
4+ import System
35import SystemPackage
46
57typealias sys = SwiftlyCore . SystemCommand
@@ -17,21 +19,21 @@ public struct SwiftPkgInfo: Codable {
1719public struct MacOS: Platform {
1820 public init ( ) { }
1921
20- public var defaultSwiftlyHomeDir : FilePath {
22+ public var defaultSwiftlyHomeDir : SystemPackage . FilePath {
2123 fs. home / " .swiftly "
2224 }
2325
24- public var defaultToolchainsDirectory : FilePath {
26+ public var defaultToolchainsDirectory : SystemPackage . FilePath {
2527 fs. home / " Library/Developer/Toolchains "
2628 }
2729
28- public func swiftlyBinDir( _ ctx: SwiftlyCoreContext ) -> FilePath {
30+ public func swiftlyBinDir( _ ctx: SwiftlyCoreContext ) -> SystemPackage . FilePath {
2931 ctx. mockedHomeDir. map { $0 / " bin " }
3032 ?? ProcessInfo . processInfo. environment [ " SWIFTLY_BIN_DIR " ] . map { FilePath ( $0) }
3133 ?? fs. home / " .swiftly/bin "
3234 }
3335
34- public func swiftlyToolchainsDir( _ ctx: SwiftlyCoreContext ) -> FilePath {
36+ public func swiftlyToolchainsDir( _ ctx: SwiftlyCoreContext ) -> SystemPackage . FilePath {
3537 ctx. mockedHomeDir. map { $0 / " Toolchains " }
3638 ?? ProcessInfo . processInfo. environment [ " SWIFTLY_TOOLCHAINS_DIR " ] . map { FilePath ( $0) }
3739 // This is where the installer will put the toolchains, and where Xcode can find them
@@ -55,7 +57,7 @@ public struct MacOS: Platform {
5557 }
5658
5759 public func install(
58- _ ctx: SwiftlyCoreContext , from tmpFile: FilePath , version: ToolchainVersion , verbose: Bool
60+ _ ctx: SwiftlyCoreContext , from tmpFile: SystemPackage . FilePath , version: ToolchainVersion , verbose: Bool
5961 ) async throws {
6062 guard try await fs. exists ( atPath: tmpFile) else {
6163 throw SwiftlyError ( message: " \( tmpFile) doesn't exist " )
@@ -71,7 +73,7 @@ public struct MacOS: Platform {
7173 // If the toolchains go into the default user location then we use the installer to install them
7274 await ctx. message ( " Installing package in user home directory... " )
7375
74- try await sys. installer ( . verbose, . pkg( tmpFile) , . target( " CurrentUserHomeDirectory " ) ) . run ( self , quiet : !verbose )
76+ try await sys. installer ( . verbose, . pkg( tmpFile) , . target( " CurrentUserHomeDirectory " ) ) . run ( )
7577 } else {
7678 // Otherwise, we extract the pkg into the requested toolchains directory.
7779 await ctx. message ( " Expanding pkg... " )
@@ -84,7 +86,7 @@ public struct MacOS: Platform {
8486
8587 await ctx. message ( " Checking package signature... " )
8688 do {
87- try await sys. pkgutil ( ) . checksignature ( pkg_path: tmpFile) . run ( self , quiet: !verbose)
89+ try await sys. pkgutil ( ) . checksignature ( pkg_path: tmpFile) . run ( quiet: !verbose)
8890 } catch {
8991 // If this is not a test that uses mocked toolchains then we must throw this error and abort installation
9092 guard ctx. mockedHomeDir != nil else {
@@ -94,7 +96,7 @@ public struct MacOS: Platform {
9496 // We permit the signature verification to fail during testing
9597 await ctx. message ( " Signature verification failed, which is allowable during testing with mocked toolchains " )
9698 }
97- try await sys. pkgutil ( . verbose) . expand ( pkg_path: tmpFile, dir_path: tmpDir) . run ( self , quiet : !verbose )
99+ try await sys. pkgutil ( . verbose) . expand ( pkg_path: tmpFile, dir_path: tmpDir) . run ( )
98100
99101 // There's a slight difference in the location of the special Payload file between official swift packages
100102 // and the ones that are mocked here in the test framework.
@@ -104,11 +106,11 @@ public struct MacOS: Platform {
104106 }
105107
106108 await ctx. message ( " Untarring pkg Payload... " )
107- try await sys. tar ( . directory( toolchainDir) ) . extract ( . verbose, . archive( payload) ) . run ( self , quiet: !verbose)
109+ try await sys. tar ( . directory( toolchainDir) ) . extract ( . verbose, . archive( payload) ) . run ( quiet: !verbose)
108110 }
109111 }
110112
111- public func extractSwiftlyAndInstall( _ ctx: SwiftlyCoreContext , from archive: FilePath ) async throws {
113+ public func extractSwiftlyAndInstall( _ ctx: SwiftlyCoreContext , from archive: SystemPackage . FilePath ) async throws {
112114 guard try await fs. exists ( atPath: archive) else {
113115 throw SwiftlyError ( message: " \( archive) doesn't exist " )
114116 }
@@ -120,16 +122,16 @@ public struct MacOS: Platform {
120122 try await sys. installer (
121123 . pkg( archive) ,
122124 . target( " CurrentUserHomeDirectory " )
123- ) . run ( self )
124- try ? await sys. pkgutil ( . volume( userHomeDir) ) . forget ( pkg_id: " org.swift.swiftly " ) . run ( self )
125+ ) . run ( )
126+ try ? await sys. pkgutil ( . volume( userHomeDir) ) . forget ( pkg_id: " org.swift.swiftly " ) . run ( )
125127 } else {
126128 let installDir = userHomeDir / " .swiftly "
127129 try await fs. mkdir ( . parents, atPath: installDir)
128130
129131 // In the case of a mock for testing purposes we won't use the installer, perferring a manual process because
130132 // the installer will not install to an arbitrary path, only a volume or user home directory.
131133 let tmpDir = fs. mktemp ( )
132- try await sys. pkgutil ( ) . expand ( pkg_path: archive, dir_path: tmpDir) . run ( self )
134+ try await sys. pkgutil ( ) . expand ( pkg_path: archive, dir_path: tmpDir) . run ( )
133135
134136 // There's a slight difference in the location of the special Payload file between official swift packages
135137 // and the ones that are mocked here in the test framework.
@@ -139,10 +141,10 @@ public struct MacOS: Platform {
139141 }
140142
141143 await ctx. message ( " Extracting the swiftly package into \( installDir) ... " )
142- try await sys. tar ( . directory( installDir) ) . extract ( . verbose, . archive( payload) ) . run ( self , quiet: false )
144+ try await sys. tar ( . directory( installDir) ) . extract ( . verbose, . archive( payload) ) . run ( quiet: false )
143145 }
144146
145- try await self . runProgram ( ( userHomeDir / " .swiftly/bin/swiftly " ) . string, " init " )
147+ _ = try await run ( . path ( System . FilePath ( ( userHomeDir / " .swiftly/bin/swiftly " ) . string) ) , arguments : [ " init " ] , input : . standardInput , output : . standardOutput , error : . standardError )
146148 }
147149
148150 public func uninstall( _ ctx: SwiftlyCoreContext , _ toolchain: ToolchainVersion , verbose: Bool )
@@ -164,22 +166,22 @@ public struct MacOS: Platform {
164166
165167 try await fs. remove ( atPath: toolchainDir)
166168
167- try ? await sys. pkgutil ( . volume( fs. home) ) . forget ( pkg_id: pkgInfo. CFBundleIdentifier) . run ( self , quiet: !verbose)
169+ try ? await sys. pkgutil ( . volume( fs. home) ) . forget ( pkg_id: pkgInfo. CFBundleIdentifier) . run ( quiet: !verbose)
168170 }
169171
170172 public func getExecutableName( ) -> String {
171173 " swiftly-macos-osx "
172174 }
173175
174176 public func verifyToolchainSignature(
175- _: SwiftlyCoreContext , toolchainFile _: ToolchainFile , archive _: FilePath , verbose _: Bool
177+ _: SwiftlyCoreContext , toolchainFile _: ToolchainFile , archive _: SystemPackage . FilePath , verbose _: Bool
176178 ) async throws {
177179 // No signature verification is required on macOS since the pkg files have their own signing
178180 // mechanism and the swift.org downloadables are trusted by stock macOS installations.
179181 }
180182
181183 public func verifySwiftlySignature(
182- _: SwiftlyCoreContext , archiveDownloadURL _: URL , archive _: FilePath , verbose _: Bool
184+ _: SwiftlyCoreContext , archiveDownloadURL _: URL , archive _: SystemPackage . FilePath , verbose _: Bool
183185 ) async throws {
184186 // No signature verification is required on macOS since the pkg files have their own signing
185187 // mechanism and the swift.org downloadables are trusted by stock macOS installations.
@@ -201,11 +203,11 @@ public struct MacOS: Platform {
201203 return " /bin/zsh "
202204 }
203205
204- public func findToolchainLocation( _ ctx: SwiftlyCoreContext , _ toolchain: ToolchainVersion ) async throws -> FilePath
206+ public func findToolchainLocation( _ ctx: SwiftlyCoreContext , _ toolchain: ToolchainVersion ) async throws -> SystemPackage . FilePath
205207 {
206208 if toolchain == . xcodeVersion {
207209 // Print the toolchain location with the help of xcrun
208- if let xcrunLocation = try ? await self . runProgramOutput ( " /usr/bin/xcrun " , " -f " , " swift " ) {
210+ if let xcrunLocation = try ? await run ( . path ( SystemPackage . FilePath ( " /usr/bin/xcrun " ) ) , arguments : [ " -f " , " swift " ] , output : . string ( limit : 1024 * 10 ) ) . standardOutput {
209211 return FilePath ( xcrunLocation. replacingOccurrences ( of: " \n " , with: " " ) ) . removingLastComponent ( ) . removingLastComponent ( ) . removingLastComponent ( )
210212 }
211213 }
0 commit comments