Skip to content

Commit 9512ae1

Browse files
authored
Merge pull request #1955 from ahoppen/plugin-from-toolchain
Allow loading the SourceKit plugin from the toolchain during testing
2 parents 055d931 + 8787787 commit 9512ae1

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Documentation/Environment Variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ The following environment variables can be used to control some behavior in Sour
1818
- `SOURCEKIT_LSP_KEEP_TEST_SCRATCH_DIR`: Does not delete the temporary files created during test execution. Allows inspection of the test projects after the test finishes.
1919
- `SOURCEKIT_LSP_TEST_MODULE_CACHE`: Specifies where tests should store their shared module cache. Defaults to writing the module cache to a temporary directory. Intended so that CI systems can clean the module cache directory after running.
2020
- `SOURCEKIT_LSP_TEST_TIMEOUT`: Override the timeout duration for tests, in seconds.
21-
- `SOURCEKIT_LSP_TEST_PLUGIN_PATHS`: Load the SourceKit plugins from this path instead of relative to the package's build folder.
21+
- `SOURCEKIT_LSP_TEST_PLUGIN_PATHS`: Load the SourceKit plugins from this path instead of relative to the package's build folder. If set to `RELATIVE_TO_SOURCEKITD`, the SourceKit plugin is found from the toolchain, relative to sourcekitd.

Sources/SKTestSupport/PluginPaths.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private func pluginPaths(relativeTo base: URL) -> PluginPaths? {
109109

110110
/// Returns the paths from which the SourceKit plugins should be loaded or throws an error if the plugins cannot be
111111
/// found.
112-
package var sourceKitPluginPaths: PluginPaths {
112+
package var sourceKitPluginPaths: PluginPaths? {
113113
get throws {
114114
struct PluginLoadingError: Error, CustomStringConvertible {
115115
let searchBase: URL
@@ -126,12 +126,16 @@ package var sourceKitPluginPaths: PluginPaths {
126126
}
127127
}
128128

129-
let base =
130-
if let pluginPaths = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_TEST_PLUGIN_PATHS"] {
131-
URL(fileURLWithPath: pluginPaths)
129+
var base: URL
130+
if let pluginPaths = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_TEST_PLUGIN_PATHS"] {
131+
if pluginPaths == "RELATIVE_TO_SOURCEKITD" {
132+
return nil
132133
} else {
133-
xctestBundle
134+
base = URL(fileURLWithPath: pluginPaths)
134135
}
136+
} else {
137+
base = xctestBundle
138+
}
135139
var searchPath = base
136140
while searchPath.pathComponents.count > 1 {
137141
if let paths = pluginPaths(relativeTo: searchPath) {

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ extension SourceKitLSPOptions {
3939
) -> SourceKitLSPOptions {
4040
return SourceKitLSPOptions(
4141
sourcekitd: SourceKitDOptions(
42-
clientPlugin: try! sourceKitPluginPaths.clientPlugin.filePath,
43-
servicePlugin: try! sourceKitPluginPaths.servicePlugin.filePath
42+
clientPlugin: try! sourceKitPluginPaths?.clientPlugin.filePath,
43+
servicePlugin: try! sourceKitPluginPaths?.servicePlugin.filePath
4444
),
4545
backgroundIndexing: backgroundIndexing,
4646
experimentalFeatures: experimentalFeatures,

0 commit comments

Comments
 (0)