@@ -96,6 +96,13 @@ package final actor ToolchainRegistry {
96
96
var toolchainsByPath : [ URL : Toolchain ] = [ : ]
97
97
var toolchainsByCompiler : [ URL : Toolchain ] = [ : ]
98
98
for (toolchain, reason) in toolchainsAndReasonsParam {
99
+ // Toolchain should always be unique by path. It isn't particularly useful to log if we already have a toolchain
100
+ // though, as we could have just found toolchains through symlinks (this is actually quite normal - eg. OSS
101
+ // toolchains add a `swift-latest.xctoolchain` symlink on macOS).
102
+ if toolchainsByPath [ toolchain. path] != nil {
103
+ continue
104
+ }
105
+
99
106
// Non-XcodeDefault toolchain: disallow all duplicates.
100
107
if toolchainsByIdentifier [ toolchain. identifier] != nil ,
101
108
toolchain. identifier != ToolchainRegistry . darwinDefaultToolchainIdentifier
@@ -104,12 +111,6 @@ package final actor ToolchainRegistry {
104
111
continue
105
112
}
106
113
107
- // Toolchain should always be unique by path.
108
- if toolchainsByPath [ toolchain. path] != nil {
109
- logger. fault ( " Found two toolchains with the same path: \( toolchain. path) " )
110
- continue
111
- }
112
-
113
114
toolchainsByPath [ toolchain. path] = toolchain
114
115
toolchainsByIdentifier [ toolchain. identifier, default: [ ] ] . append ( toolchain)
115
116
@@ -219,7 +220,9 @@ package final actor ToolchainRegistry {
219
220
}
220
221
221
222
let toolchainsAndReasons = toolchainPaths. compactMap {
222
- if let toolchain = Toolchain ( $0. path) {
223
+ if let resolvedPath = try ? $0. path. realpath,
224
+ let toolchain = Toolchain ( resolvedPath)
225
+ {
223
226
return ( toolchain, $0. reason)
224
227
}
225
228
return nil
@@ -283,7 +286,18 @@ package final actor ToolchainRegistry {
283
286
/// If we have a toolchain in the toolchain registry that contains the compiler with the given URL, return it.
284
287
/// Otherwise, return `nil`.
285
288
package func toolchain( withCompiler compiler: URL ) -> Toolchain ? {
286
- return toolchainsByCompiler [ compiler]
289
+ if let resolvedPath = try ? compiler. realpath {
290
+ return toolchainsByCompiler [ resolvedPath]
291
+ }
292
+ return nil
293
+ }
294
+
295
+ /// If we have a toolchain in the toolchain registry with the given URL, return it. Otherwise, return `nil`.
296
+ package func toolchain( withPath path: URL) - > Toolchain? {
297
+ if let resolvedPath = try ? path. realpath {
298
+ return toolchainsByPath [ resolvedPath]
299
+ }
300
+ return nil
287
301
}
288
302
}
289
303
@@ -292,10 +306,6 @@ extension ToolchainRegistry {
292
306
package func toolchains( withIdentifier identifier: String ) -> [ Toolchain ] {
293
307
return toolchainsByIdentifier [ identifier] ?? [ ]
294
308
}
295
-
296
- package func toolchain( withPath path: URL ) -> Toolchain ? {
297
- return toolchainsByPath [ path]
298
- }
299
309
}
300
310
301
311
extension ToolchainRegistry {
0 commit comments