@@ -95,71 +95,35 @@ public actor SwiftPMBuildSystem {
95
95
}
96
96
97
97
/// Callbacks that should be called if the list of possible test files has changed.
98
- public var testFilesDidChangeCallbacks : [ ( ) async -> Void ] = [ ]
98
+ private var testFilesDidChangeCallbacks : [ ( ) async -> Void ] = [ ]
99
99
100
- let workspacePath : TSCAbsolutePath
100
+ private let workspacePath : TSCAbsolutePath
101
101
/// The directory containing `Package.swift`.
102
+ @_spi ( Testing)
102
103
public var projectRoot : TSCAbsolutePath
103
- var modulesGraph : ModulesGraph
104
- let workspace : Workspace
105
- public let toolsBuildParameters : BuildParameters
106
- public let destinationBuildParameters : BuildParameters
107
- let fileSystem : FileSystem
104
+ private var modulesGraph : ModulesGraph
105
+ private let workspace : Workspace
106
+ @ _spi ( Testing ) public let toolsBuildParameters : BuildParameters
107
+ @ _spi ( Testing ) public let destinationBuildParameters : BuildParameters
108
+ private let fileSystem : FileSystem
108
109
private let toolchainRegistry : ToolchainRegistry
109
110
110
111
private let swiftBuildSupportsPrepareForIndexingTask = SKSupport . ThreadSafeBox < Task < Bool , Never > ? > ( initialValue: nil )
111
112
112
- #if compiler(>=6.1)
113
- #warning(
114
- " Remove swiftBuildSupportsPrepareForIndexing when we no longer need to support SwiftPM versions that don't have support for `--experimental-prepare-for-indexing` "
115
- )
116
- #endif
117
- /// Whether `swift build` supports the `--experimental-prepare-for-indexing` flag.
118
- private var swiftBuildSupportsPrepareForIndexing : Bool {
119
- get async {
120
- let task = swiftBuildSupportsPrepareForIndexingTask. withLock { task in
121
- if let task {
122
- return task
123
- }
124
- let newTask = Task { ( ) -> Bool in
125
- guard let swift = await toolchainRegistry. default? . swift else {
126
- return false
127
- }
128
-
129
- do {
130
- let process = Process ( args: swift. pathString, " build " , " --help-hidden " )
131
- try process. launch ( )
132
- let result = try await process. waitUntilExit ( )
133
- guard let output = String ( bytes: try result. output. get ( ) , encoding: . utf8) else {
134
- return false
135
- }
136
- return output. contains ( " --experimental-prepare-for-indexing " )
137
- } catch {
138
- return false
139
- }
140
- }
141
- task = newTask
142
- return newTask
143
- }
144
-
145
- return await task. value
146
- }
147
- }
148
-
149
- var fileToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
150
- var sourceDirToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
113
+ private var fileToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
114
+ private var sourceDirToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
151
115
152
116
/// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
153
117
///
154
118
/// Targets with lower index are more low level, ie. targets with higher indices depend on targets with lower indices.
155
- var targets : [ ConfiguredTarget : ( index: Int , buildTarget: SwiftBuildTarget ) ] = [ : ]
119
+ private var targets : [ ConfiguredTarget : ( index: Int , buildTarget: SwiftBuildTarget ) ] = [ : ]
156
120
157
121
/// The URIs for which the delegate has registered for change notifications,
158
122
/// mapped to the language the delegate specified when registering for change notifications.
159
- var watchedFiles : Set < DocumentURI > = [ ]
123
+ private var watchedFiles : Set < DocumentURI > = [ ]
160
124
161
125
/// This callback is informed when `reloadPackage` starts and ends executing.
162
- var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
126
+ private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
163
127
164
128
/// Debounces calls to `delegate.filesDependenciesUpdated`.
165
129
///
@@ -169,16 +133,19 @@ public actor SwiftPMBuildSystem {
169
133
/// `fileDependenciesUpdated` call once for every updated file within the target.
170
134
///
171
135
/// Force-unwrapped optional because initializing it requires access to `self`.
172
- var fileDependenciesUpdatedDebouncer : Debouncer < Set < DocumentURI > > ! = nil
136
+ private var fileDependenciesUpdatedDebouncer : Debouncer < Set < DocumentURI > > ! = nil
173
137
174
138
/// A `ObservabilitySystem` from `SwiftPM` that logs.
175
139
private let observabilitySystem = ObservabilitySystem ( { scope, diagnostic in
176
140
logger. log ( level: diagnostic. severity. asLogLevel, " SwiftPM log: \( diagnostic. description) " )
177
141
} )
178
142
143
+ /// Whether to pass `--experimental-prepare-for-indexing` to `swift build` as part of preparation.
144
+ private let experimentalFeatures : Set < ExperimentalFeature >
145
+
179
146
/// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
180
147
/// user's build.
181
- private let isForIndexBuild : Bool
148
+ private var isForIndexBuild : Bool { experimentalFeatures . contains ( . backgroundIndexing ) }
182
149
183
150
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
184
151
///
@@ -193,13 +160,13 @@ public actor SwiftPMBuildSystem {
193
160
toolchainRegistry: ToolchainRegistry ,
194
161
fileSystem: FileSystem = localFileSystem,
195
162
buildSetup: BuildSetup ,
196
- isForIndexBuild : Bool ,
163
+ experimentalFeatures : Set < ExperimentalFeature > ,
197
164
reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void = { _ in }
198
165
) async throws {
199
166
self . workspacePath = workspacePath
200
167
self . fileSystem = fileSystem
201
168
self . toolchainRegistry = toolchainRegistry
202
- self . isForIndexBuild = isForIndexBuild
169
+ self . experimentalFeatures = experimentalFeatures
203
170
204
171
guard let packageRoot = findPackageDirectory ( containing: workspacePath, fileSystem) else {
205
172
throw Error . noManifest ( workspacePath: workspacePath)
@@ -218,7 +185,7 @@ public actor SwiftPMBuildSystem {
218
185
forRootPackage: AbsolutePath ( packageRoot) ,
219
186
fileSystem: fileSystem
220
187
)
221
- if isForIndexBuild {
188
+ if experimentalFeatures . contains ( . backgroundIndexing ) {
222
189
location. scratchDirectory = AbsolutePath ( packageRoot. appending ( component: " .index-build " ) )
223
190
} else if let scratchDirectory = buildSetup. path {
224
191
location. scratchDirectory = AbsolutePath ( scratchDirectory)
@@ -289,7 +256,7 @@ public actor SwiftPMBuildSystem {
289
256
uri: DocumentURI ,
290
257
toolchainRegistry: ToolchainRegistry ,
291
258
buildSetup: BuildSetup ,
292
- isForIndexBuild : Bool ,
259
+ experimentalFeatures : Set < ExperimentalFeature > ,
293
260
reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void
294
261
) async {
295
262
guard let fileURL = uri. fileURL else {
@@ -301,7 +268,7 @@ public actor SwiftPMBuildSystem {
301
268
toolchainRegistry: toolchainRegistry,
302
269
fileSystem: localFileSystem,
303
270
buildSetup: buildSetup,
304
- isForIndexBuild : isForIndexBuild ,
271
+ experimentalFeatures : experimentalFeatures ,
305
272
reloadPackageStatusCallback: reloadPackageStatusCallback
306
273
)
307
274
} catch Error . noManifest {
@@ -612,7 +579,7 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
612
579
arguments += self . destinationBuildParameters. flags. swiftCompilerFlags. flatMap { [ " -Xswiftc " , $0] }
613
580
arguments += self . destinationBuildParameters. flags. linkerFlags. flatMap { [ " -Xlinker " , $0] }
614
581
arguments += self . destinationBuildParameters. flags. xcbuildFlags? . flatMap { [ " -Xxcbuild " , $0] } ?? [ ]
615
- if await swiftBuildSupportsPrepareForIndexing {
582
+ if experimentalFeatures . contains ( . swiftpmPrepareForIndexing ) {
616
583
arguments. append ( " --experimental-prepare-for-indexing " )
617
584
}
618
585
if Task . isCancelled {
0 commit comments