@@ -19,13 +19,13 @@ import * as plist from "plist";
19
19
import * as vscode from "vscode" ;
20
20
import configuration from "../configuration" ;
21
21
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel" ;
22
- import { execFile , ExecFileError , execSwift } from "../utilities/utilities" ;
22
+ import { execFile , execSwift } from "../utilities/utilities" ;
23
23
import { expandFilePathTilde , fileExists , pathExists } from "../utilities/filesystem" ;
24
24
import { Version } from "../utilities/version" ;
25
25
import { BuildFlags } from "./BuildFlags" ;
26
26
import { Sanitizer } from "./Sanitizer" ;
27
- import { SwiftlyConfig } from "./ToolchainVersion" ;
28
27
import { lineBreakRegex } from "../utilities/tasks" ;
28
+ import { swiftly } from "./swiftly" ;
29
29
30
30
/**
31
31
* Contents of **Info.plist** on Windows.
@@ -251,54 +251,6 @@ export class SwiftToolchain {
251
251
return result ;
252
252
}
253
253
254
- /**
255
- * Finds the list of toolchains managed by Swiftly.
256
- *
257
- * @returns an array of toolchain paths
258
- */
259
- public static async getSwiftlyToolchainInstalls ( ) : Promise < string [ ] > {
260
- // Swiftly is available on Linux and macOS
261
- if ( process . platform !== "linux" && process . platform !== "darwin" ) {
262
- return [ ] ;
263
- }
264
- try {
265
- const swiftlyHomeDir : string | undefined = process . env [ "SWIFTLY_HOME_DIR" ] ;
266
- if ( ! swiftlyHomeDir ) {
267
- return [ ] ;
268
- }
269
- const swiftlyConfig = await SwiftToolchain . getSwiftlyConfig ( ) ;
270
- if ( ! swiftlyConfig || ! ( "installedToolchains" in swiftlyConfig ) ) {
271
- return [ ] ;
272
- }
273
- const installedToolchains = swiftlyConfig . installedToolchains ;
274
- if ( ! Array . isArray ( installedToolchains ) ) {
275
- return [ ] ;
276
- }
277
- return installedToolchains
278
- . filter ( ( toolchain ) : toolchain is string => typeof toolchain === "string" )
279
- . map ( toolchain => path . join ( swiftlyHomeDir , "toolchains" , toolchain ) ) ;
280
- } catch ( error ) {
281
- throw new Error ( "Failed to retrieve Swiftly installations from disk." ) ;
282
- }
283
- }
284
-
285
- /**
286
- * Reads the Swiftly configuration file, if it exists.
287
- *
288
- * @returns A parsed Swiftly configuration.
289
- */
290
- private static async getSwiftlyConfig ( ) : Promise < SwiftlyConfig | undefined > {
291
- const swiftlyHomeDir : string | undefined = process . env [ "SWIFTLY_HOME_DIR" ] ;
292
- if ( ! swiftlyHomeDir ) {
293
- return ;
294
- }
295
- const swiftlyConfigRaw = await fs . readFile (
296
- path . join ( swiftlyHomeDir , "config.json" ) ,
297
- "utf-8"
298
- ) ;
299
- return JSON . parse ( swiftlyConfigRaw ) ;
300
- }
301
-
302
254
/**
303
255
* Checks common directories for available swift toolchain installations.
304
256
*
@@ -615,7 +567,7 @@ export class SwiftToolchain {
615
567
let realSwift = await fs . realpath ( swift ) ;
616
568
if ( path . basename ( realSwift ) === "swiftly" ) {
617
569
try {
618
- const inUse = await this . swiftlyInUseLocation ( realSwift , cwd ) ;
570
+ const inUse = await swiftly . swiftlyInUseLocation ( realSwift , cwd ) ;
619
571
if ( inUse ) {
620
572
realSwift = path . join ( inUse , "usr" , "bin" , "swift" ) ;
621
573
}
@@ -668,7 +620,7 @@ export class SwiftToolchain {
668
620
const swiftlyPath = path . join ( configPath , "swiftly" ) ;
669
621
if ( await fileExists ( swiftlyPath ) ) {
670
622
try {
671
- const inUse = await this . swiftlyInUseLocation ( swiftlyPath , cwd ) ;
623
+ const inUse = await swiftly . swiftlyInUseLocation ( swiftlyPath , cwd ) ;
672
624
if ( inUse ) {
673
625
return path . join ( inUse , "usr" ) ;
674
626
}
@@ -679,7 +631,7 @@ export class SwiftToolchain {
679
631
return path . dirname ( configuration . path ) ;
680
632
}
681
633
682
- const swiftlyToolchainLocation = await this . swiftlyToolchain ( cwd ) ;
634
+ const swiftlyToolchainLocation = await swiftly . swiftlyToolchain ( cwd ) ;
683
635
if ( swiftlyToolchainLocation ) {
684
636
return swiftlyToolchainLocation ;
685
637
}
@@ -699,41 +651,6 @@ export class SwiftToolchain {
699
651
}
700
652
}
701
653
702
- private static async swiftlyInUseLocation ( swiftlyPath : string , cwd ?: vscode . Uri ) {
703
- const { stdout : inUse } = await execFile ( swiftlyPath , [ "use" , "--print-location" ] , {
704
- cwd : cwd ?. fsPath ,
705
- } ) ;
706
- return inUse . trimEnd ( ) ;
707
- }
708
-
709
- /**
710
- * Determine if Swiftly is being used to manage the active toolchain and if so, return
711
- * the path to the active toolchain.
712
- * @returns The location of the active toolchain if swiftly is being used to manage it.
713
- */
714
- private static async swiftlyToolchain ( cwd ?: vscode . Uri ) : Promise < string | undefined > {
715
- const swiftlyHomeDir : string | undefined = process . env [ "SWIFTLY_HOME_DIR" ] ;
716
- if ( swiftlyHomeDir ) {
717
- const { stdout : swiftLocation } = await execFile ( "which" , [ "swift" ] ) ;
718
- if ( swiftLocation . indexOf ( swiftlyHomeDir ) === 0 ) {
719
- // Print the location of the toolchain that swiftly is using. If there
720
- // is no cwd specified then it returns the global "inUse" toolchain otherwise
721
- // it respects the .swift-version file in the cwd and resolves using that.
722
- try {
723
- const inUse = await this . swiftlyInUseLocation ( "swiftly" , cwd ) ;
724
- if ( inUse . length > 0 ) {
725
- return path . join ( inUse , "usr" ) ;
726
- }
727
- } catch ( err : unknown ) {
728
- const error = err as ExecFileError ;
729
- // Its possible the toolchain in .swift-version is misconfigured or doesn't exist.
730
- void vscode . window . showErrorMessage ( `${ error . stderr } ` ) ;
731
- }
732
- }
733
- }
734
- return undefined ;
735
- }
736
-
737
654
/**
738
655
* @param targetInfo swift target info
739
656
* @returns path to Swift runtime
0 commit comments