@@ -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,43 @@ 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
+ // We have a whole separate arena if we're performing background indexing. This allows us to also build and run
366
+ // plugins, without having to worry about messing up any regular build state.
367
+ let buildDescription : SourceKitLSPAPI . BuildDescription
368
+ if isForIndexBuild {
369
+ let loaded = try await BuildDescription . load (
370
+ destinationBuildParameters: destinationBuildParameters,
371
+ toolsBuildParameters: toolsBuildParameters,
372
+ packageGraph: modulesGraph,
373
+ pluginConfiguration: pluginConfiguration,
374
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
375
+ scratchDirectory: swiftPMWorkspace. location. scratchDirectory. asURL,
376
+ fileSystem: localFileSystem,
377
+ observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build description " )
378
+ )
379
+ if !loaded. errors. isEmpty {
380
+ logger. error ( " Loading SwiftPM description had errors: \( loaded. errors) " )
381
+ }
382
+
383
+ buildDescription = loaded. description
384
+ } else {
385
+ let plan = try await BuildPlan (
386
+ destinationBuildParameters: destinationBuildParameters,
387
+ toolsBuildParameters: toolsBuildParameters,
388
+ graph: modulesGraph,
389
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
390
+ fileSystem: localFileSystem,
391
+ observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build plan " )
392
+ )
393
+
394
+ buildDescription = BuildDescription ( buildPlan: plan)
395
+ }
363
396
364
397
/// Make sure to execute any throwing statements before setting any
365
398
/// properties because otherwise we might end up in an inconsistent state
366
399
/// with only some properties modified.
367
400
401
+ self . buildDescription = buildDescription
368
402
self . swiftPMTargets = [ : ]
369
403
self . targetDependencies = [ : ]
370
404
0 commit comments