@@ -105,7 +105,7 @@ public final class Toolchain: Hashable, Sendable {
105
105
self . testingLibraryPlatformNames = testingLibraryPlatformNames
106
106
}
107
107
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 {
109
109
let data : PropertyListItem
110
110
111
111
do {
@@ -216,6 +216,8 @@ public final class Toolchain: Hashable, Sendable {
216
216
aliases = Toolchain . deriveAliases ( path: path, identifier: identifier)
217
217
}
218
218
219
+ aliases. formUnion ( additionalAliases)
220
+
219
221
// Framework Search Paths
220
222
var frameworkSearchPaths = Array < String > ( )
221
223
if let infoFrameworkSearchPaths = items [ " FallbackFrameworkSearchPaths " ] {
@@ -412,8 +414,32 @@ extension Array where Element == Toolchain {
412
414
}
413
415
}
414
416
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
+
415
429
/// The ToolchainRegistry manages the set of registered toolchains.
416
430
public 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
+
417
443
let fs : any FSProxy
418
444
let hostOperatingSystem : OperatingSystem
419
445
@@ -427,17 +453,19 @@ public final class ToolchainRegistry: @unchecked Sendable {
427
453
428
454
public static let appleToolchainIdentifierPrefix : String = " com.apple.dt.toolchain. "
429
455
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 {
431
457
self . fs = fs
432
458
self . hostOperatingSystem = hostOperatingSystem
433
459
434
- for (path, strict) in searchPaths {
460
+ for searchPath in searchPaths {
461
+ let path = searchPath. path
462
+ let strict = searchPath. strict
435
463
if !strict && !fs. exists ( path) {
436
464
continue
437
465
}
438
466
439
467
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)
441
469
}
442
470
catch let err {
443
471
delegate. issue ( strict: strict, path, " failed to load toolchains in \( path. str) : \( err) " )
@@ -462,7 +490,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
462
490
}
463
491
464
492
/// 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 {
466
494
let toolchainPaths : [ Path ] = try fs. listdir ( path)
467
495
. sorted ( )
468
496
. map { path. join ( $0) }
@@ -475,7 +503,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
475
503
guard toolchainPath. basenameWithoutSuffix != " swift-latest " else { continue }
476
504
477
505
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)
479
507
try register ( toolchain)
480
508
} catch let err {
481
509
delegate. issue ( strict: strict, toolchainPath, " failed to load toolchain: \( err) " )
@@ -505,24 +533,15 @@ public final class ToolchainRegistry: @unchecked Sendable {
505
533
/// Look up the toolchain with the given identifier.
506
534
public func lookup( _ identifier: String ) -> Toolchain ? {
507
535
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]
514
538
} 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]
521
540
}
522
541
}
523
542
524
543
public var defaultToolchain : Toolchain ? {
525
- return self . lookup ( ToolchainRegistry . defaultToolchainIdentifier )
544
+ return self . lookup ( " default " )
526
545
}
527
546
528
547
public var toolchains : Set < Toolchain > {
0 commit comments