Skip to content

Commit a082d41

Browse files
committed
Standardize file paths when attempting to find toolchains
`containingXCToolchain` loops infinitely when given eg. `C:\foo\..\bar`. The underlying cause is that `deletingLastPathComponent` does not remove the `..` on Windows. On macOS it's potentially worse - it *adds* `..`. We don't see the infinite loop on macOS/Linux though because `AbsolutePath` already removes them (which is not the case on Windows). Resolves #2174.
1 parent 016a0b1 commit a082d41

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Sources/ToolchainRegistry/Toolchain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public final class Toolchain: Sendable {
369369
func containingXCToolchain(
370370
_ path: URL
371371
) -> (XCToolchainPlist, URL)? {
372-
var path = path
372+
var path = path.standardizedFileURL
373373
while !((try? path.isRoot) ?? true) {
374374
if path.pathExtension == "xctoolchain" {
375375
if let infoPlist = orLog("Loading information from xctoolchain", { try XCToolchainPlist(fromDirectory: path) }) {

Tests/ToolchainRegistryTests/ToolchainRegistryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ final class ToolchainRegistryTests: XCTestCase {
336336

337337
try ProcessEnv.setVar(
338338
"SOURCEKIT_PATH_FOR_TEST",
339-
value: ["/bogus", binPath.filePath, "/bogus2"].joined(separator: separator)
339+
value: ["/bogus/../parent", "/bogus", binPath.filePath, "/bogus2"].joined(separator: separator)
340340
)
341341
defer { try! ProcessEnv.setVar("SOURCEKIT_PATH_FOR_TEST", value: "") }
342342

0 commit comments

Comments
 (0)