@@ -105,7 +105,7 @@ public final class Toolchain: Hashable, Sendable {
105105 self . testingLibraryPlatformNames = testingLibraryPlatformNames
106106 }
107107
108- convenience init ( path: Path , operatingSystem: OperatingSystem , fs: any FSProxy , pluginManager: any PluginManager , platformRegistry: PlatformRegistry ? ) async throws {
108+ convenience init ( path: Path , operatingSystem: OperatingSystem , aliases additionalAliases : Set < String > , fs: any FSProxy , pluginManager: any PluginManager , platformRegistry: PlatformRegistry ? ) async throws {
109109 let data : PropertyListItem
110110
111111 do {
@@ -216,6 +216,8 @@ public final class Toolchain: Hashable, Sendable {
216216 aliases = Toolchain . deriveAliases ( path: path, identifier: identifier)
217217 }
218218
219+ aliases. formUnion ( additionalAliases)
220+
219221 // Framework Search Paths
220222 var frameworkSearchPaths = Array < String > ( )
221223 if let infoFrameworkSearchPaths = items [ " FallbackFrameworkSearchPaths " ] {
@@ -412,8 +414,32 @@ extension Array where Element == Toolchain {
412414 }
413415}
414416
417+ extension Toolchain {
418+ public func lookup( subject: StackedSearchPathLookupSubject , operatingSystem: OperatingSystem ) throws ( StackedSearchPathLookupError) -> Path {
419+ let searchPathsList = [ librarySearchPaths, fallbackLibrarySearchPaths]
420+ for searchPaths in searchPathsList {
421+ if let library = searchPaths. lookup ( subject: subject, operatingSystem: operatingSystem) {
422+ return library
423+ }
424+ }
425+ throw . unableToFind( subject: subject, operatingSystem: operatingSystem, searchPaths: searchPathsList)
426+ }
427+ }
428+
415429/// The ToolchainRegistry manages the set of registered toolchains.
416430public final class ToolchainRegistry : @unchecked Sendable {
431+ @_spi ( Testing) public struct SearchPath : Sendable {
432+ public var path : Path
433+ public var strict : Bool
434+ public var aliases : Set < String > = [ ]
435+
436+ public init ( path: Path , strict: Bool , aliases: Set < String > = [ ] ) {
437+ self . path = path
438+ self . strict = strict
439+ self . aliases = aliases
440+ }
441+ }
442+
417443 let fs : any FSProxy
418444 let hostOperatingSystem : OperatingSystem
419445
@@ -427,17 +453,19 @@ public final class ToolchainRegistry: @unchecked Sendable {
427453
428454 public static let appleToolchainIdentifierPrefix : String = " com.apple.dt.toolchain. "
429455
430- @_spi ( Testing) public init ( delegate: any ToolchainRegistryDelegate , searchPaths: [ ( Path , strict : Bool ) ] , fs: any FSProxy , hostOperatingSystem: OperatingSystem ) async {
456+ @_spi ( Testing) public init ( delegate: any ToolchainRegistryDelegate , searchPaths: [ SearchPath ] , fs: any FSProxy , hostOperatingSystem: OperatingSystem ) async {
431457 self . fs = fs
432458 self . hostOperatingSystem = hostOperatingSystem
433459
434- for (path, strict) in searchPaths {
460+ for searchPath in searchPaths {
461+ let path = searchPath. path
462+ let strict = searchPath. strict
435463 if !strict && !fs. exists ( path) {
436464 continue
437465 }
438466
439467 do {
440- try await registerToolchainsInDirectory ( path, strict: strict, operatingSystem: hostOperatingSystem, delegate: delegate)
468+ try await registerToolchainsInDirectory ( path, strict: strict, aliases : searchPath . aliases , operatingSystem: hostOperatingSystem, delegate: delegate)
441469 }
442470 catch let err {
443471 delegate. issue ( strict: strict, path, " failed to load toolchains in \( path. str) : \( err) " )
@@ -462,7 +490,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
462490 }
463491
464492 /// Register all the toolchains in the given directory.
465- private func registerToolchainsInDirectory( _ path: Path , strict: Bool , operatingSystem: OperatingSystem , delegate: any ToolchainRegistryDelegate ) async throws {
493+ private func registerToolchainsInDirectory( _ path: Path , strict: Bool , aliases : Set < String > , operatingSystem: OperatingSystem , delegate: any ToolchainRegistryDelegate ) async throws {
466494 let toolchainPaths : [ Path ] = try fs. listdir ( path)
467495 . sorted ( )
468496 . map { path. join ( $0) }
@@ -475,7 +503,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
475503 guard toolchainPath. basenameWithoutSuffix != " swift-latest " else { continue }
476504
477505 do {
478- let toolchain = try await Toolchain ( path: toolchainPath, operatingSystem: operatingSystem, fs: fs, pluginManager: delegate. pluginManager, platformRegistry: delegate. platformRegistry)
506+ let toolchain = try await Toolchain ( path: toolchainPath, operatingSystem: operatingSystem, aliases : aliases , fs: fs, pluginManager: delegate. pluginManager, platformRegistry: delegate. platformRegistry)
479507 try register ( toolchain)
480508 } catch let err {
481509 delegate. issue ( strict: strict, toolchainPath, " failed to load toolchain: \( err) " )
@@ -505,24 +533,15 @@ public final class ToolchainRegistry: @unchecked Sendable {
505533 /// Look up the toolchain with the given identifier.
506534 public func lookup( _ identifier: String ) -> Toolchain ? {
507535 let lowercasedIdentifier = identifier. lowercased ( )
508- if hostOperatingSystem == . macOS {
509- if [ " default " , " xcode " ] . contains ( lowercasedIdentifier) {
510- return toolchainsByIdentifier [ ToolchainRegistry . defaultToolchainIdentifier] ?? toolchainsByAlias [ lowercasedIdentifier]
511- } else {
512- return toolchainsByIdentifier [ identifier] ?? toolchainsByAlias [ lowercasedIdentifier]
513- }
536+ if [ " default " , " xcode " ] . contains ( lowercasedIdentifier) {
537+ return toolchainsByIdentifier [ ToolchainRegistry . defaultToolchainIdentifier] ?? toolchainsByAlias [ lowercasedIdentifier]
514538 } else {
515- // On non-Darwin, assume if there is only one registered toolchain, it is the default.
516- if [ " default " , " xcode " ] . contains ( lowercasedIdentifier) || identifier == ToolchainRegistry . defaultToolchainIdentifier {
517- return toolchainsByIdentifier [ ToolchainRegistry . defaultToolchainIdentifier] ?? toolchainsByAlias [ lowercasedIdentifier] ?? toolchainsByIdentifier. values. only
518- } else {
519- return toolchainsByIdentifier [ identifier] ?? toolchainsByAlias [ lowercasedIdentifier]
520- }
539+ return toolchainsByIdentifier [ identifier] ?? toolchainsByAlias [ lowercasedIdentifier]
521540 }
522541 }
523542
524543 public var defaultToolchain : Toolchain ? {
525- return self . lookup ( ToolchainRegistry . defaultToolchainIdentifier )
544+ return self . lookup ( " default " )
526545 }
527546
528547 public var toolchains : Set < Toolchain > {
0 commit comments