@@ -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 " ] {
@@ -414,6 +416,18 @@ extension Array where Element == Toolchain {
414
416
415
417
/// The ToolchainRegistry manages the set of registered toolchains.
416
418
public final class ToolchainRegistry : @unchecked Sendable {
419
+ @_spi ( Testing) public struct SearchPath : Sendable {
420
+ public var path : Path
421
+ public var strict : Bool
422
+ public var aliases : Set < String > = [ ]
423
+
424
+ public init ( path: Path , strict: Bool , aliases: Set < String > = [ ] ) {
425
+ self . path = path
426
+ self . strict = strict
427
+ self . aliases = aliases
428
+ }
429
+ }
430
+
417
431
let fs : any FSProxy
418
432
let hostOperatingSystem : OperatingSystem
419
433
@@ -427,17 +441,19 @@ public final class ToolchainRegistry: @unchecked Sendable {
427
441
428
442
public static let appleToolchainIdentifierPrefix : String = " com.apple.dt.toolchain. "
429
443
430
- @_spi ( Testing) public init ( delegate: any ToolchainRegistryDelegate , searchPaths: [ ( Path , strict : Bool ) ] , fs: any FSProxy , hostOperatingSystem: OperatingSystem ) async {
444
+ @_spi ( Testing) public init ( delegate: any ToolchainRegistryDelegate , searchPaths: [ SearchPath ] , fs: any FSProxy , hostOperatingSystem: OperatingSystem ) async {
431
445
self . fs = fs
432
446
self . hostOperatingSystem = hostOperatingSystem
433
447
434
- for (path, strict) in searchPaths {
448
+ for searchPath in searchPaths {
449
+ let path = searchPath. path
450
+ let strict = searchPath. strict
435
451
if !strict && !fs. exists ( path) {
436
452
continue
437
453
}
438
454
439
455
do {
440
- try await registerToolchainsInDirectory ( path, strict: strict, operatingSystem: hostOperatingSystem, delegate: delegate)
456
+ try await registerToolchainsInDirectory ( path, strict: strict, aliases : searchPath . aliases , operatingSystem: hostOperatingSystem, delegate: delegate)
441
457
}
442
458
catch let err {
443
459
delegate. issue ( strict: strict, path, " failed to load toolchains in \( path. str) : \( err) " )
@@ -462,7 +478,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
462
478
}
463
479
464
480
/// Register all the toolchains in the given directory.
465
- private func registerToolchainsInDirectory( _ path: Path , strict: Bool , operatingSystem: OperatingSystem , delegate: any ToolchainRegistryDelegate ) async throws {
481
+ private func registerToolchainsInDirectory( _ path: Path , strict: Bool , aliases : Set < String > , operatingSystem: OperatingSystem , delegate: any ToolchainRegistryDelegate ) async throws {
466
482
let toolchainPaths : [ Path ] = try fs. listdir ( path)
467
483
. sorted ( )
468
484
. map { path. join ( $0) }
@@ -475,7 +491,7 @@ public final class ToolchainRegistry: @unchecked Sendable {
475
491
guard toolchainPath. basenameWithoutSuffix != " swift-latest " else { continue }
476
492
477
493
do {
478
- let toolchain = try await Toolchain ( path: toolchainPath, operatingSystem: operatingSystem, fs: fs, pluginManager: delegate. pluginManager, platformRegistry: delegate. platformRegistry)
494
+ let toolchain = try await Toolchain ( path: toolchainPath, operatingSystem: operatingSystem, aliases : aliases , fs: fs, pluginManager: delegate. pluginManager, platformRegistry: delegate. platformRegistry)
479
495
try register ( toolchain)
480
496
} catch let err {
481
497
delegate. issue ( strict: strict, toolchainPath, " failed to load toolchain: \( err) " )
@@ -505,19 +521,10 @@ public final class ToolchainRegistry: @unchecked Sendable {
505
521
/// Look up the toolchain with the given identifier.
506
522
public func lookup( _ identifier: String ) -> Toolchain ? {
507
523
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
- }
524
+ if [ " default " , " xcode " ] . contains ( lowercasedIdentifier) {
525
+ return toolchainsByIdentifier [ ToolchainRegistry . defaultToolchainIdentifier] ?? toolchainsByAlias [ lowercasedIdentifier]
514
526
} 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
- }
527
+ return toolchainsByIdentifier [ identifier] ?? toolchainsByAlias [ lowercasedIdentifier]
521
528
}
522
529
}
523
530
0 commit comments