Skip to content
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

When the SourceKit plugins fail to load during testing, include the search base in the error #1946

Merged
merged 1 commit into from
Jan 25, 2025
Merged
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
25 changes: 18 additions & 7 deletions Sources/SKTestSupport/PluginPaths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,34 @@ private func pluginPaths(relativeTo base: URL) -> PluginPaths? {
package var sourceKitPluginPaths: PluginPaths {
get throws {
struct PluginLoadingError: Error, CustomStringConvertible {
var description: String =
"Could not find SourceKit plugin. Ensure that you build the entire SourceKit-LSP package before running tests."
let searchBase: URL
var description: String {
// We can't declare a dependency from the test *target* on the SourceKit plugin *product*
// (https://github.com/swiftlang/swift-package-manager/issues/8245).
// We thus require a build before running the tests to ensure the plugin dylibs are in the build products
// folder.
"""
Could not find SourceKit plugin. Ensure that you build the entire SourceKit-LSP package before running tests.
bnbarham marked this conversation as resolved.
Show resolved Hide resolved

Searching for plugin relative to \(searchBase)
"""
}
}

var base =
let base =
if let pluginPaths = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_TEST_PLUGIN_PATHS"] {
URL(fileURLWithPath: pluginPaths)
} else {
xctestBundle
}
while base.pathComponents.count > 1 {
if let paths = pluginPaths(relativeTo: base) {
var searchPath = base
while searchPath.pathComponents.count > 1 {
if let paths = pluginPaths(relativeTo: searchPath) {
return paths
}
base = base.deletingLastPathComponent()
searchPath = searchPath.deletingLastPathComponent()
}

throw PluginLoadingError()
throw PluginLoadingError(searchBase: base)
}
}