@@ -125,39 +125,44 @@ struct GenericUnixToolchainRegistryExtension: ToolchainRegistryExtension {
125125
126126 let fs = context. fs
127127
128- if let swift = StackedSearchPath ( environment: . current, fs: fs) . lookup ( Path ( " swift " ) ) , fs. exists ( swift) {
129- let realSwiftPath = try fs. realpath ( swift) . dirname. normalize ( )
130- let hasUsrBin = realSwiftPath. str. hasSuffix ( " /usr/bin " )
131- let hasUsrLocalBin = realSwiftPath. str. hasSuffix ( " /usr/local/bin " )
132- let path : Path
133- switch ( hasUsrBin, hasUsrLocalBin) {
134- case ( true , false ) :
135- path = realSwiftPath. dirname. dirname
136- case ( false , true ) :
137- path = realSwiftPath. dirname. dirname. dirname
138- case ( false , false ) :
139- throw StubError . error ( " Unexpected toolchain layout for Swift installation path: \( realSwiftPath) " )
140- case ( true , true ) :
141- preconditionFailure ( )
128+ for swift in [
129+ Environment . current [ " SWIFT_EXEC " ] . map ( Path . init) ,
130+ StackedSearchPath ( environment: . current, fs: fs) . lookup ( Path ( " swift " ) )
131+ ] . compactMap ( \. self) {
132+ if 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 ( )
146+ }
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+ ]
142165 }
143- let llvmDirectories = try Array ( fs. listdir ( Path ( " /usr/lib " ) ) . filter { $0. hasPrefix ( " llvm- " ) } . sorted ( ) . reversed ( ) )
144- let llvmDirectoriesLocal = try Array ( fs. listdir ( Path ( " /usr/local " ) ) . filter { $0. hasPrefix ( " llvm " ) } . sorted ( ) . reversed ( ) )
145- return [
146- Toolchain (
147- identifier: ToolchainRegistry . defaultToolchainIdentifier,
148- displayName: " Default " ,
149- version: Version ( ) ,
150- aliases: [ " default " ] ,
151- path: path,
152- frameworkPaths: [ ] ,
153- libraryPaths: llvmDirectories. map { " /usr/lib/ \( $0) /lib " } + llvmDirectoriesLocal. map { " /usr/local/ \( $0) /lib " } + [ " /usr/lib64 " ] ,
154- defaultSettings: [ : ] ,
155- overrideSettings: [ : ] ,
156- defaultSettingsWhenPrimary: [ : ] ,
157- executableSearchPaths: realSwiftPath. dirname. relativeSubpath ( from: path) . map { [ path. join ( $0) . join ( " bin " ) ] } ?? [ ] ,
158- testingLibraryPlatformNames: [ ] ,
159- fs: fs)
160- ]
161166 }
162167
163168 return [ ]
0 commit comments