Skip to content

Commit e43740a

Browse files
committed
Re-arrange members in SwiftPMBuildSystem by groups
1 parent 219b11d commit e43740a

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,57 +110,38 @@ package struct SwiftPMTestHooks: Sendable {
110110
/// Package Manager (SwiftPM) package. The settings are determined by loading the Package.swift
111111
/// manifest using `libSwiftPM` and constructing a build plan using the default (debug) parameters.
112112
package actor SwiftPMBuildSystem {
113-
114113
package enum Error: Swift.Error {
115-
116114
/// Could not find a manifest (Package.swift file). This is not a package.
117115
case noManifest(workspacePath: TSCAbsolutePath)
118116

119117
/// Could not determine an appropriate toolchain for swiftpm to use for manifest loading.
120118
case cannotDetermineHostToolchain
121119
}
122120

121+
// MARK: Integration with SourceKit-LSP
122+
123+
/// Options that allow the user to pass extra compiler flags.
124+
private let options: SourceKitLSPOptions
125+
126+
private let testHooks: SwiftPMTestHooks
127+
123128
/// Delegate to handle any build system events.
124129
package weak var delegate: BuildSystemIntegration.BuildSystemDelegate? = nil
125130

126131
package func setDelegate(_ delegate: BuildSystemIntegration.BuildSystemDelegate?) async {
127132
self.delegate = delegate
128133
}
129134

135+
/// This callback is informed when `reloadPackage` starts and ends executing.
136+
private var reloadPackageStatusCallback: (ReloadPackageStatus) async -> Void
137+
130138
/// Callbacks that should be called if the list of possible test files has changed.
131139
private var testFilesDidChangeCallbacks: [() async -> Void] = []
132140

133-
private let workspacePath: TSCAbsolutePath
134-
135-
/// Options that allow the user to pass extra compiler flags.
136-
private let options: SourceKitLSPOptions
137-
138-
/// The directory containing `Package.swift`.
139-
package var projectRoot: TSCAbsolutePath
140-
141-
private var buildDescription: SourceKitLSPAPI.BuildDescription?
142-
private var modulesGraph: ModulesGraph
143-
private let workspace: Workspace
144-
package let toolsBuildParameters: BuildParameters
145-
package let destinationBuildParameters: BuildParameters
146-
private let fileSystem: FileSystem
147-
private let toolchain: Toolchain
148-
149-
private var fileToTargets: [DocumentURI: [SwiftBuildTarget]] = [:]
150-
private var sourceDirToTargets: [DocumentURI: [SwiftBuildTarget]] = [:]
151-
152-
/// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
153-
///
154-
/// Targets with lower index are more low level, ie. targets with higher indices depend on targets with lower indices.
155-
private var targets: [ConfiguredTarget: (index: Int, buildTarget: SwiftBuildTarget)] = [:]
156-
157141
/// The URIs for which the delegate has registered for change notifications,
158142
/// mapped to the language the delegate specified when registering for change notifications.
159143
private var watchedFiles: Set<DocumentURI> = []
160144

161-
/// This callback is informed when `reloadPackage` starts and ends executing.
162-
private var reloadPackageStatusCallback: (ReloadPackageStatus) async -> Void
163-
164145
/// Debounces calls to `delegate.filesDependenciesUpdated`.
165146
///
166147
/// This is to ensure we don't call `filesDependenciesUpdated` for the same file multiple time if the client does not
@@ -171,16 +152,45 @@ package actor SwiftPMBuildSystem {
171152
/// Force-unwrapped optional because initializing it requires access to `self`.
172153
private var fileDependenciesUpdatedDebouncer: Debouncer<Set<DocumentURI>>! = nil
173154

155+
/// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
156+
/// user's build.
157+
private var isForIndexBuild: Bool { options.backgroundIndexingOrDefault }
158+
159+
// MARK: Build system options (set once and not modified)
160+
161+
/// The path at which the LSP workspace is opened. This might be a subdirectory of the path that contains the
162+
/// `Package.swift`.
163+
private let workspacePath: TSCAbsolutePath
164+
165+
/// The directory containing `Package.swift`.
166+
package let projectRoot: TSCAbsolutePath
167+
168+
package let toolsBuildParameters: BuildParameters
169+
package let destinationBuildParameters: BuildParameters
170+
171+
private let fileSystem: FileSystem
172+
private let toolchain: Toolchain
173+
private let workspace: Workspace
174+
174175
/// A `ObservabilitySystem` from `SwiftPM` that logs.
175176
private let observabilitySystem = ObservabilitySystem({ scope, diagnostic in
176177
logger.log(level: diagnostic.severity.asLogLevel, "SwiftPM log: \(diagnostic.description)")
177178
})
178179

179-
/// Whether the `SwiftPMBuildSystem` is pointed at a `.index-build` directory that's independent of the
180-
/// user's build.
181-
private var isForIndexBuild: Bool { options.backgroundIndexingOrDefault }
180+
// MARK: Build system state (modified on package reload)
182181

183-
private let testHooks: SwiftPMTestHooks
182+
/// The entry point via with we can access the `SourceKitLSPAPI` provided by SwiftPM.
183+
private var buildDescription: SourceKitLSPAPI.BuildDescription?
184+
185+
private var modulesGraph: ModulesGraph
186+
187+
private var fileToTargets: [DocumentURI: [SwiftBuildTarget]] = [:]
188+
private var sourceDirToTargets: [DocumentURI: [SwiftBuildTarget]] = [:]
189+
190+
/// Maps configured targets ids to their SwiftPM build target as well as an index in their topological sorting.
191+
///
192+
/// Targets with lower index are more low level, ie. targets with higher indices depend on targets with lower indices.
193+
private var targets: [ConfiguredTarget: (index: Int, buildTarget: SwiftBuildTarget)] = [:]
184194

185195
/// Creates a build system using the Swift Package Manager, if this workspace is a package.
186196
///

Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -408,23 +408,13 @@ final class SwiftPMBuildSystemTests: XCTestCase {
408408
.compilerArguments
409409
assertArgumentsContain(aswift.pathString, arguments: arguments)
410410
assertArgumentsDoNotContain(bswift.pathString, arguments: arguments)
411-
// Temporary conditional to work around revlock between SourceKit-LSP and SwiftPM
412-
// as a result of fix for SR-12050. Can be removed when that fix has been merged.
413-
if arguments.joined(separator: " ").contains("-Xcc -I -Xcc") {
414-
assertArgumentsContain(
415-
"-Xcc",
416-
"-I",
417-
"-Xcc",
418-
packageRoot.appending(components: "Sources", "libC", "include").pathString,
419-
arguments: arguments
420-
)
421-
} else {
422-
assertArgumentsContain(
423-
"-I",
424-
packageRoot.appending(components: "Sources", "libC", "include").pathString,
425-
arguments: arguments
426-
)
427-
}
411+
assertArgumentsContain(
412+
"-Xcc",
413+
"-I",
414+
"-Xcc",
415+
packageRoot.appending(components: "Sources", "libC", "include").pathString,
416+
arguments: arguments
417+
)
428418

429419
let argumentsB = try await unwrap(swiftpmBuildSystem.buildSettings(for: bswift.asURI, language: .swift))
430420
.compilerArguments

0 commit comments

Comments
 (0)