Skip to content

Commit 90fd3ad

Browse files
authored
adjust to latest SwiftPM APIs (#741)
motivation: support changes in SwiftPM underlying path APIs changes: * adjust call sites in SwiftPMWorkspace to use SwiftPM's path
1 parent 0946a78 commit 90fd3ad

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Sources/SKCore/XCToolchainPlist.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ extension XCToolchainPlist {
4949
init(fromDirectory path: AbsolutePath, _ fileSystem: FileSystem = localFileSystem) throws {
5050
#if os(macOS)
5151
let plistNames = [
52-
RelativePath("ToolchainInfo.plist"), // Xcode
53-
RelativePath("Info.plist"), // Swift.org
52+
try RelativePath(validating: "ToolchainInfo.plist"), // Xcode
53+
try RelativePath(validating: "Info.plist"), // Swift.org
5454
]
5555

5656
var missingPlistPath: AbsolutePath?

Sources/SKSupport/FileSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension AbsolutePath {
2424
/// Inititializes an absolute path from a string, expanding a leading `~` to `homeDirectoryForCurrentUser` first.
2525
public init(expandingTilde path: String) throws {
2626
if path.first == "~" {
27-
try self.init(homeDirectoryForCurrentUser, String(path.dropFirst(2)))
27+
try self.init(homeDirectoryForCurrentUser, validating: String(path.dropFirst(2)))
2828
} else {
2929
try self.init(validating: path)
3030
}

Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ import Workspace
2828
import Dispatch
2929
import struct Foundation.URL
3030

31+
import struct Basics.AbsolutePath
32+
import struct Basics.TSCAbsolutePath
33+
3134
import func TSCBasic.resolveSymlinks
3235
import protocol TSCBasic.FileSystem
33-
import struct TSCBasic.AbsolutePath
3436
import var TSCBasic.localFileSystem
3537

3638
/// Swift Package Manager build system and workspace support.
@@ -43,7 +45,7 @@ public final class SwiftPMWorkspace {
4345
public enum Error: Swift.Error {
4446

4547
/// Could not find a manifest (Package.swift file). This is not a package.
46-
case noManifest(workspacePath: AbsolutePath)
48+
case noManifest(workspacePath: TSCAbsolutePath)
4749

4850
/// Could not determine an appropriate toolchain for swiftpm to use for manifest loading.
4951
case cannotDetermineHostToolchain
@@ -52,10 +54,10 @@ public final class SwiftPMWorkspace {
5254
/// Delegate to handle any build system events.
5355
public weak var delegate: SKCore.BuildSystemDelegate? = nil
5456

55-
let workspacePath: AbsolutePath
56-
let packageRoot: AbsolutePath
57+
let workspacePath: TSCAbsolutePath
58+
let packageRoot: TSCAbsolutePath
5759
/// *Public for testing*
58-
public var _packageRoot: AbsolutePath { packageRoot }
60+
public var _packageRoot: TSCAbsolutePath { packageRoot }
5961
var packageGraph: PackageGraph
6062
let workspace: Workspace
6163
public let buildParameters: BuildParameters
@@ -84,7 +86,7 @@ public final class SwiftPMWorkspace {
8486
/// manifest parsing and runtime support.
8587
/// - Throws: If there is an error loading the package, or no manifest is found.
8688
public init(
87-
workspacePath: AbsolutePath,
89+
workspacePath: TSCAbsolutePath,
8890
toolchainRegistry: ToolchainRegistry,
8991
fileSystem: FileSystem = localFileSystem,
9092
buildSetup: BuildSetup) throws
@@ -102,12 +104,15 @@ public final class SwiftPMWorkspace {
102104
throw Error.cannotDetermineHostToolchain
103105
}
104106

105-
let destination = try Destination.hostDestination(destinationToolchainBinDir)
107+
let destination = try Destination.hostDestination(AbsolutePath(destinationToolchainBinDir))
106108
let toolchain = try UserToolchain(destination: destination)
107109

108-
var location = try Workspace.Location(forRootPackage: packageRoot, fileSystem: fileSystem)
110+
var location = try Workspace.Location(
111+
forRootPackage: AbsolutePath(packageRoot),
112+
fileSystem: fileSystem
113+
)
109114
if let scratchDirectory = buildSetup.path {
110-
location.scratchDirectory = scratchDirectory
115+
location.scratchDirectory = AbsolutePath(scratchDirectory)
111116
}
112117

113118
var configuration = WorkspaceConfiguration.default
@@ -150,7 +155,7 @@ public final class SwiftPMWorkspace {
150155
{
151156
do {
152157
try self.init(
153-
workspacePath: try AbsolutePath(validating: url.path),
158+
workspacePath: try TSCAbsolutePath(validating: url.path),
154159
toolchainRegistry: toolchainRegistry,
155160
fileSystem: localFileSystem,
156161
buildSetup: buildSetup)
@@ -176,7 +181,7 @@ extension SwiftPMWorkspace {
176181
})
177182

178183
let packageGraph = try self.workspace.loadPackageGraph(
179-
rootInput: PackageGraphRootInput(packages: [packageRoot]),
184+
rootInput: PackageGraphRootInput(packages: [AbsolutePath(packageRoot)]),
180185
observabilityScope: observabilitySystem.topScope
181186
)
182187

@@ -234,15 +239,15 @@ extension SwiftPMWorkspace {
234239

235240
extension SwiftPMWorkspace: SKCore.BuildSystem {
236241

237-
public var buildPath: AbsolutePath {
238-
return buildParameters.buildPath
242+
public var buildPath: TSCAbsolutePath {
243+
return TSCAbsolutePath(buildParameters.buildPath)
239244
}
240245

241-
public var indexStorePath: AbsolutePath? {
242-
return buildParameters.indexStoreMode == .off ? nil : buildParameters.indexStore
246+
public var indexStorePath: TSCAbsolutePath? {
247+
return buildParameters.indexStoreMode == .off ? nil : TSCAbsolutePath(buildParameters.indexStore)
243248
}
244249

245-
public var indexDatabasePath: AbsolutePath? {
250+
public var indexDatabasePath: TSCAbsolutePath? {
246251
return buildPath.appending(components: "index", "db")
247252
}
248253

@@ -555,8 +560,8 @@ extension SwiftPMWorkspace {
555560

556561
/// Find a Swift Package root directory that contains the given path, if any.
557562
private func findPackageDirectory(
558-
containing path: AbsolutePath,
559-
_ fileSystem: FileSystem) -> AbsolutePath? {
563+
containing path: TSCAbsolutePath,
564+
_ fileSystem: FileSystem) -> TSCAbsolutePath? {
560565
var path = path
561566
while true {
562567
let packagePath = path.appending(component: "Package.swift")

Sources/sourcekit-lsp/SourceKitLSP.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension AbsolutePath: ExpressibleByArgument {
2828
public init?(argument: String) {
2929
let path: AbsolutePath?
3030

31-
if let cwd = localFileSystem.currentWorkingDirectory {
31+
if let cwd: AbsolutePath = localFileSystem.currentWorkingDirectory {
3232
path = try? AbsolutePath(validating: argument, relativeTo: cwd)
3333
} else {
3434
path = try? AbsolutePath(validating: argument)

0 commit comments

Comments
 (0)