@@ -128,12 +128,9 @@ public actor SwiftPMBuildSystem {
128
128
logger. log ( level: diagnostic. severity. asLogLevel, " SwiftPM log: \( diagnostic. description) " )
129
129
} )
130
130
131
- /// Whether the SwiftPMBuildSystem may modify `Package.resolved` or not.
132
- ///
133
- /// This is `false` if the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
134
- /// user's build. In this case `SwiftPMBuildSystem` is allowed to clone repositories even if no `Package.resolved`
135
- /// exists.
136
- private let forceResolvedVersions : Bool
131
+ /// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
132
+ /// user's build.
133
+ private let isForIndexBuild : Bool
137
134
138
135
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
139
136
///
@@ -148,13 +145,13 @@ public actor SwiftPMBuildSystem {
148
145
toolchainRegistry: ToolchainRegistry ,
149
146
fileSystem: FileSystem = localFileSystem,
150
147
buildSetup: BuildSetup ,
151
- forceResolvedVersions : Bool ,
148
+ isForIndexBuild : Bool ,
152
149
reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void = { _ in }
153
150
) async throws {
154
151
self . workspacePath = workspacePath
155
152
self . fileSystem = fileSystem
156
153
self . toolchainRegistry = toolchainRegistry
157
- self . forceResolvedVersions = forceResolvedVersions
154
+ self . isForIndexBuild = isForIndexBuild
158
155
159
156
guard let packageRoot = findPackageDirectory ( containing: workspacePath, fileSystem) else {
160
157
throw Error . noManifest ( workspacePath: workspacePath)
@@ -234,7 +231,7 @@ public actor SwiftPMBuildSystem {
234
231
url: URL ,
235
232
toolchainRegistry: ToolchainRegistry ,
236
233
buildSetup: BuildSetup ,
237
- forceResolvedVersions : Bool ,
234
+ isForIndexBuild : Bool ,
238
235
reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void
239
236
) async {
240
237
do {
@@ -243,7 +240,7 @@ public actor SwiftPMBuildSystem {
243
240
toolchainRegistry: toolchainRegistry,
244
241
fileSystem: localFileSystem,
245
242
buildSetup: buildSetup,
246
- forceResolvedVersions : forceResolvedVersions ,
243
+ isForIndexBuild : isForIndexBuild ,
247
244
reloadPackageStatusCallback: reloadPackageStatusCallback
248
245
)
249
246
} catch Error . noManifest {
@@ -272,7 +269,7 @@ extension SwiftPMBuildSystem {
272
269
273
270
let modulesGraph = try self . workspace. loadPackageGraph (
274
271
rootInput: PackageGraphRootInput ( packages: [ AbsolutePath ( projectRoot) ] ) ,
275
- forceResolvedVersions: forceResolvedVersions ,
272
+ forceResolvedVersions: !isForIndexBuild ,
276
273
observabilityScope: observabilitySystem. topScope
277
274
)
278
275
@@ -430,6 +427,8 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
430
427
for target in targets {
431
428
try await prepare ( singleTarget: target)
432
429
}
430
+ let filesInPreparedTargets = targets. flatMap { self . targets [ $0. targetID] ? . buildTarget. sources ?? [ ] }
431
+ await fileDependenciesUpdatedDebouncer. scheduleCall ( Set ( filesInPreparedTargets. map ( DocumentURI . init) ) )
433
432
}
434
433
435
434
private func prepare( singleTarget target: ConfiguredTarget ) async throws {
@@ -561,9 +560,9 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
561
560
// The file watching here is somewhat fragile as well because it assumes that the `.swiftmodule` files are being
562
561
// written to a directory within the workspace root. This is not necessarily true if the user specifies a build
563
562
// directory outside the source tree.
564
- // All of this shouldn't be necessary once we have background preparation, in which case we know when preparation of
565
- // a target has finished .
566
- if events. contains ( where: { $0. uri. fileURL? . pathExtension == " swiftmodule " } ) {
563
+ // If we have background indexing enabled, this is not necessary because we call `fileDependenciesUpdated` when
564
+ // preparation of a target finishes .
565
+ if !isForIndexBuild , events. contains ( where: { $0. uri. fileURL? . pathExtension == " swiftmodule " } ) {
567
566
filesWithUpdatedDependencies. formUnion ( self . fileToTarget. keys. map { DocumentURI ( $0. asURL) } )
568
567
}
569
568
await self . fileDependenciesUpdatedDebouncer. scheduleCall ( filesWithUpdatedDependencies)
0 commit comments