Skip to content

Re-apply "SourceKit: make SwiftLang build in linux. (#18455)" #18506

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

Merged
merged 1 commit into from
Aug 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/SwiftSyntax/AbsolutePosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func getInput(_ file: String) -> URL {
}

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

Expand Down
2 changes: 1 addition & 1 deletion test/SwiftSyntax/DeserializeFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var DecodeTests = TestSuite("DecodeSyntax")

DecodeTests.test("Basic") {
expectDoesNotThrow({
let content = try SwiftLang.parse(getInput("visitor.swift"))
let content = try SwiftLang.parse(path: getInput("visitor.swift").path)
let contentData = content.data(using: .utf8)!
let source = try String(contentsOf: getInput("visitor.swift"))
let parsed = try SyntaxTreeDeserializer().deserialize(contentData)
Expand Down
4 changes: 2 additions & 2 deletions test/SwiftSyntax/ParseFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ParseFile.test("ParseSingleFile") {
let currentFile = URL(fileURLWithPath: #file)
expectDoesNotThrow({
let fileContents = try String(contentsOf: currentFile)
let syntaxTreeData = try SwiftLang.parse(fileContents).data(using: .utf8)!
let syntaxTreeData = try SwiftLang.parse(source: fileContents).data(using: .utf8)!
let parsed = try SyntaxTreeDeserializer().deserialize(syntaxTreeData)
expectEqual("\(parsed)", fileContents)
})
Expand All @@ -40,7 +40,7 @@ ParseFile.test("ParseSingleFile") {
ParseFile.test("ParseBuffer") {
expectDoesNotThrow({
let content = "func foo() {}"
let syntaxTreeData = try SwiftLang.parse(content).data(using: .utf8)!
let syntaxTreeData = try SwiftLang.parse(source: content).data(using: .utf8)!
let parsed = try SyntaxTreeDeserializer().deserialize(syntaxTreeData)
expectEqual("\(parsed)", content)
})
Expand Down
2 changes: 1 addition & 1 deletion test/SwiftSyntax/VisitorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func getInput(_ file: String) -> URL {
}

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

Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ include_directories(BEFORE
)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(SOURCEKIT_DEFAULT_TARGET_SDK "LINUX")
if(SWIFT_BUILD_SOURCEKIT)
include(ExternalProject)
ExternalProject_Add(libdispatch
Expand Down
4 changes: 1 addition & 3 deletions tools/SourceKit/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ if(HAVE_UNICODE_LIBEDIT)
add_swift_tool_subdirectory(sourcekitd-repl)
endif()
add_swift_tool_subdirectory(complete-test)
if(BUILD_FOUNDATION)
add_subdirectory(swift-lang)
endif()
add_subdirectory(swift-lang)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module sourcekitd {
umbrella header "sourcekitd.h"
export *
}
20 changes: 12 additions & 8 deletions tools/SourceKit/tools/swift-lang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
set(EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
set(EXTRA_LINKER_FLAGS "-Xlinker" "-rpath" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}"
"-Xlinker" "-F" "-Xlinker" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
set(EXTRA_COMPILE_FLAGS "-I" "${SOURCEKITD_SOURCE_DIR}/include/sourcekitd")
set(SOURCEKITD_LINK_LIBS sourcekitdInProc)
set(INSTALLED_COMP sourcekit-inproc)
else()
set(EXTRA_COMPILE_FLAGS "-F" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
set(SOURCEKITD_LINK_LIBS sourcekitd)
set(INSTALLED_COMP sourcekit-xpc-service)
endif()

add_swift_library(swiftSwiftLang SHARED
SwiftLang.swift
Expand All @@ -11,10 +17,8 @@ add_swift_library(swiftSwiftLang SHARED
UIDs.swift.gyb

DEPENDS sourcekitd-test
PRIVATE_LINK_LIBRARIES sourcekitd
PRIVATE_LINK_LIBRARIES ${SOURCEKITD_LINK_LIBS}
SWIFT_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
LINK_FLAGS ${EXTRA_LINKER_FLAGS}
SWIFT_MODULE_DEPENDS Foundation
INSTALL_IN_COMPONENT sourcekit-xpc-service
TARGET_SDKS OSX
INSTALL_IN_COMPONENT ${INSTALLED_COMP}
TARGET_SDKS ${SOURCEKIT_DEFAULT_TARGET_SDK}
IS_STDLIB)
1 change: 0 additions & 1 deletion tools/SourceKit/tools/swift-lang/SourceKitdClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//

import sourcekitd
import Foundation

public class SourceKitdService {

Expand Down
5 changes: 2 additions & 3 deletions tools/SourceKit/tools/swift-lang/SourceKitdResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// This file provides convenient APIs to interpret a SourceKitd response.
//===----------------------------------------------------------------------===//

import Foundation
import sourcekitd

public class SourceKitdResponse: CustomStringConvertible {
Expand Down Expand Up @@ -253,6 +252,6 @@ extension sourcekitd_variant_t: CustomStringConvertible {
}

private func fromCStringLen(_ ptr: UnsafePointer<Int8>, length: Int) -> String? {
return NSString(bytes: ptr, length: length,
encoding: String.Encoding.utf8.rawValue) as String?
return String(decoding: Array(UnsafeBufferPointer(start: ptr, count: length)).map {
UInt8(bitPattern: $0) }, as: UTF8.self)
}
9 changes: 3 additions & 6 deletions tools/SourceKit/tools/swift-lang/SwiftLang.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// This file provides Swift language support by invoking SourceKit internally.
//===----------------------------------------------------------------------===//

import Foundation

enum SourceKitdError: Error, CustomStringConvertible {
case EditorOpenError(message: String)
case EditorCloseError(message: String)
Expand Down Expand Up @@ -65,16 +63,15 @@ public class SwiftLang {
/// thread safe.
/// - Parameter url: The URL you wish to parse.
/// - Returns: The syntax tree in Json format string.
public static func parse(_ url: URL) throws -> String {
let Path = url.path
return try parse(content: Path, name: Path, isURL: true)
public static func parse(path: String) throws -> String {
return try parse(content: path, name: path, isURL: true)
}

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