From 93d94e532b78268480db32fdb5853c0d995a5ef5 Mon Sep 17 00:00:00 2001 From: Julia DeMille <8127111+judemille@users.noreply.github.com> Date: Sun, 4 Feb 2024 07:14:50 -0600 Subject: [PATCH] fix(linux): detect swift symlinked to bin dir. (#802) Signed-off-by: Julia DeMille --- CHANGELOG.md | 5 +++++ Source/SourceKittenFramework/library_wrapper.swift | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f1280d9..f184cf6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ ##### Bug Fixes +* Fix an issue where the path to the SourceKit library would not be properly + detected on Linux, when the swift executable was symlinked into a directory + in PATH from its actual install tree. + [Julia DeMille](https://github.com/judemille) + * Fix a crash when a file cannot be read as UTF-8. [Martin Redington](https://github.com/mildm8nnered) [#765](https://github.com/jpsim/SourceKitten/issues/765) diff --git a/Source/SourceKittenFramework/library_wrapper.swift b/Source/SourceKittenFramework/library_wrapper.swift index c8da323d..877be09f 100644 --- a/Source/SourceKittenFramework/library_wrapper.swift +++ b/Source/SourceKittenFramework/library_wrapper.swift @@ -69,6 +69,10 @@ private extension String { .reduce(URL(fileURLWithPath: self)) { url, _ in url.deletingLastPathComponent() } .path } + + func resolvingSymlinksInPath() -> String { + return URL(fileURLWithPath: self).resolvingSymlinksInPath().path + } } #if os(Linux) @@ -111,7 +115,7 @@ internal let linuxFindSwiftInstallationLibPath: String? = { } /// .../bin/swift -> .../lib - return swiftPath.deleting(lastPathComponents: 2).appending(pathComponent: "/lib") + return swiftPath.resolvingSymlinksInPath().deleting(lastPathComponents: 2).appending(pathComponent: "/lib") }() /// Fallback path on Linux if no better option is available.