@@ -95,71 +95,36 @@ 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
113
145
- return await task. value
146
- }
147
- }
148
-
149
- var fileToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
150
- var sourceDirToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
114
+ private var fileToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
115
+ private var sourceDirToTarget : [ DocumentURI : SwiftBuildTarget ] = [ : ]
151
116
152
117
/// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
153
118
///
154
119
/// 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 ) ] = [ : ]
120
+ private var targets : [ ConfiguredTarget : ( index: Int , buildTarget: SwiftBuildTarget ) ] = [ : ]
156
121
157
122
/// The URIs for which the delegate has registered for change notifications,
158
123
/// mapped to the language the delegate specified when registering for change notifications.
159
- var watchedFiles : Set < DocumentURI > = [ ]
124
+ private var watchedFiles : Set < DocumentURI > = [ ]
160
125
161
126
/// This callback is informed when `reloadPackage` starts and ends executing.
162
- var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
127
+ private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
163
128
164
129
/// Debounces calls to `delegate.filesDependenciesUpdated`.
165
130
///
@@ -169,16 +134,19 @@ public actor SwiftPMBuildSystem {
169
134
/// `fileDependenciesUpdated` call once for every updated file within the target.
170
135
///
171
136
/// Force-unwrapped optional because initializing it requires access to `self`.
172
- var fileDependenciesUpdatedDebouncer : Debouncer < Set < DocumentURI > > ! = nil
137
+ private var fileDependenciesUpdatedDebouncer : Debouncer < Set < DocumentURI > > ! = nil
173
138
174
139
/// A `ObservabilitySystem` from `SwiftPM` that logs.
175
140
private let observabilitySystem = ObservabilitySystem ( { scope, diagnostic in
176
141
logger. log ( level: diagnostic. severity. asLogLevel, " SwiftPM log: \( diagnostic. description) " )
177
142
} )
178
143
144
+ /// Whether to pass `--experimental-prepare-for-indexing` to `swift build` as part of preparation.
145
+ private let experimentalFeatures : Set < ExperimentalFeature >
146
+
179
147
/// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
180
148
/// user's build.
181
- private let isForIndexBuild : Bool
149
+ private var isForIndexBuild : Bool { experimentalFeatures . contains ( . backgroundIndexing ) }
182
150
183
151
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
184
152
///
@@ -193,13 +161,13 @@ public actor SwiftPMBuildSystem {
193
161
toolchainRegistry: ToolchainRegistry ,
194
162
fileSystem: FileSystem = localFileSystem,
195
163
buildSetup: BuildSetup ,
196
- isForIndexBuild : Bool ,
164
+ experimentalFeatures : Set < ExperimentalFeature > ,
197
165
reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void = { _ in }
198
166
) async throws {
199
167
self . workspacePath = workspacePath
200
168
self . fileSystem = fileSystem
201
169
self . toolchainRegistry = toolchainRegistry
202
- self . isForIndexBuild = isForIndexBuild
170
+ self . experimentalFeatures = experimentalFeatures
203
171
204
172
guard let packageRoot = findPackageDirectory ( containing: workspacePath, fileSystem) else {
205
173
throw Error . noManifest ( workspacePath: workspacePath)
@@ -218,7 +186,7 @@ public actor SwiftPMBuildSystem {
218
186
forRootPackage: AbsolutePath ( packageRoot) ,
219
187
fileSystem: fileSystem
220
188
)
221
- if isForIndexBuild {
189
+ if experimentalFeatures . contains ( . backgroundIndexing ) {
222
190
location. scratchDirectory = AbsolutePath ( packageRoot. appending ( component: " .index-build " ) )
223
191
} else if let scratchDirectory = buildSetup. path {
224
192
location. scratchDirectory = AbsolutePath ( scratchDirectory)
@@ -289,7 +257,7 @@ public actor SwiftPMBuildSystem {
289
257
uri: DocumentURI ,
290
258
toolchainRegistry: ToolchainRegistry ,
291
259
buildSetup: BuildSetup ,
292
- isForIndexBuild : Bool ,
260
+ experimentalFeatures : Set < ExperimentalFeature > ,
293
261
reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void
294
262
) async {
295
263
guard let fileURL = uri. fileURL else {
@@ -301,7 +269,7 @@ public actor SwiftPMBuildSystem {
301
269
toolchainRegistry: toolchainRegistry,
302
270
fileSystem: localFileSystem,
303
271
buildSetup: buildSetup,
304
- isForIndexBuild : isForIndexBuild ,
272
+ experimentalFeatures : experimentalFeatures ,
305
273
reloadPackageStatusCallback: reloadPackageStatusCallback
306
274
)
307
275
} catch Error . noManifest {
@@ -612,7 +580,7 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
612
580
arguments += self . destinationBuildParameters. flags. swiftCompilerFlags. flatMap { [ " -Xswiftc " , $0] }
613
581
arguments += self . destinationBuildParameters. flags. linkerFlags. flatMap { [ " -Xlinker " , $0] }
614
582
arguments += self . destinationBuildParameters. flags. xcbuildFlags? . flatMap { [ " -Xxcbuild " , $0] } ?? [ ]
615
- if await swiftBuildSupportsPrepareForIndexing {
583
+ if experimentalFeatures . contains ( . swiftpmPrepareForIndexing ) {
616
584
arguments. append ( " --experimental-prepare-for-indexing " )
617
585
}
618
586
if Task . isCancelled {
0 commit comments