|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | import Foundation
|
| 14 | +import SKLogging |
14 | 15 | package import SourceKitD
|
| 16 | +import SwiftExtensions |
15 | 17 | import ToolchainRegistry
|
16 | 18 |
|
17 | 19 | // Anchor class to lookup the testing bundle when swiftpm-testing-helper is used.
|
18 | 20 | private final class TestingAnchor {}
|
19 | 21 |
|
20 | 22 | /// The path to the `SwiftSourceKitPluginTests` test bundle. This gives us a hook into the the build directory.
|
21 | 23 | private let xctestBundle: URL = {
|
22 |
| - #if canImport(Darwin) |
23 |
| - for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { |
24 |
| - return bundle.bundleURL |
25 |
| - } |
26 |
| - let bundle = Bundle(for: TestingAnchor.self) |
27 |
| - if bundle.bundlePath.hasSuffix(".xctest") { |
28 |
| - return bundle.bundleURL |
| 24 | + if Platform.current == .darwin { |
| 25 | + for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { |
| 26 | + return bundle.bundleURL |
| 27 | + } |
| 28 | + let bundle = Bundle(for: TestingAnchor.self) |
| 29 | + if bundle.bundlePath.hasSuffix(".xctest") { |
| 30 | + return bundle.bundleURL |
| 31 | + } |
| 32 | + preconditionFailure("Failed to find xctest bundle") |
| 33 | + } else { |
| 34 | + return URL( |
| 35 | + fileURLWithPath: CommandLine.arguments.first!, |
| 36 | + relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath) |
| 37 | + ) |
29 | 38 | }
|
30 |
| - preconditionFailure("Failed to find xctest bundle") |
31 |
| - #else |
32 |
| - return URL( |
33 |
| - fileURLWithPath: CommandLine.arguments.first!, |
34 |
| - relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath) |
35 |
| - ) |
36 |
| - #endif |
37 | 39 | }()
|
38 | 40 |
|
39 | 41 | /// When running tests from Xcode, determine the build configuration of the package.
|
@@ -90,16 +92,23 @@ private func pluginPaths(relativeTo base: URL) -> PluginPaths? {
|
90 | 92 |
|
91 | 93 | // When building using 'swift test'
|
92 | 94 | do {
|
93 |
| - #if canImport(Darwin) |
94 |
| - let clientPluginName = "libSwiftSourceKitClientPlugin.dylib" |
95 |
| - let servicePluginName = "libSwiftSourceKitPlugin.dylib" |
96 |
| - #elseif os(Windows) |
97 |
| - let clientPluginName = "SwiftSourceKitClientPlugin.dll" |
98 |
| - let servicePluginName = "SwiftSourceKitPlugin.dll" |
99 |
| - #else |
100 |
| - let clientPluginName = "libSwiftSourceKitClientPlugin.so" |
101 |
| - let servicePluginName = "libSwiftSourceKitPlugin.so" |
102 |
| - #endif |
| 95 | + let clientPluginName: String |
| 96 | + let servicePluginName: String |
| 97 | + switch Platform.current { |
| 98 | + case .darwin: |
| 99 | + clientPluginName = "libSwiftSourceKitClientPlugin.dylib" |
| 100 | + servicePluginName = "libSwiftSourceKitPlugin.dylib" |
| 101 | + case .windows: |
| 102 | + clientPluginName = "SwiftSourceKitClientPlugin.dll" |
| 103 | + servicePluginName = "SwiftSourceKitPlugin.dll" |
| 104 | + case .linux: |
| 105 | + clientPluginName = "libSwiftSourceKitClientPlugin.so" |
| 106 | + servicePluginName = "libSwiftSourceKitPlugin.so" |
| 107 | + case nil: |
| 108 | + logger.fault("Could not determine host OS. Falling back to using '.so' as dynamic library extension") |
| 109 | + clientPluginName = "libSwiftSourceKitClientPlugin.so" |
| 110 | + servicePluginName = "libSwiftSourceKitPlugin.so" |
| 111 | + } |
103 | 112 | let clientPlugin = base.appendingPathComponent(clientPluginName)
|
104 | 113 | let servicePlugin = base.appendingPathComponent(servicePluginName)
|
105 | 114 | if fileExists(at: clientPlugin) && fileExists(at: servicePlugin) {
|
|
0 commit comments