Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Sources/SwiftExtensions/URLExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

package import Foundation

#if os(Windows)
import WinSDK
#endif

enum FilePathError: Error, CustomStringConvertible {
case noFileSystemRepresentation(URL)
case noFileURL(URL)
Expand Down Expand Up @@ -83,14 +87,14 @@ extension URL {
}

package var isRoot: Bool {
#if os(Windows)
// FIXME: We should call into Windows' native check to check if this path is a root once https://github.com/swiftlang/swift-foundation/issues/976 is fixed.
return self.pathComponents.count <= 1
#else
// On Linux, we may end up with an string for the path due to https://github.com/swiftlang/swift-foundation/issues/980
// TODO: Remove the check for "" once https://github.com/swiftlang/swift-foundation/issues/980 is fixed.
return self.path == "/" || self.path == ""
#endif
get throws {
let checkPath = try filePath
#if os(Windows)
return checkPath.withCString(encodedAs: UTF16.self, PathCchIsRoot)
#else
return checkPath == "/"
#endif
}
}

/// Returns true if the path of `self` starts with the path in `other`.
Expand Down
4 changes: 2 additions & 2 deletions Sources/ToolchainRegistry/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ public final class Toolchain: Sendable {
func containingXCToolchain(
_ path: URL
) -> (XCToolchainPlist, URL)? {
var path = path
while !path.isRoot {
var path = path.standardizedFileURL
while !((try? path.isRoot) ?? true) {
if path.pathExtension == "xctoolchain" {
if let infoPlist = orLog("Loading information from xctoolchain", { try XCToolchainPlist(fromDirectory: path) }) {
return (infoPlist, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ final class ToolchainRegistryTests: XCTestCase {

try ProcessEnv.setVar(
"SOURCEKIT_PATH_FOR_TEST",
value: ["/bogus", binPath.filePath, "/bogus2"].joined(separator: separator)
value: ["/bogus/../parent", "/bogus", binPath.filePath, "/bogus2"].joined(separator: separator)
)
defer { try! ProcessEnv.setVar("SOURCEKIT_PATH_FOR_TEST", value: "") }

Expand Down