-
Notifications
You must be signed in to change notification settings - Fork 326
Standardize file paths when attempting to find toolchains #2289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,13 @@ package final actor ToolchainRegistry { | |
var toolchainsByPath: [URL: Toolchain] = [:] | ||
var toolchainsByCompiler: [URL: Toolchain] = [:] | ||
for (toolchain, reason) in toolchainsAndReasonsParam { | ||
// Toolchain should always be unique by path. It isn't particularly useful to log if we already have a toolchain | ||
// though, as we could have just found toolchains through symlinks (this is actually quite normal - eg. OSS | ||
// toolchains add a `swift-latest.xctoolchain` symlink on macOS). | ||
if toolchainsByPath[toolchain.path] != nil { | ||
continue | ||
} | ||
|
||
// Non-XcodeDefault toolchain: disallow all duplicates. | ||
if toolchainsByIdentifier[toolchain.identifier] != nil, | ||
toolchain.identifier != ToolchainRegistry.darwinDefaultToolchainIdentifier | ||
|
@@ -104,12 +111,6 @@ package final actor ToolchainRegistry { | |
continue | ||
} | ||
|
||
// Toolchain should always be unique by path. | ||
if toolchainsByPath[toolchain.path] != nil { | ||
logger.fault("Found two toolchains with the same path: \(toolchain.path)") | ||
continue | ||
} | ||
|
||
toolchainsByPath[toolchain.path] = toolchain | ||
toolchainsByIdentifier[toolchain.identifier, default: []].append(toolchain) | ||
|
||
|
@@ -219,7 +220,9 @@ package final actor ToolchainRegistry { | |
} | ||
|
||
let toolchainsAndReasons = toolchainPaths.compactMap { | ||
if let toolchain = Toolchain($0.path) { | ||
if let resolvedPath = try? $0.path.realpath, | ||
bnbarham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let toolchain = Toolchain(resolvedPath) | ||
{ | ||
return (toolchain, $0.reason) | ||
} | ||
return nil | ||
|
@@ -283,7 +286,18 @@ package final actor ToolchainRegistry { | |
/// If we have a toolchain in the toolchain registry that contains the compiler with the given URL, return it. | ||
/// Otherwise, return `nil`. | ||
package func toolchain(withCompiler compiler: URL) -> Toolchain? { | ||
return toolchainsByCompiler[compiler] | ||
if let resolvedPath = try? compiler.realpath { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that we need to run |
||
return toolchainsByCompiler[resolvedPath] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. I didn't do this since we already realpathed the toolchain path coming into ToolchainRegistry, but forgot about the case the binaries themselves could be. We could just realpath the parent folder here? EDIT: Hmmm, but we don't know the "toolchain" path in order to do that. I don't love the idea of realpathing to swift-driver though. |
||
} | ||
return nil | ||
} | ||
|
||
/// If we have a toolchain in the toolchain registry with the given URL, return it. Otherwise, return `nil`. | ||
package func toolchain(withPath path: URL) -> Toolchain? { | ||
if let resolvedPath = try? path.realpath { | ||
return toolchainsByPath[resolvedPath] | ||
} | ||
return nil | ||
Comment on lines
+297
to
+300
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to my comment on if let toolchain = toolchainsByPath[path] {
return toolchain
}
guard let realpath = orLog("Realpath toolchain", { try path.realpath }) else {
return nil
}
guard let toolchain = lchainsByPath[realpath] else {
return nil
}
// Cache mapping of non-realpath to the realpath toolchain for faster subsequent lookups
toolchainsByPath[path] = toolchain
return toolchain |
||
} | ||
} | ||
|
||
|
@@ -292,10 +306,6 @@ extension ToolchainRegistry { | |
package func toolchains(withIdentifier identifier: String) -> [Toolchain] { | ||
return toolchainsByIdentifier[identifier] ?? [] | ||
} | ||
|
||
package func toolchain(withPath path: URL) -> Toolchain? { | ||
return toolchainsByPath[path] | ||
} | ||
} | ||
|
||
extension ToolchainRegistry { | ||
|
Uh oh!
There was an error while loading. Please reload this page.