@@ -142,10 +142,9 @@ private enum BuildSystemAdapter {
142
142
}
143
143
144
144
private extension BuildSystemSpec {
145
- private static func createBuiltInBuildSystemAdapter(
146
- projectRoot: URL ,
145
+ private func createBuiltInBuildSystemAdapter(
147
146
messagesToSourceKitLSPHandler: any MessageHandler ,
148
- buildSystemTestHooks : BuildSystemTestHooks ,
147
+ buildSystemHooks : BuildSystemHooks ,
149
148
_ createBuildSystem: @Sendable ( _ connectionToSourceKitLSP: any Connection ) async throws -> BuiltInBuildSystem ?
150
149
) async -> BuildSystemAdapter ? {
151
150
let connectionToSourceKitLSP = LocalConnection (
@@ -164,7 +163,7 @@ private extension BuildSystemSpec {
164
163
let buildSystemAdapter = BuiltInBuildSystemAdapter (
165
164
underlyingBuildSystem: buildSystem,
166
165
connectionToSourceKitLSP: connectionToSourceKitLSP,
167
- buildSystemTestHooks : buildSystemTestHooks
166
+ buildSystemHooks : buildSystemHooks
168
167
)
169
168
let connectionToBuildSystem = LocalConnection (
170
169
receiverName: " \( type ( of: buildSystem) ) for \( projectRoot. lastPathComponent) "
@@ -178,14 +177,15 @@ private extension BuildSystemSpec {
178
177
func createBuildSystemAdapter(
179
178
toolchainRegistry: ToolchainRegistry ,
180
179
options: SourceKitLSPOptions ,
181
- buildSystemTestHooks testHooks : BuildSystemTestHooks ,
180
+ buildSystemHooks : BuildSystemHooks ,
182
181
messagesToSourceKitLSPHandler: any MessageHandler
183
182
) async -> BuildSystemAdapter ? {
184
183
switch self . kind {
185
184
case . buildServer:
186
185
let buildSystem = await orLog ( " Creating external build system " ) {
187
186
try await ExternalBuildSystemAdapter (
188
187
projectRoot: projectRoot,
188
+ configPath: configPath,
189
189
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler
190
190
)
191
191
}
@@ -196,40 +196,38 @@ private extension BuildSystemSpec {
196
196
logger. log ( " Created external build server at \( projectRoot) " )
197
197
return . external( buildSystem)
198
198
case . compilationDatabase:
199
- return await Self . createBuiltInBuildSystemAdapter (
200
- projectRoot: projectRoot,
199
+ return await createBuiltInBuildSystemAdapter (
201
200
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
202
- buildSystemTestHooks : testHooks
201
+ buildSystemHooks : buildSystemHooks
203
202
) { connectionToSourceKitLSP in
204
- CompilationDatabaseBuildSystem (
205
- projectRoot: projectRoot,
206
- searchPaths: ( options. compilationDatabaseOrDefault. searchPaths ?? [ ] ) . compactMap {
207
- try ? RelativePath ( validating: $0)
208
- } ,
203
+ try CompilationDatabaseBuildSystem (
204
+ configPath: configPath,
209
205
connectionToSourceKitLSP: connectionToSourceKitLSP
210
206
)
211
207
}
212
208
case . swiftPM:
213
- return await Self . createBuiltInBuildSystemAdapter (
214
- projectRoot : projectRoot ,
209
+ #if canImport(PackageModel)
210
+ return await createBuiltInBuildSystemAdapter (
215
211
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
216
- buildSystemTestHooks : testHooks
212
+ buildSystemHooks : buildSystemHooks
217
213
) { connectionToSourceKitLSP in
218
214
try await SwiftPMBuildSystem (
219
215
projectRoot: projectRoot,
220
216
toolchainRegistry: toolchainRegistry,
221
217
options: options,
222
218
connectionToSourceKitLSP: connectionToSourceKitLSP,
223
- testHooks: testHooks . swiftPMTestHooks
219
+ testHooks: buildSystemHooks . swiftPMTestHooks
224
220
)
225
221
}
226
- case . testBuildSystem:
227
- return await Self . createBuiltInBuildSystemAdapter (
228
- projectRoot: projectRoot,
222
+ #else
223
+ return nil
224
+ #endif
225
+ case . injected( let injector) :
226
+ return await createBuiltInBuildSystemAdapter (
229
227
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
230
- buildSystemTestHooks : testHooks
228
+ buildSystemHooks : buildSystemHooks
231
229
) { connectionToSourceKitLSP in
232
- TestBuildSystem ( projectRoot: projectRoot, connectionToSourceKitLSP: connectionToSourceKitLSP)
230
+ await injector . createBuildSystem ( projectRoot: projectRoot, connectionToSourceKitLSP: connectionToSourceKitLSP)
233
231
}
234
232
}
235
233
}
@@ -244,13 +242,14 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
244
242
245
243
package let messageHandlingQueue = AsyncQueue < BuildSystemMessageDependencyTracker > ( )
246
244
247
- /// The root of the project that this build system manages.
245
+ /// The path to the main configuration file (or directory) that this build system manages.
248
246
///
249
- /// For example, in SwiftPM packages this is the folder containing Package.swift.
250
- /// For compilation databases it is the root folder based on which the compilation database was found.
247
+ /// Some examples:
248
+ /// - The path to `Package.swift` for SwiftPM packages
249
+ /// - The path to `compile_commands.json` for a JSON compilation database
251
250
///
252
251
/// `nil` if the `BuildSystemManager` does not have an underlying build system.
253
- package let projectRoot : URL ?
252
+ package let configPath : URL ?
254
253
255
254
/// The files for which the delegate has requested change notifications, ie. the files for which the delegate wants to
256
255
/// get `fileBuildSettingsChanged` and `filesDependenciesUpdated` callbacks.
@@ -271,19 +270,6 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
271
270
}
272
271
}
273
272
274
- /// If the underlying build system is a `TestBuildSystem`, return it. Otherwise, `nil`
275
- ///
276
- /// - Important: For testing purposes only.
277
- package var testBuildSystem : TestBuildSystem ? {
278
- get async {
279
- switch buildSystemAdapter {
280
- case . builtIn( let builtInBuildSystemAdapter, _) : return await builtInBuildSystemAdapter. testBuildSystem
281
- case . external: return nil
282
- case nil : return nil
283
- }
284
- }
285
- }
286
-
287
273
/// Provider of file to main file mappings.
288
274
private var mainFilesProvider : MainFilesProvider ?
289
275
@@ -363,16 +349,16 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
363
349
toolchainRegistry: ToolchainRegistry ,
364
350
options: SourceKitLSPOptions ,
365
351
connectionToClient: BuildSystemManagerConnectionToClient ,
366
- buildSystemTestHooks : BuildSystemTestHooks
352
+ buildSystemHooks : BuildSystemHooks
367
353
) async {
368
354
self . toolchainRegistry = toolchainRegistry
369
355
self . options = options
370
356
self . connectionToClient = connectionToClient
371
- self . projectRoot = buildSystemSpec? . projectRoot
357
+ self . configPath = buildSystemSpec? . configPath
372
358
self . buildSystemAdapter = await buildSystemSpec? . createBuildSystemAdapter (
373
359
toolchainRegistry: toolchainRegistry,
374
360
options: options,
375
- buildSystemTestHooks : buildSystemTestHooks ,
361
+ buildSystemHooks : buildSystemHooks ,
376
362
messagesToSourceKitLSPHandler: WeakMessageHandler ( self )
377
363
)
378
364
@@ -422,13 +408,14 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
422
408
logger. log ( " Launched a legacy BSP server. Using push-based build settings model. " )
423
409
let legacyBuildServer = await LegacyBuildServerBuildSystem (
424
410
projectRoot: buildSystemSpec. projectRoot,
411
+ configPath: buildSystemSpec. configPath,
425
412
initializationData: initializeResponse,
426
413
externalBuildSystemAdapter
427
414
)
428
415
let adapter = BuiltInBuildSystemAdapter (
429
416
underlyingBuildSystem: legacyBuildServer,
430
417
connectionToSourceKitLSP: legacyBuildServer. connectionToSourceKitLSP,
431
- buildSystemTestHooks : buildSystemTestHooks
418
+ buildSystemHooks : buildSystemHooks
432
419
)
433
420
let connectionToBuildSystem = LocalConnection ( receiverName: " Legacy BSP server " )
434
421
connectionToBuildSystem. start ( handler: adapter)
@@ -688,8 +675,8 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
688
675
result. formUnion ( targets)
689
676
}
690
677
if !filesAndDirectories. directories. isEmpty, let documentPathComponents = document. fileURL? . pathComponents {
691
- for (directory , ( directoryPathComponents, info) ) in filesAndDirectories. directories {
692
- guard let directoryPathComponents, let directoryPath = directory . fileURL else {
678
+ for (_ , ( directoryPathComponents, info) ) in filesAndDirectories. directories {
679
+ guard let directoryPathComponents else {
693
680
continue
694
681
}
695
682
if isDescendant ( documentPathComponents, of: directoryPathComponents) {
0 commit comments