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

[SKCore] If 'Platform.currentPlatform' is nil use 'so' as library extension #13

Merged
merged 2 commits into from Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/SKCore/Toolchain.swift
Expand Up @@ -86,7 +86,8 @@ public final class Toolchain {
foundAny = true
}

let dylibExt = Platform.currentPlatform?.dynamicLibraryExtension ?? "dylib"
// If 'currentPlatform' is nil it's most likely an unknown linux flavor.
let dylibExt = Platform.currentPlatform?.dynamicLibraryExtension ?? "so"

let sourcekitdPath = libPath.appending(components: "sourcekitd.framework", "sourcekitd")
if fs.isFile(sourcekitdPath) {
Expand Down
26 changes: 25 additions & 1 deletion Tests/SKCoreTests/ToolchainRegistryTests.swift
Expand Up @@ -47,6 +47,29 @@ final class ToolchainRegistryTests: XCTestCase {
XCTAssertEqual(tr.default?.identifier, ToolchainRegistry.darwinDefaultToolchainID)
}

func testUnknownPlatform() {
let prevPlatform = Platform.currentPlatform
defer { Platform.currentPlatform = prevPlatform }
Platform.currentPlatform = nil

let fs = InMemoryFileSystem()

let makeToolchain = { (binPath: AbsolutePath) in
let libPath = binPath.parentDirectory.appending(component: "lib")
try! fs.createDirectory(libPath, recursive: true)
try! fs.writeFileContents(libPath.appending(components: "libsourcekitdInProc.so") , bytes: "")
}

let binPath = AbsolutePath("/foo/bar/my_toolchain/bin")
makeToolchain(binPath)

guard let t = Toolchain(identifier: "a", displayName: "b", searchForTools: binPath, fileSystem: fs) else {
XCTFail("could not find any tools")
return
}
XCTAssertNotNil(t.sourcekitd)
}

func testSearchDarwin() {
// FIXME: requires PropertyListEncoder
#if os(macOS)
Expand Down Expand Up @@ -228,7 +251,7 @@ final class ToolchainRegistryTests: XCTestCase {
func testDylibNames() {
let fs = InMemoryFileSystem()

let ext = Platform.currentPlatform?.dynamicLibraryExtension ?? "dylib"
let ext = Platform.currentPlatform?.dynamicLibraryExtension ?? "so"

let makeToolchain = { (binPath: AbsolutePath) in
let libPath = binPath.parentDirectory.appending(component: "lib")
Expand Down Expand Up @@ -275,6 +298,7 @@ final class ToolchainRegistryTests: XCTestCase {
static var allTests = [
("testDefaultBasic", testDefaultBasic),
("testDefaultDarwin", testDefaultDarwin),
("testUnknownPlatform", testUnknownPlatform),
("testSearchDarwin", testSearchDarwin),
("testSearchPATH", testSearchPATH),
("testFromDirectory", testFromDirectory),
Expand Down