@@ -33,15 +33,15 @@ package import BuildServerProtocol
33
33
package import Foundation
34
34
package import LanguageServerProtocol
35
35
package import SKOptions
36
- package import SourceKitLSPAPI
36
+ @ preconcurrency package import SourceKitLSPAPI
37
37
package import ToolchainRegistry
38
38
package import class ToolchainRegistry. Toolchain
39
39
#else
40
40
import BuildServerProtocol
41
41
import Foundation
42
42
import LanguageServerProtocol
43
43
import SKOptions
44
- import SourceKitLSPAPI
44
+ @ preconcurrency import SourceKitLSPAPI
45
45
import ToolchainRegistry
46
46
import class ToolchainRegistry. Toolchain
47
47
#endif
@@ -153,6 +153,8 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
153
153
private let toolchain : Toolchain
154
154
private let swiftPMWorkspace : Workspace
155
155
156
+ private let pluginConfiguration : PluginConfiguration
157
+
156
158
/// A `ObservabilitySystem` from `SwiftPM` that logs.
157
159
private let observabilitySystem : ObservabilitySystem
158
160
@@ -192,13 +194,10 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
192
194
) async throws {
193
195
self . projectRoot = projectRoot
194
196
self . options = options
195
- self . fileWatchers =
196
- try [ " Package.swift " , " Package@swift*.swift " , " Package.resolved " ] . map {
197
- FileSystemWatcher ( globPattern: try projectRoot. appendingPathComponent ( $0) . filePath, kind: [ . change] )
198
- }
199
- + FileRuleDescription. builtinRules. flatMap ( { $0. fileTypes } ) . map { fileExtension in
200
- FileSystemWatcher ( globPattern: " **/*. \( fileExtension) " , kind: [ . create, . change, . delete] )
201
- }
197
+ // We could theoretically dynamically register all known files when we get back the build graph, but that seems
198
+ // more errorprone than just watching everything and then filtering when we need to (eg. in
199
+ // `SemanticIndexManager.filesDidChange`).
200
+ self . fileWatchers = [ FileSystemWatcher ( globPattern: " **/* " , kind: [ . create, . change, . delete] ) ]
202
201
let toolchain = await toolchainRegistry. preferredToolchain ( containing: [
203
202
\. clang, \. clangd, \. sourcekitd, \. swift, \. swiftc,
204
203
] )
@@ -313,6 +312,19 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
313
312
prepareForIndexing: options. backgroundPreparationModeOrDefault. toSwiftPMPreparation
314
313
)
315
314
315
+ let pluginScriptRunner = DefaultPluginScriptRunner (
316
+ fileSystem: localFileSystem,
317
+ cacheDir: location. pluginWorkingDirectory. appending ( " cache " ) ,
318
+ toolchain: hostSwiftPMToolchain,
319
+ extraPluginSwiftCFlags: [ ] ,
320
+ enableSandbox: !( options. swiftPMOrDefault. disableSandbox ?? false )
321
+ )
322
+ self . pluginConfiguration = PluginConfiguration (
323
+ scriptRunner: pluginScriptRunner,
324
+ workDirectory: location. pluginWorkingDirectory,
325
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false
326
+ )
327
+
316
328
packageLoadingQueue. async {
317
329
await orLog ( " Initial package loading " ) {
318
330
// Schedule an initial generation of the build graph. Once the build graph is loaded, the build system will send
@@ -350,21 +362,49 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
350
362
observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Load package graph " )
351
363
)
352
364
353
- let plan = try await BuildPlan (
354
- destinationBuildParameters: destinationBuildParameters,
355
- toolsBuildParameters: toolsBuildParameters,
356
- graph: modulesGraph,
357
- disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
358
- fileSystem: localFileSystem,
359
- observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build plan " )
360
- )
361
- let buildDescription = BuildDescription ( buildPlan: plan)
362
- self . buildDescription = buildDescription
365
+ signposter. emitEvent ( " Finished loading modules graph " , id: signpostID)
366
+
367
+ // We have a whole separate arena if we're performing background indexing. This allows us to also build and run
368
+ // plugins, without having to worry about messing up any regular build state.
369
+ let buildDescription : SourceKitLSPAPI . BuildDescription
370
+ if isForIndexBuild {
371
+ let loaded = try await BuildDescription . load (
372
+ destinationBuildParameters: destinationBuildParameters,
373
+ toolsBuildParameters: toolsBuildParameters,
374
+ packageGraph: modulesGraph,
375
+ pluginConfiguration: pluginConfiguration,
376
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
377
+ scratchDirectory: swiftPMWorkspace. location. scratchDirectory. asURL,
378
+ fileSystem: localFileSystem,
379
+ observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build description " )
380
+ )
381
+ if !loaded. errors. isEmpty {
382
+ logger. error ( " Loading SwiftPM description had errors: \( loaded. errors) " )
383
+ }
384
+
385
+ signposter. emitEvent ( " Finished generating build description " , id: signpostID)
386
+
387
+ buildDescription = loaded. description
388
+ } else {
389
+ let plan = try await BuildPlan (
390
+ destinationBuildParameters: destinationBuildParameters,
391
+ toolsBuildParameters: toolsBuildParameters,
392
+ graph: modulesGraph,
393
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
394
+ fileSystem: localFileSystem,
395
+ observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build plan " )
396
+ )
397
+
398
+ signposter. emitEvent ( " Finished generating build plan " , id: signpostID)
399
+
400
+ buildDescription = BuildDescription ( buildPlan: plan)
401
+ }
363
402
364
403
/// Make sure to execute any throwing statements before setting any
365
404
/// properties because otherwise we might end up in an inconsistent state
366
405
/// with only some properties modified.
367
406
407
+ self . buildDescription = buildDescription
368
408
self . swiftPMTargets = [ : ]
369
409
self . targetDependencies = [ : ]
370
410
0 commit comments