@@ -95,71 +95,35 @@ public actor SwiftPMBuildSystem {
9595 }
9696
9797 /// 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 ] = [ ]
9999
100- let workspacePath : TSCAbsolutePath
100+ private let workspacePath : TSCAbsolutePath
101101 /// The directory containing `Package.swift`.
102+ @_spi ( Testing)
102103 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
108109 private let toolchainRegistry : ToolchainRegistry
109110
110111 private let swiftBuildSupportsPrepareForIndexingTask = SKSupport . ThreadSafeBox < Task < Bool , Never > ? > ( initialValue: nil )
111112
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 ] = [ : ]
151115
152116 /// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
153117 ///
154118 /// 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 ) ] = [ : ]
156120
157121 /// The URIs for which the delegate has registered for change notifications,
158122 /// mapped to the language the delegate specified when registering for change notifications.
159- var watchedFiles : Set < DocumentURI > = [ ]
123+ private var watchedFiles : Set < DocumentURI > = [ ]
160124
161125 /// This callback is informed when `reloadPackage` starts and ends executing.
162- var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
126+ private var reloadPackageStatusCallback : ( ReloadPackageStatus ) async -> Void
163127
164128 /// Debounces calls to `delegate.filesDependenciesUpdated`.
165129 ///
@@ -169,16 +133,19 @@ public actor SwiftPMBuildSystem {
169133 /// `fileDependenciesUpdated` call once for every updated file within the target.
170134 ///
171135 /// 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
173137
174138 /// A `ObservabilitySystem` from `SwiftPM` that logs.
175139 private let observabilitySystem = ObservabilitySystem ( { scope, diagnostic in
176140 logger. log ( level: diagnostic. severity. asLogLevel, " SwiftPM log: \( diagnostic. description) " )
177141 } )
178142
143+ /// Whether to pass `--experimental-prepare-for-indexing` to `swift build` as part of preparation.
144+ private let experimentalFeatures : Set < ExperimentalFeature >
145+
179146 /// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
180147 /// user's build.
181- private let isForIndexBuild : Bool
148+ private var isForIndexBuild : Bool { experimentalFeatures . contains ( . backgroundIndexing ) }
182149
183150 /// Creates a build system using the Swift Package Manager, if this workspace is a package.
184151 ///
@@ -193,13 +160,13 @@ public actor SwiftPMBuildSystem {
193160 toolchainRegistry: ToolchainRegistry ,
194161 fileSystem: FileSystem = localFileSystem,
195162 buildSetup: BuildSetup ,
196- isForIndexBuild : Bool ,
163+ experimentalFeatures : Set < ExperimentalFeature > ,
197164 reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void = { _ in }
198165 ) async throws {
199166 self . workspacePath = workspacePath
200167 self . fileSystem = fileSystem
201168 self . toolchainRegistry = toolchainRegistry
202- self . isForIndexBuild = isForIndexBuild
169+ self . experimentalFeatures = experimentalFeatures
203170
204171 guard let packageRoot = findPackageDirectory ( containing: workspacePath, fileSystem) else {
205172 throw Error . noManifest ( workspacePath: workspacePath)
@@ -218,7 +185,7 @@ public actor SwiftPMBuildSystem {
218185 forRootPackage: AbsolutePath ( packageRoot) ,
219186 fileSystem: fileSystem
220187 )
221- if isForIndexBuild {
188+ if experimentalFeatures . contains ( . backgroundIndexing ) {
222189 location. scratchDirectory = AbsolutePath ( packageRoot. appending ( component: " .index-build " ) )
223190 } else if let scratchDirectory = buildSetup. path {
224191 location. scratchDirectory = AbsolutePath ( scratchDirectory)
@@ -289,7 +256,7 @@ public actor SwiftPMBuildSystem {
289256 uri: DocumentURI ,
290257 toolchainRegistry: ToolchainRegistry ,
291258 buildSetup: BuildSetup ,
292- isForIndexBuild : Bool ,
259+ experimentalFeatures : Set < ExperimentalFeature > ,
293260 reloadPackageStatusCallback: @escaping ( ReloadPackageStatus ) async -> Void
294261 ) async {
295262 guard let fileURL = uri. fileURL else {
@@ -301,7 +268,7 @@ public actor SwiftPMBuildSystem {
301268 toolchainRegistry: toolchainRegistry,
302269 fileSystem: localFileSystem,
303270 buildSetup: buildSetup,
304- isForIndexBuild : isForIndexBuild ,
271+ experimentalFeatures : experimentalFeatures ,
305272 reloadPackageStatusCallback: reloadPackageStatusCallback
306273 )
307274 } catch Error . noManifest {
@@ -612,7 +579,7 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
612579 arguments += self . destinationBuildParameters. flags. swiftCompilerFlags. flatMap { [ " -Xswiftc " , $0] }
613580 arguments += self . destinationBuildParameters. flags. linkerFlags. flatMap { [ " -Xlinker " , $0] }
614581 arguments += self . destinationBuildParameters. flags. xcbuildFlags? . flatMap { [ " -Xxcbuild " , $0] } ?? [ ]
615- if await swiftBuildSupportsPrepareForIndexing {
582+ if experimentalFeatures . contains ( . swiftpmPrepareForIndexing ) {
616583 arguments. append ( " --experimental-prepare-for-indexing " )
617584 }
618585 if Task . isCancelled {
0 commit comments