@@ -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
@@ -131,6 +131,8 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
131
131
private let toolchain : Toolchain
132
132
private let swiftPMWorkspace : Workspace
133
133
134
+ private let pluginConfiguration : PluginConfiguration
135
+
134
136
/// A `ObservabilitySystem` from `SwiftPM` that logs.
135
137
private let observabilitySystem : ObservabilitySystem
136
138
@@ -170,13 +172,10 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
170
172
) async throws {
171
173
self . projectRoot = projectRoot
172
174
self . options = options
173
- self . fileWatchers =
174
- try [ " Package.swift " , " Package@swift*.swift " , " Package.resolved " ] . map {
175
- FileSystemWatcher ( globPattern: try projectRoot. appendingPathComponent ( $0) . filePath, kind: [ . change] )
176
- }
177
- + FileRuleDescription. builtinRules. flatMap ( { $0. fileTypes } ) . map { fileExtension in
178
- FileSystemWatcher ( globPattern: " **/*. \( fileExtension) " , kind: [ . create, . change, . delete] )
179
- }
175
+ // We could theoretically dynamically register all known files when we get back the build graph, but that seems
176
+ // more errorprone than just watching everything and then filtering when we need to (eg. in
177
+ // `SemanticIndexManager.filesDidChange`).
178
+ self . fileWatchers = [ FileSystemWatcher ( globPattern: " **/* " , kind: [ . create, . change, . delete] ) ]
180
179
let toolchain = await toolchainRegistry. preferredToolchain ( containing: [
181
180
\. clang, \. clangd, \. sourcekitd, \. swift, \. swiftc,
182
181
] )
@@ -291,6 +290,19 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
291
290
prepareForIndexing: options. backgroundPreparationModeOrDefault. toSwiftPMPreparation
292
291
)
293
292
293
+ let pluginScriptRunner = DefaultPluginScriptRunner (
294
+ fileSystem: localFileSystem,
295
+ cacheDir: location. pluginWorkingDirectory. appending ( " cache " ) ,
296
+ toolchain: hostSwiftPMToolchain,
297
+ extraPluginSwiftCFlags: [ ] ,
298
+ enableSandbox: !( options. swiftPMOrDefault. disableSandbox ?? false )
299
+ )
300
+ self . pluginConfiguration = PluginConfiguration (
301
+ scriptRunner: pluginScriptRunner,
302
+ workDirectory: location. pluginWorkingDirectory,
303
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false
304
+ )
305
+
294
306
packageLoadingQueue. async {
295
307
await orLog ( " Initial package loading " ) {
296
308
// Schedule an initial generation of the build graph. Once the build graph is loaded, the build system will send
@@ -334,24 +346,47 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
334
346
335
347
signposter. emitEvent ( " Finished loading modules graph " , id: signpostID)
336
348
337
- let plan = try await BuildPlan (
338
- destinationBuildParameters: destinationBuildParameters,
339
- toolsBuildParameters: toolsBuildParameters,
340
- graph: modulesGraph,
341
- disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
342
- fileSystem: localFileSystem,
343
- observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build plan " )
344
- )
349
+ // We have a whole separate arena if we're performing background indexing. This allows us to also build and run
350
+ // plugins, without having to worry about messing up any regular build state.
351
+ let buildDescription : SourceKitLSPAPI . BuildDescription
352
+ if isForIndexBuild {
353
+ let loaded = try await BuildDescription . load (
354
+ destinationBuildParameters: destinationBuildParameters,
355
+ toolsBuildParameters: toolsBuildParameters,
356
+ packageGraph: modulesGraph,
357
+ pluginConfiguration: pluginConfiguration,
358
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
359
+ scratchDirectory: swiftPMWorkspace. location. scratchDirectory. asURL,
360
+ fileSystem: localFileSystem,
361
+ observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build description " )
362
+ )
363
+ if !loaded. errors. isEmpty {
364
+ logger. error ( " Loading SwiftPM description had errors: \( loaded. errors) " )
365
+ }
345
366
346
- signposter. emitEvent ( " Finished generating build plan " , id: signpostID)
367
+ signposter. emitEvent ( " Finished generating build description " , id: signpostID)
347
368
348
- let buildDescription = BuildDescription ( buildPlan: plan)
349
- self . buildDescription = buildDescription
369
+ buildDescription = loaded. description
370
+ } else {
371
+ let plan = try await BuildPlan (
372
+ destinationBuildParameters: destinationBuildParameters,
373
+ toolsBuildParameters: toolsBuildParameters,
374
+ graph: modulesGraph,
375
+ disableSandbox: options. swiftPMOrDefault. disableSandbox ?? false ,
376
+ fileSystem: localFileSystem,
377
+ observabilityScope: observabilitySystem. topScope. makeChildScope ( description: " Create SwiftPM build plan " )
378
+ )
379
+
380
+ signposter. emitEvent ( " Finished generating build plan " , id: signpostID)
381
+
382
+ buildDescription = BuildDescription ( buildPlan: plan)
383
+ }
350
384
351
385
/// Make sure to execute any throwing statements before setting any
352
386
/// properties because otherwise we might end up in an inconsistent state
353
387
/// with only some properties modified.
354
388
389
+ self . buildDescription = buildDescription
355
390
self . swiftPMTargets = [ : ]
356
391
self . targetDependencies = [ : ]
357
392
0 commit comments