@@ -129,39 +129,44 @@ struct GenericUnixToolchainRegistryExtension: ToolchainRegistryExtension {
129129
130130 let fs = context. fs
131131
132- if let swift = StackedSearchPath ( environment: . current, fs: fs) . lookup ( Path ( " swift " ) ) , fs. exists ( swift) {
133- let realSwiftPath = try fs. realpath ( swift) . dirname. normalize ( )
134- let hasUsrBin = realSwiftPath. str. hasSuffix ( " /usr/bin " )
135- let hasUsrLocalBin = realSwiftPath. str. hasSuffix ( " /usr/local/bin " )
136- let path : Path
137- switch ( hasUsrBin, hasUsrLocalBin) {
138- case ( true , false ) :
139- path = realSwiftPath. dirname. dirname
140- case ( false , true ) :
141- path = realSwiftPath. dirname. dirname. dirname
142- case ( false , false ) :
143- throw StubError . error ( " Unexpected toolchain layout for Swift installation path: \( realSwiftPath) " )
144- case ( true , true ) :
145- preconditionFailure ( )
132+ for swift in [
133+ Environment . current [ " SWIFT_EXEC " ] . map ( Path . init) ,
134+ StackedSearchPath ( environment: . current, fs: fs) . lookup ( Path ( " swift " ) )
135+ ] . compactMap ( \. self) {
136+ if fs. exists ( swift) {
137+ let realSwiftPath = try fs. realpath ( swift) . dirname. normalize ( )
138+ let hasUsrBin = realSwiftPath. str. hasSuffix ( " /usr/bin " )
139+ let hasUsrLocalBin = realSwiftPath. str. hasSuffix ( " /usr/local/bin " )
140+ let path : Path
141+ switch ( hasUsrBin, hasUsrLocalBin) {
142+ case ( true , false ) :
143+ path = realSwiftPath. dirname. dirname
144+ case ( false , true ) :
145+ path = realSwiftPath. dirname. dirname. dirname
146+ case ( false , false ) :
147+ throw StubError . error ( " Unexpected toolchain layout for Swift installation path: \( realSwiftPath) " )
148+ case ( true , true ) :
149+ preconditionFailure ( )
150+ }
151+ let llvmDirectories = try Array ( fs. listdir ( Path ( " /usr/lib " ) ) . filter { $0. hasPrefix ( " llvm- " ) } . sorted ( ) . reversed ( ) )
152+ let llvmDirectoriesLocal = try Array ( fs. listdir ( Path ( " /usr/local " ) ) . filter { $0. hasPrefix ( " llvm " ) } . sorted ( ) . reversed ( ) )
153+ return [
154+ Toolchain (
155+ identifier: ToolchainRegistry . defaultToolchainIdentifier,
156+ displayName: " Default " ,
157+ version: Version ( ) ,
158+ aliases: [ " default " ] ,
159+ path: path,
160+ frameworkPaths: [ ] ,
161+ libraryPaths: llvmDirectories. map { " /usr/lib/ \( $0) /lib " } + llvmDirectoriesLocal. map { " /usr/local/ \( $0) /lib " } + [ " /usr/lib64 " ] ,
162+ defaultSettings: [ : ] ,
163+ overrideSettings: [ : ] ,
164+ defaultSettingsWhenPrimary: [ : ] ,
165+ executableSearchPaths: realSwiftPath. dirname. relativeSubpath ( from: path) . map { [ path. join ( $0) . join ( " bin " ) ] } ?? [ ] ,
166+ testingLibraryPlatformNames: [ ] ,
167+ fs: fs)
168+ ]
146169 }
147- let llvmDirectories = try Array ( fs. listdir ( Path ( " /usr/lib " ) ) . filter { $0. hasPrefix ( " llvm- " ) } . sorted ( ) . reversed ( ) )
148- let llvmDirectoriesLocal = try Array ( fs. listdir ( Path ( " /usr/local " ) ) . filter { $0. hasPrefix ( " llvm " ) } . sorted ( ) . reversed ( ) )
149- return [
150- Toolchain (
151- identifier: ToolchainRegistry . defaultToolchainIdentifier,
152- displayName: " Default " ,
153- version: Version ( ) ,
154- aliases: [ " default " ] ,
155- path: path,
156- frameworkPaths: [ ] ,
157- libraryPaths: llvmDirectories. map { " /usr/lib/ \( $0) /lib " } + llvmDirectoriesLocal. map { " /usr/local/ \( $0) /lib " } + [ " /usr/lib64 " ] ,
158- defaultSettings: [ : ] ,
159- overrideSettings: [ : ] ,
160- defaultSettingsWhenPrimary: [ : ] ,
161- executableSearchPaths: realSwiftPath. dirname. relativeSubpath ( from: path) . map { [ path. join ( $0) . join ( " bin " ) ] } ?? [ ] ,
162- testingLibraryPlatformNames: [ ] ,
163- fs: fs)
164- ]
165170 }
166171
167172 return [ ]
0 commit comments