From 425102ea93d25fc0a6552b95a6e763f9dd892d23 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 22 Jan 2025 13:14:37 -0800 Subject: [PATCH] When the SourceKit plugins fail to load during testing, include the search base in the error --- Sources/SKTestSupport/PluginPaths.swift | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Sources/SKTestSupport/PluginPaths.swift b/Sources/SKTestSupport/PluginPaths.swift index 4ef47d3e3..aa80a409e 100644 --- a/Sources/SKTestSupport/PluginPaths.swift +++ b/Sources/SKTestSupport/PluginPaths.swift @@ -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. + + 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) } }