@@ -41,9 +41,6 @@ public final actor ToolchainRegistry {
41
41
/// Note: Not all toolchains have a path.
42
42
private var toolchainsByPath : [ AbsolutePath : Toolchain ] = [ : ]
43
43
44
- /// The default toolchain.
45
- private var _default : Toolchain ? = nil
46
-
47
44
/// The currently selected toolchain identifier on Darwin.
48
45
public lazy var darwinToolchainOverride : String ? = {
49
46
if let id = ProcessEnv . vars [ " TOOLCHAINS " ] , !id. isEmpty, id != " default " {
@@ -90,9 +87,6 @@ public final actor ToolchainRegistry {
90
87
) async {
91
88
scanForToolchains ( installPath: installPath, fileSystem)
92
89
}
93
- }
94
-
95
- extension ToolchainRegistry {
96
90
97
91
/// The default toolchain.
98
92
///
@@ -103,26 +97,12 @@ extension ToolchainRegistry {
103
97
/// The default toolchain must be only of the registered toolchains.
104
98
public var `default` : Toolchain ? {
105
99
get {
106
- if _default == nil {
107
- if let tc = toolchainsByIdentifier [ darwinToolchainIdentifier] ? . first {
108
- _default = tc
109
- } else {
110
- _default = toolchains. first
111
- }
112
- }
113
- return _default
114
- }
115
-
116
- set {
117
- guard let toolchain = newValue else {
118
- _default = nil
119
- return
100
+ if let tc = toolchainsByIdentifier [ darwinToolchainIdentifier] ? . first {
101
+ return tc
102
+ } else {
103
+ return toolchains. first
120
104
}
121
- precondition (
122
- toolchains. contains { $0 === toolchain } ,
123
- " default toolchain must be registered first "
124
- )
125
- _default = toolchain
105
+ return nil
126
106
}
127
107
}
128
108
@@ -206,12 +186,11 @@ extension ToolchainRegistry {
206
186
public func registerToolchain(
207
187
_ path: AbsolutePath ,
208
188
_ fileSystem: FileSystem = localFileSystem
209
- ) throws -> Toolchain {
189
+ ) throws {
210
190
guard let toolchain = Toolchain ( path, fileSystem) else {
211
191
throw Error . invalidToolchain
212
192
}
213
193
try registerToolchain ( toolchain)
214
- return toolchain
215
194
}
216
195
}
217
196
@@ -240,12 +219,9 @@ extension ToolchainRegistry {
240
219
AbsolutePath ( validating: " /Library/Developer/Toolchains " ) ,
241
220
]
242
221
243
- scanForToolchains ( environmentVariables: environmentVariables, setDefault: true , fileSystem)
244
- if let installPath = installPath,
245
- let toolchain = try ? registerToolchain ( installPath, fileSystem) ,
246
- _default == nil
247
- {
248
- _default = toolchain
222
+ scanForToolchains ( environmentVariables: environmentVariables, fileSystem)
223
+ if let installPath = installPath {
224
+ try ? registerToolchain ( installPath, fileSystem)
249
225
}
250
226
for xcode in xcodes {
251
227
scanForToolchains ( xcode: xcode, fileSystem)
@@ -261,22 +237,16 @@ extension ToolchainRegistry {
261
237
///
262
238
/// - parameters:
263
239
/// - environmentVariables: A list of environment variable names to search for toolchain paths.
264
- /// - setDefault: If true, the first toolchain found will be set as the default.
265
240
@_spi ( Testing)
266
241
public func scanForToolchains(
267
242
environmentVariables: [ String ] ,
268
- setDefault: Bool ,
269
243
_ fileSystem: FileSystem = localFileSystem
270
244
) {
271
- var shouldSetDefault = setDefault
272
245
for envVar in environmentVariables {
273
246
if let pathStr = ProcessEnv . vars [ envVar] ,
274
- let path = try ? AbsolutePath ( validating: pathStr) ,
275
- let toolchain = try ? registerToolchain ( path, fileSystem) ,
276
- shouldSetDefault
247
+ let path = try ? AbsolutePath ( validating: pathStr)
277
248
{
278
- shouldSetDefault = false
279
- _default = toolchain
249
+ try ? registerToolchain ( path, fileSystem)
280
250
}
281
251
}
282
252
}
@@ -285,7 +255,6 @@ extension ToolchainRegistry {
285
255
///
286
256
/// - parameters:
287
257
/// - pathVariables: A list of PATH-like environment variable names to search.
288
- /// - setDefault: If true, the first toolchain found will be set as the default.
289
258
@_spi ( Testing)
290
259
public func scanForToolchains( pathVariables: [ String ] , _ fileSystem: FileSystem = localFileSystem) {
291
260
pathVariables. lazy. flatMap { envVar in
0 commit comments