@@ -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,8 @@ 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) {
223
225
return ( toolchain, $0. reason)
224
226
}
225
227
return nil
@@ -283,7 +285,18 @@ package final actor ToolchainRegistry {
283
285
/// If we have a toolchain in the toolchain registry that contains the compiler with the given URL, return it.
284
286
/// Otherwise, return `nil`.
285
287
package func toolchain( withCompiler compiler: URL ) -> Toolchain ? {
286
- return toolchainsByCompiler [ compiler]
288
+ if let resolvedPath = try ? compiler. realpath {
289
+ return toolchainsByCompiler [ resolvedPath]
290
+ }
291
+ return nil
292
+ }
293
+
294
+ /// If we have a toolchain in the toolchain registry with the given URL, return it. Otherwise, return `nil`.
295
+ package func toolchain( withPath path: URL) - > Toolchain? {
296
+ if let resolvedPath = try ? path. realpath {
297
+ return toolchainsByPath [ resolvedPath]
298
+ }
299
+ return nil
287
300
}
288
301
}
289
302
@@ -292,10 +305,6 @@ extension ToolchainRegistry {
292
305
package func toolchains( withIdentifier identifier: String ) -> [ Toolchain ] {
293
306
return toolchainsByIdentifier [ identifier] ?? [ ]
294
307
}
295
-
296
- package func toolchain( withPath path: URL ) -> Toolchain ? {
297
- return toolchainsByPath [ path]
298
- }
299
308
}
300
309
301
310
extension ToolchainRegistry {
0 commit comments