Skip to content

Commit 084286e

Browse files
authored
SourceKit: make SwiftLang build in linux. (#18455)
1 parent 701eb4f commit 084286e

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

test/SwiftSyntax/AbsolutePosition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func getInput(_ file: String) -> URL {
1717
}
1818

1919
func getSyntaxTree(_ url: URL) throws -> SourceFileSyntax {
20-
let content = try SwiftLang.parse(url).data(using: .utf8)!
20+
let content = try SwiftLang.parse(path: url.path).data(using: .utf8)!
2121
return try SyntaxTreeDeserializer().deserialize(content)
2222
}
2323

test/SwiftSyntax/DeserializeFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var DecodeTests = TestSuite("DecodeSyntax")
2020

2121
DecodeTests.test("Basic") {
2222
expectDoesNotThrow({
23-
let content = try SwiftLang.parse(getInput("visitor.swift"))
23+
let content = try SwiftLang.parse(path: getInput("visitor.swift").path)
2424
let contentData = content.data(using: .utf8)!
2525
let source = try String(contentsOf: getInput("visitor.swift"))
2626
let parsed = try SyntaxTreeDeserializer().deserialize(contentData)

test/SwiftSyntax/ParseFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ParseFile.test("ParseSingleFile") {
3131
let currentFile = URL(fileURLWithPath: #file)
3232
expectDoesNotThrow({
3333
let fileContents = try String(contentsOf: currentFile)
34-
let syntaxTreeData = try SwiftLang.parse(fileContents).data(using: .utf8)!
34+
let syntaxTreeData = try SwiftLang.parse(source: fileContents).data(using: .utf8)!
3535
let parsed = try SyntaxTreeDeserializer().deserialize(syntaxTreeData)
3636
expectEqual("\(parsed)", fileContents)
3737
})
@@ -40,7 +40,7 @@ ParseFile.test("ParseSingleFile") {
4040
ParseFile.test("ParseBuffer") {
4141
expectDoesNotThrow({
4242
let content = "func foo() {}"
43-
let syntaxTreeData = try SwiftLang.parse(content).data(using: .utf8)!
43+
let syntaxTreeData = try SwiftLang.parse(source: content).data(using: .utf8)!
4444
let parsed = try SyntaxTreeDeserializer().deserialize(syntaxTreeData)
4545
expectEqual("\(parsed)", content)
4646
})

test/SwiftSyntax/VisitorTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func getInput(_ file: String) -> URL {
1717
}
1818

1919
func getSyntaxTree(_ url: URL) throws -> SourceFileSyntax {
20-
let content = try SwiftLang.parse(url).data(using: .utf8)!
20+
let content = try SwiftLang.parse(path: url.path).data(using: .utf8)!
2121
return try SyntaxTreeDeserializer().deserialize(content)
2222
}
2323

tools/SourceKit/tools/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ if(HAVE_UNICODE_LIBEDIT)
1010
add_swift_tool_subdirectory(sourcekitd-repl)
1111
endif()
1212
add_swift_tool_subdirectory(complete-test)
13-
if(BUILD_FOUNDATION)
14-
add_subdirectory(swift-lang)
15-
endif()
13+
add_subdirectory(swift-lang)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module sourcekitd {
2+
umbrella header "sourcekitd.h"
3+
export *
4+
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
set(EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
2-
set(EXTRA_LINKER_FLAGS "-Xlinker" "-rpath" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}"
3-
"-Xlinker" "-F" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
1+
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
2+
set(EXTRA_COMPILE_FLAGS "-I" "${SOURCEKITD_SOURCE_DIR}/include/sourcekitd")
3+
set(SOURCEKITD_LINK_LIBS sourcekitdInProc)
4+
set(INSTALLED_COMP sourcekit-inproc)
5+
else()
6+
set(EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
7+
set(SOURCEKITD_LINK_LIBS sourcekitd)
8+
set(INSTALLED_COMP sourcekit-xpc-service)
9+
endif()
410

511
add_swift_library(swiftSwiftLang SHARED
612
SwiftLang.swift
@@ -11,10 +17,7 @@ add_swift_library(swiftSwiftLang SHARED
1117
UIDs.swift.gyb
1218

1319
DEPENDS sourcekitd-test
14-
PRIVATE_LINK_LIBRARIES sourcekitd
20+
PRIVATE_LINK_LIBRARIES ${SOURCEKITD_LINK_LIBS}
1521
SWIFT_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
16-
LINK_FLAGS ${EXTRA_LINKER_FLAGS}
17-
SWIFT_MODULE_DEPENDS Foundation
18-
INSTALL_IN_COMPONENT sourcekit-xpc-service
19-
TARGET_SDKS OSX
22+
INSTALL_IN_COMPONENT ${INSTALLED_COMP}
2023
IS_STDLIB)

tools/SourceKit/tools/swift-lang/SourceKitdClient.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import sourcekitd
16-
import Foundation
1716

1817
public class SourceKitdService {
1918

tools/SourceKit/tools/swift-lang/SourceKitdResponse.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// This file provides convenient APIs to interpret a SourceKitd response.
1313
//===----------------------------------------------------------------------===//
1414

15-
import Foundation
1615
import sourcekitd
1716

1817
public class SourceKitdResponse: CustomStringConvertible {
@@ -253,6 +252,6 @@ extension sourcekitd_variant_t: CustomStringConvertible {
253252
}
254253

255254
private func fromCStringLen(_ ptr: UnsafePointer<Int8>, length: Int) -> String? {
256-
return NSString(bytes: ptr, length: length,
257-
encoding: String.Encoding.utf8.rawValue) as String?
255+
return String(decoding: Array(UnsafeBufferPointer(start: ptr, count: length)).map {
256+
UInt8(bitPattern: $0) }, as: UTF8.self)
258257
}

tools/SourceKit/tools/swift-lang/SwiftLang.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// This file provides Swift language support by invoking SourceKit internally.
1313
//===----------------------------------------------------------------------===//
1414

15-
import Foundation
16-
1715
enum SourceKitdError: Error, CustomStringConvertible {
1816
case EditorOpenError(message: String)
1917
case EditorCloseError(message: String)
@@ -65,16 +63,15 @@ public class SwiftLang {
6563
/// thread safe.
6664
/// - Parameter url: The URL you wish to parse.
6765
/// - Returns: The syntax tree in Json format string.
68-
public static func parse(_ url: URL) throws -> String {
69-
let Path = url.path
70-
return try parse(content: Path, name: Path, isURL: true)
66+
public static func parse(path: String) throws -> String {
67+
return try parse(content: path, name: path, isURL: true)
7168
}
7269

7370
/// Parses a given source buffer into a `Syntax` tree in Json serialization
7471
/// format by querying SourceKitd service. This function isn't thread safe.
7572
/// - Parameter source: The source buffer you wish to parse.
7673
/// - Returns: The syntax tree in Json format string.
77-
public static func parse(_ source: String) throws -> String {
74+
public static func parse(source: String) throws -> String {
7875
return try parse(content: source, name: "foo", isURL: false)
7976
}
8077
}

0 commit comments

Comments
 (0)