@@ -29,25 +29,21 @@ public struct Linux: Platform {
2929 }
3030 }
3131
32- public var swiftlyBinDir : URL {
33- SwiftlyCore . mockedHomeDir. map { $0. appendingPathComponent ( " bin " , isDirectory: true ) }
32+ public func swiftlyBinDir( _ ctx : SwiftlyCoreContext ) -> URL {
33+ ctx . mockedHomeDir. map { $0. appendingPathComponent ( " bin " , isDirectory: true ) }
3434 ?? ProcessInfo . processInfo. environment [ " SWIFTLY_BIN_DIR " ] . map { URL ( fileURLWithPath: $0) }
3535 ?? FileManager . default. homeDirectoryForCurrentUser
3636 . appendingPathComponent ( " .local/share/swiftly/bin " , isDirectory: true )
3737 }
3838
39- public var swiftlyToolchainsDir : URL {
40- self . swiftlyHomeDir. appendingPathComponent ( " toolchains " , isDirectory: true )
39+ public func swiftlyToolchainsDir( _ ctx : SwiftlyCoreContext ) -> URL {
40+ self . swiftlyHomeDir ( ctx ) . appendingPathComponent ( " toolchains " , isDirectory: true )
4141 }
4242
4343 public var toolchainFileExtension : String {
4444 " tar.gz "
4545 }
4646
47- public func isSystemDependencyPresent( _: SystemDependency ) -> Bool {
48- true
49- }
50-
5147 private static let skipVerificationMessage : String = " To skip signature verification, specify the --no-verify flag. "
5248
5349 public func verifySwiftlySystemPrerequisites( ) throws {
@@ -330,17 +326,17 @@ public struct Linux: Platform {
330326 }
331327 }
332328
333- public func install( from tmpFile: URL , version: ToolchainVersion , verbose: Bool ) throws {
329+ public func install( _ ctx : SwiftlyCoreContext , from tmpFile: URL , version: ToolchainVersion , verbose: Bool ) throws {
334330 guard tmpFile. fileExists ( ) else {
335331 throw SwiftlyError ( message: " \( tmpFile) doesn't exist " )
336332 }
337333
338- if !self . swiftlyToolchainsDir. fileExists ( ) {
339- try FileManager . default. createDirectory ( at: self . swiftlyToolchainsDir, withIntermediateDirectories: false )
334+ if !self . swiftlyToolchainsDir ( ctx ) . fileExists ( ) {
335+ try FileManager . default. createDirectory ( at: self . swiftlyToolchainsDir ( ctx ) , withIntermediateDirectories: false )
340336 }
341337
342- SwiftlyCore . print ( " Extracting toolchain... " )
343- let toolchainDir = self . swiftlyToolchainsDir. appendingPathComponent ( version. name)
338+ SwiftlyCore . print ( ctx , " Extracting toolchain... " )
339+ let toolchainDir = self . swiftlyToolchainsDir ( ctx ) . appendingPathComponent ( version. name)
344340
345341 if toolchainDir. fileExists ( ) {
346342 try FileManager . default. removeItem ( at: toolchainDir)
@@ -354,23 +350,23 @@ public struct Linux: Platform {
354350 let destination = toolchainDir. appendingPathComponent ( String ( relativePath) )
355351
356352 if verbose {
357- SwiftlyCore . print ( " \( destination. path) " )
353+ SwiftlyCore . print ( ctx , " \( destination. path) " )
358354 }
359355
360356 // prepend /path/to/swiftlyHomeDir/toolchains/<toolchain> to each file name
361357 return destination
362358 }
363359 }
364360
365- public func extractSwiftlyAndInstall( from archive: URL ) throws {
361+ public func extractSwiftlyAndInstall( _ ctx : SwiftlyCoreContext , from archive: URL ) throws {
366362 guard archive. fileExists ( ) else {
367363 throw SwiftlyError ( message: " \( archive) doesn't exist " )
368364 }
369365
370366 let tmpDir = self . getTempFilePath ( )
371367 try FileManager . default. createDirectory ( atPath: tmpDir. path, withIntermediateDirectories: true )
372368
373- SwiftlyCore . print ( " Extracting new swiftly... " )
369+ SwiftlyCore . print ( ctx , " Extracting new swiftly... " )
374370 try extractArchive ( atPath: archive) { name in
375371 // Extract to the temporary directory
376372 tmpDir. appendingPathComponent ( String ( name) )
@@ -379,8 +375,8 @@ public struct Linux: Platform {
379375 try self . runProgram ( tmpDir. appendingPathComponent ( " swiftly " ) . path, " init " )
380376 }
381377
382- public func uninstall( _ toolchain: ToolchainVersion , verbose _: Bool ) throws {
383- let toolchainDir = self . swiftlyToolchainsDir. appendingPathComponent ( toolchain. name)
378+ public func uninstall( _ ctx : SwiftlyCoreContext , _ toolchain: ToolchainVersion , verbose _: Bool ) throws {
379+ let toolchainDir = self . swiftlyToolchainsDir ( ctx ) . appendingPathComponent ( toolchain. name)
384380 try FileManager . default. removeItem ( at: toolchainDir)
385381 }
386382
@@ -394,9 +390,9 @@ public struct Linux: Platform {
394390 FileManager . default. temporaryDirectory. appendingPathComponent ( " swiftly- \( UUID ( ) ) " )
395391 }
396392
397- public func verifySignature( httpClient : SwiftlyHTTPClient , archiveDownloadURL: URL , archive: URL , verbose: Bool ) async throws {
393+ public func verifySignature( _ ctx : SwiftlyCoreContext , archiveDownloadURL: URL , archive: URL , verbose: Bool ) async throws {
398394 if verbose {
399- SwiftlyCore . print ( " Downloading toolchain signature... " )
395+ SwiftlyCore . print ( ctx , " Downloading toolchain signature... " )
400396 }
401397
402398 let sigFile = self . getTempFilePath ( )
@@ -405,20 +401,20 @@ public struct Linux: Platform {
405401 try ? FileManager . default. removeItem ( at: sigFile)
406402 }
407403
408- try await httpClient. downloadFile (
404+ try await ctx . httpClient. downloadFile (
409405 url: archiveDownloadURL. appendingPathExtension ( " sig " ) ,
410406 to: sigFile
411407 )
412408
413- SwiftlyCore . print ( " Verifying toolchain signature... " )
409+ SwiftlyCore . print ( ctx , " Verifying toolchain signature... " )
414410 do {
415411 try self . runProgram ( " gpg " , " --verify " , sigFile. path, archive. path, quiet: !verbose)
416412 } catch {
417413 throw SwiftlyError ( message: " Signature verification failed: \( error) . " )
418414 }
419415 }
420416
421- private func manualSelectPlatform( _ platformPretty: String ? ) async -> PlatformDefinition {
417+ private func manualSelectPlatform( _ ctx : SwiftlyCoreContext , _ platformPretty: String ? ) async -> PlatformDefinition {
422418 if let platformPretty {
423419 print ( " \( platformPretty) is not an officially supported platform, but the toolchains for another platform may still work on it. " )
424420 } else {
@@ -434,7 +430,7 @@ public struct Linux: Platform {
434430 \( selections)
435431 """ )
436432
437- let choice = SwiftlyCore . readLine ( prompt: " Pick one of the available selections [0- \( self . linuxPlatforms. count) ] " ) ?? " 0 "
433+ let choice = SwiftlyCore . readLine ( ctx , prompt: " Pick one of the available selections [0- \( self . linuxPlatforms. count) ] " ) ?? " 0 "
438434
439435 guard let choiceNum = Int ( choice) else {
440436 fatalError ( " Installation canceled " )
@@ -447,7 +443,7 @@ public struct Linux: Platform {
447443 return self . linuxPlatforms [ choiceNum - 1 ]
448444 }
449445
450- public func detectPlatform( disableConfirmation: Bool , platform: String ? ) async throws -> PlatformDefinition {
446+ public func detectPlatform( _ ctx : SwiftlyCoreContext , disableConfirmation: Bool , platform: String ? ) async throws -> PlatformDefinition {
451447 // We've been given a hint to use
452448 if let platform {
453449 guard let pd = linuxPlatforms. first ( where: { $0. nameFull == platform } ) else {
@@ -475,7 +471,7 @@ public struct Linux: Platform {
475471 } else {
476472 print ( message)
477473 }
478- return await self . manualSelectPlatform ( platformPretty)
474+ return await self . manualSelectPlatform ( ctx , platformPretty)
479475 }
480476
481477 let releaseInfo = try String ( contentsOfFile: releaseFile, encoding: . utf8)
@@ -502,7 +498,7 @@ public struct Linux: Platform {
502498 } else {
503499 print ( message)
504500 }
505- return await self . manualSelectPlatform ( platformPretty)
501+ return await self . manualSelectPlatform ( ctx , platformPretty)
506502 }
507503
508504 if ( id + ( idlike ?? " " ) ) . contains ( " amzn " ) {
@@ -513,7 +509,7 @@ public struct Linux: Platform {
513509 } else {
514510 print ( message)
515511 }
516- return await self . manualSelectPlatform ( platformPretty)
512+ return await self . manualSelectPlatform ( ctx , platformPretty)
517513 }
518514
519515 return . amazonlinux2
@@ -525,7 +521,7 @@ public struct Linux: Platform {
525521 } else {
526522 print ( message)
527523 }
528- return await self . manualSelectPlatform ( platformPretty)
524+ return await self . manualSelectPlatform ( ctx , platformPretty)
529525 }
530526
531527 return . rhel9
@@ -539,7 +535,7 @@ public struct Linux: Platform {
539535 } else {
540536 print ( message)
541537 }
542- return await self . manualSelectPlatform ( platformPretty)
538+ return await self . manualSelectPlatform ( ctx , platformPretty)
543539 }
544540
545541 public func getShell( ) async throws -> String {
@@ -559,8 +555,8 @@ public struct Linux: Platform {
559555 return " /bin/bash"
560556 }
561557
562- public func findToolchainLocation( _ toolchain: ToolchainVersion) - > URL {
563- self . swiftlyToolchainsDir. appendingPathComponent ( " \( toolchain. name) " )
558+ public func findToolchainLocation( _ ctx : SwiftlyCoreContext , _ toolchain: ToolchainVersion) - > URL {
559+ self . swiftlyToolchainsDir ( ctx ) . appendingPathComponent ( " \( toolchain. name) " )
564560 }
565561
566562 public static let currentPlatform : any Platform = Linux ( )
0 commit comments