Skip to content

Commit b89a232

Browse files
committed
Use realpath when setting SOURCEKIT_LSP_PLUGIN_SOURCEKITD_PATH_ environment variable
Otherwise we run into path mismatch issues when the test products are in a path that includes symlinks, such as `/tmp`.
1 parent fe5644b commit b89a232

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/SourceKitD/DynamicallyLoadedSourceKitD.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ package actor DynamicallyLoadedSourceKitD: SourceKitD {
126126
#endif
127127
if let pluginPaths {
128128
try setenv(
129-
name: "SOURCEKIT_LSP_PLUGIN_SOURCEKITD_PATH_\(pluginPaths.clientPlugin.filePath)",
129+
name: "SOURCEKIT_LSP_PLUGIN_SOURCEKITD_PATH_\(pluginPaths.clientPlugin.realpath.filePath)",
130130
value: dylibPath.filePath,
131131
override: false
132132
)

Sources/SwiftSourceKitClientPlugin/ClientPlugin.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public func sourcekitd_plugin_initialize(_ params: sourcekitd_api_plugin_initial
3333
var dlInfo = Dl_info()
3434
dladdr(#dsohandle, &dlInfo)
3535
let path = String(cString: dlInfo.dli_fname)
36-
var url = URL(fileURLWithPath: path, isDirectory: false)
36+
let clientPluginDylibUrl = URL(fileURLWithPath: path, isDirectory: false)
37+
var url = clientPluginDylibUrl
3738
while url.pathExtension != "framework" && url.lastPathComponent != "/" {
3839
url.deleteLastPathComponent()
3940
}
@@ -43,7 +44,10 @@ public func sourcekitd_plugin_initialize(_ params: sourcekitd_api_plugin_initial
4344
.appendingPathComponent("sourcekitd.framework")
4445
.appendingPathComponent("sourcekitd")
4546
if !FileManager.default.fileExists(at: url),
46-
let sourcekitdPath = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_PLUGIN_SOURCEKITD_PATH_\(path)"]
47+
let clientPluginDylibUrlRealpath = try? clientPluginDylibUrl.realpath.filePath,
48+
let sourcekitdPath = ProcessInfo.processInfo.environment[
49+
"SOURCEKIT_LSP_PLUGIN_SOURCEKITD_PATH_\(clientPluginDylibUrlRealpath)"
50+
]
4751
{
4852
// When using a SourceKit plugin from the build directory, we can't find sourcekitd relative to the plugin.
4953
// Respect the sourcekitd path that was passed to us via an environment variable from

0 commit comments

Comments
 (0)