Skip to content

Commit 3555675

Browse files
authored
Merge pull request #2254 from ahoppen/remove-pound-if
2 parents 35c0fd3 + 509ac6f commit 3555675

File tree

6 files changed

+81
-67
lines changed

6 files changed

+81
-67
lines changed

Sources/BuildServerIntegration/BuildServerManager.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,36 +1349,36 @@ package actor BuildServerManager: QueueBasedMessageHandler {
13491349
return [uri]
13501350
}
13511351
let mainFiles = Array(await mainFilesProvider.mainFiles(containing: uri, crossLanguage: false))
1352-
#if canImport(Darwin)
1353-
if let buildableSourceFiles = try? await self.buildableSourceFiles() {
1354-
return mainFiles.map { mainFile in
1355-
if mainFile == uri {
1356-
// Do not apply the standardized file normalization to the source file itself. Otherwise we would get the
1357-
// following behavior:
1358-
// - We have a build server that uses standardized file paths and index a file as /tmp/test.c
1359-
// - We are asking for the main files of /private/tmp/test.c
1360-
// - Since indexstore-db uses realpath for everything, we find the unit for /tmp/test.c as a unit containg
1361-
// /private/tmp/test.c, which has /private/tmp/test.c as the main file.
1362-
// - If we applied the path normalization, we would normalize /private/tmp/test.c to /tmp/test.c, thus
1363-
// reporting that /tmp/test.c is a main file containing /private/tmp/test.c,
1364-
// But that doesn't make sense (it would, in fact cause us to treat /private/tmp/test.c as a header file that
1365-
// we should index using /tmp/test.c as a main file.
1366-
return mainFile
1367-
}
1368-
if buildableSourceFiles.contains(mainFile) {
1369-
return mainFile
1370-
}
1371-
guard let fileURL = mainFile.fileURL else {
1352+
if Platform.current == .darwin {
1353+
if let buildableSourceFiles = try? await self.buildableSourceFiles() {
1354+
return mainFiles.map { mainFile in
1355+
if mainFile == uri {
1356+
// Do not apply the standardized file normalization to the source file itself. Otherwise we would get the
1357+
// following behavior:
1358+
// - We have a build server that uses standardized file paths and index a file as /tmp/test.c
1359+
// - We are asking for the main files of /private/tmp/test.c
1360+
// - Since indexstore-db uses realpath for everything, we find the unit for /tmp/test.c as a unit containg
1361+
// /private/tmp/test.c, which has /private/tmp/test.c as the main file.
1362+
// - If we applied the path normalization, we would normalize /private/tmp/test.c to /tmp/test.c, thus
1363+
// reporting that /tmp/test.c is a main file containing /private/tmp/test.c,
1364+
// But that doesn't make sense (it would, in fact cause us to treat /private/tmp/test.c as a header file that
1365+
// we should index using /tmp/test.c as a main file.
1366+
return mainFile
1367+
}
1368+
if buildableSourceFiles.contains(mainFile) {
1369+
return mainFile
1370+
}
1371+
guard let fileURL = mainFile.fileURL else {
1372+
return mainFile
1373+
}
1374+
let standardized = DocumentURI(fileURL.standardizedFileURL)
1375+
if buildableSourceFiles.contains(standardized) {
1376+
return standardized
1377+
}
13721378
return mainFile
13731379
}
1374-
let standardized = DocumentURI(fileURL.standardizedFileURL)
1375-
if buildableSourceFiles.contains(standardized) {
1376-
return standardized
1377-
}
1378-
return mainFile
13791380
}
13801381
}
1381-
#endif
13821382
return mainFiles
13831383
}
13841384

Sources/SKTestSupport/PluginPaths.swift

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,31 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14+
import SKLogging
1415
package import SourceKitD
16+
import SwiftExtensions
1517
import ToolchainRegistry
1618

1719
// Anchor class to lookup the testing bundle when swiftpm-testing-helper is used.
1820
private final class TestingAnchor {}
1921

2022
/// The path to the `SwiftSourceKitPluginTests` test bundle. This gives us a hook into the the build directory.
2123
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+
)
2938
}
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
3739
}()
3840

3941
/// When running tests from Xcode, determine the build configuration of the package.
@@ -90,16 +92,23 @@ private func pluginPaths(relativeTo base: URL) -> PluginPaths? {
9092

9193
// When building using 'swift test'
9294
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+
}
103112
let clientPlugin = base.appendingPathComponent(clientPluginName)
104113
let servicePlugin = base.appendingPathComponent(servicePluginName)
105114
if fileExists(at: clientPlugin) && fileExists(at: servicePlugin) {

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ package actor SkipUnless {
393393
file: StaticString = #filePath,
394394
line: UInt = #line
395395
) async throws {
396-
return try await shared.skipUnlessSupported(file: file, line: line) {
396+
// docc is supported on macOS and Linux. Do not perform a check on those platforms to avoid accidentally skipping
397+
// the tests in CI on those platforms.
398+
#if os(Windows)
399+
return try await shared.skipUnlessSupported(allowSkippingInCI: true, file: file, line: line) {
397400
let server = try await SourceKitLSPServer(
398401
client: LocalConnection(receiverName: "client"),
399402
toolchainRegistry: .forTesting,
@@ -421,6 +424,7 @@ package actor SkipUnless {
421424
}
422425
return .featureSupported
423426
}
427+
#endif
424428
}
425429
}
426430

Sources/SwiftExtensions/URLExtensions.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ extension URL {
4040
guard let realpath = Darwin.realpath(path, nil) else {
4141
return self
4242
}
43-
let result = URL(fileURLWithPath: String(cString: realpath))
44-
free(realpath)
45-
return result
43+
defer {
44+
free(realpath)
45+
}
46+
return URL(fileURLWithPath: String(cString: realpath))
4647
}
4748
#else
4849
// Non-Darwin platforms don't have the `/private` stripping issue, so we can just use `self.resolvingSymlinksInPath`

Sources/sourcekit-lsp/SourceKitLSP.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,19 @@ struct SourceKitLSP: AsyncParsableCommand {
184184
.appendingPathComponent("config.json")
185185
)
186186
)
187-
#if canImport(Darwin)
188-
for applicationSupportDir in FileManager.default.urls(for: .applicationSupportDirectory, in: [.allDomainsMask]) {
189-
options = SourceKitLSPOptions.merging(
190-
base: options,
191-
override: SourceKitLSPOptions(
192-
path:
193-
applicationSupportDir
194-
.appendingPathComponent("org.swift.sourcekit-lsp")
195-
.appendingPathComponent("config.json")
187+
if Platform.current == .darwin {
188+
for applicationSupportDir in FileManager.default.urls(for: .applicationSupportDirectory, in: [.allDomainsMask]) {
189+
options = SourceKitLSPOptions.merging(
190+
base: options,
191+
override: SourceKitLSPOptions(
192+
path:
193+
applicationSupportDir
194+
.appendingPathComponent("org.swift.sourcekit-lsp")
195+
.appendingPathComponent("config.json")
196+
)
196197
)
197-
)
198+
}
198199
}
199-
#endif
200200
if let xdgConfigHome = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"] {
201201
options = SourceKitLSPOptions.merging(
202202
base: options,

Tests/SourceKitLSPTests/DocumentationLanguageServiceTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if canImport(DocCDocumentation)
1413
import LanguageServerProtocol
1514
import SKTestSupport
1615
import SourceKitLSP
1716
import XCTest
1817

1918
final class DocumentationLanguageServiceTests: XCTestCase {
2019
func testHandlesMarkdownFiles() async throws {
20+
try await SkipUnless.doccSupported()
2121
try await assertHandles(language: .markdown)
2222
}
2323

2424
func testHandlesTutorialFiles() async throws {
25+
try await SkipUnless.doccSupported()
2526
try await assertHandles(language: .tutorial)
2627
}
2728
}
@@ -40,4 +41,3 @@ private func assertHandles(language: Language) async throws {
4041
)
4142
XCTAssertEqual(completions, .init(isIncomplete: false, items: []))
4243
}
43-
#endif

0 commit comments

Comments
 (0)