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

Enable SourceKit tests if building SourceKit #8485

Merged
merged 13 commits into from
Apr 24, 2017
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ endif()
option(SWIFT_BUILD_SOURCEKIT
"Build SourceKit"
${SWIFT_BUILD_SOURCEKIT_default})
option(SWIFT_ENABLE_SOURCEKIT_TESTS
"Enable running SourceKit tests"
${SWIFT_BUILD_SOURCEKIT_default})

#
# Assume a new enough ar to generate the index at construction time. This avoids
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ normalize_boolean_spelling(LLVM_ENABLE_ASSERTIONS)
normalize_boolean_spelling(SWIFT_STDLIB_ASSERTIONS)
normalize_boolean_spelling(SWIFT_AST_VERIFIER)
normalize_boolean_spelling(SWIFT_ASAN_BUILD)
normalize_boolean_spelling(SWIFT_ENABLE_SOURCEKIT_TESTS)
is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED)

set(profdata_merge_worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ func test() {
}

// XFAIL: broken_std_regex
// REQUIRES: objc_interop
// RUN: %complete-test -hide-none -group=none -tok=A %s -raw -- -I %S/Inputs -F %S/../Inputs/libIDE-mock-sdk > %t
// RUN: %FileCheck %s < %t

Expand Down
2 changes: 1 addition & 1 deletion test/SourceKit/CodeComplete/complete_sort_order.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func test() {

}

// XFAIL: broken_std_regex
// XFAIL: broken_std_regex, linux
// RUN: %sourcekitd-test -req=complete -req-opts=hidelowpriority=0 -pos=7:1 %s -- %s > %t.orig
// RUN: %FileCheck -check-prefix=NAME %s < %t.orig
// Make sure the order is as below, foo(Int) should come before foo(String).
Expand Down
1 change: 1 addition & 0 deletions test/SourceKit/CursorInfo/cursor_info.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ struct HasLocalizationKey {}
/// - LocalizationKey: ABC
func hasLocalizationKey2() {}

// REQUIRES: objc_interop
// RUN: rm -rf %t.tmp
// RUN: mkdir -p %t.tmp
// RUN: %swiftc_driver -emit-module -o %t.tmp/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift
Expand Down
1 change: 1 addition & 0 deletions test/SourceKit/CursorInfo/cursor_stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func foo2(_ a : inout [S1]) {
import Swift
func foo3(a: Float, b: Bool) {}

// REQUIRES: objc_interop
// RUN: %sourcekitd-test -req=cursor -pos=3:18 %s -- %s %mcp_opt %clang-importer-sdk | %FileCheck -check-prefix=CHECK-OVERLAY %s
// CHECK-OVERLAY: source.lang.swift.ref.var.global
// CHECK-OVERLAY-NEXT: NSUTF8StringEncoding
Expand Down
1 change: 1 addition & 0 deletions test/SourceKit/CursorInfo/cursor_usr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct S1 {}

func foo(x: FooStruct1) -> S1 {}

// REQUIRES: objc_interop
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %swiftc_driver -emit-module -o %t/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift
Expand Down
1 change: 0 additions & 1 deletion test/SourceKit/DocumentStructure/structure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@

// RUN: %sourcekitd-test -req=structure %S/../Inputs/placeholders.swift | %sed_clean > %t.placeholders.response
// RUN: diff -u %s.placeholders.response %t.placeholders.response

29 changes: 19 additions & 10 deletions test/SourceKit/Indexing/index_is_test_candidate.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{
key.kind: source.lang.swift.decl.class,
key.name: "XCTestCase",
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
key.line: 15,
key.column: 7
},
Expand All @@ -50,7 +50,7 @@
{
key.kind: source.lang.swift.ref.class,
key.name: "XCTestCase",
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
key.line: 16,
key.column: 32
}
Expand All @@ -59,7 +59,7 @@
{
key.kind: source.lang.swift.ref.class,
key.name: "XCTestCase",
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
key.line: 16,
key.column: 32
},
Expand All @@ -68,9 +68,11 @@
key.name: "test_startsWithTest_takesNoParams_returnsVoid_butIsPrivate()",
key.usr: "s:23index_is_test_candidate14MyPrivateClass33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B9LLC0c47_startsWithTest_takesNoParams_returnsVoid_butIsF0yyF",
key.line: 17,
key.column: 8
key.column: 8,
key.is_dynamic: 1
}
]
],
key.is_test_candidate: 1
},
{
key.kind: source.lang.swift.decl.class,
Expand All @@ -82,7 +84,7 @@
{
key.kind: source.lang.swift.ref.class,
key.name: "XCTestCase",
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
key.line: 20,
key.column: 24
}
Expand All @@ -91,7 +93,7 @@
{
key.kind: source.lang.swift.ref.class,
key.name: "XCTestCase",
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
key.line: 20,
key.column: 24
},
Expand All @@ -100,14 +102,16 @@
key.name: "doesNotStartWithTest()",
key.usr: "s:23index_is_test_candidate7MyClassC20doesNotStartWithTestyyF",
key.line: 21,
key.column: 8
key.column: 8,
key.is_dynamic: 1
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_butTakesAParam(param:)",
key.usr: "s:23index_is_test_candidate7MyClassC0C30_startsWithTest_butTakesAParamySi5param_tF",
key.line: 22,
key.column: 8,
key.is_dynamic: 1,
key.entities: [
{
key.kind: source.lang.swift.ref.struct,
Expand All @@ -124,6 +128,7 @@
key.usr: "s:23index_is_test_candidate7MyClassC0C50_startsWithTest_andTakesNoParams_butReturnsNonVoidSiyF",
key.line: 23,
key.column: 8,
key.is_dynamic: 1,
key.entities: [
{
key.kind: source.lang.swift.ref.struct,
Expand All @@ -139,14 +144,16 @@
key.name: "test_startsWithTest_takesNoParams_andReturnsVoid_butIsPrivate()",
key.usr: "s:23index_is_test_candidate7MyClassC0C57_startsWithTest_takesNoParams_andReturnsVoid_butIsPrivate33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B9LLyyF",
key.line: 24,
key.column: 16
key.column: 16,
key.is_dynamic: 1
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_takesNoParams_returnsVoid()",
key.usr: "s:23index_is_test_candidate7MyClassC0C41_startsWithTest_takesNoParams_returnsVoidyyF",
key.line: 25,
key.column: 8,
key.is_dynamic: 1,
key.is_test_candidate: 1
},
{
Expand All @@ -155,9 +162,11 @@
key.usr: "s:23index_is_test_candidate7MyClassC0C51_startsWithTest_takesNoParams_returnsVoid_andThrowsyyKF",
key.line: 26,
key.column: 8,
key.is_dynamic: 1,
key.is_test_candidate: 1
}
]
],
key.is_test_candidate: 1
}
]
}
2 changes: 1 addition & 1 deletion test/SourceKit/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if 'OS=macosx' not in config.available_features:
if 'sourcekit' not in config.available_features:
config.unsupported = True

else:
Expand Down
3 changes: 3 additions & 0 deletions test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ if "@CMAKE_GENERATOR@" == "Xcode":

config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@")

if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE":
config.available_features.add('sourcekit')

# Let the main config do the real work.
if config.test_exec_root is None:
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
Expand Down
7 changes: 4 additions & 3 deletions tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,9 @@ class DocSyntaxWalker : public SyntaxModelWalker {
};
}

static bool makeParserAST(CompilerInstance &CI, StringRef Text) {
CompilerInvocation Invocation;
static bool makeParserAST(CompilerInstance &CI, StringRef Text,
CompilerInvocation Invocation) {
Invocation.clearInputs();
Invocation.setModuleName("main");
Invocation.setInputKind(InputFileKind::IFK_Swift);

Expand Down Expand Up @@ -934,7 +935,7 @@ static bool reportModuleDocInfo(CompilerInvocation Invocation,
return true;

CompilerInstance ParseCI;
if (makeParserAST(ParseCI, IFaceInfo.Text))
if (makeParserAST(ParseCI, IFaceInfo.Text, Invocation))
return true;
addParameterEntities(ParseCI, IFaceInfo);

Expand Down
27 changes: 18 additions & 9 deletions tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ class DocSyntaxWalker : public SyntaxModelWalker {

}

static bool makeParserAST(CompilerInstance &CI, StringRef Text) {
CompilerInvocation Invocation;
static bool makeParserAST(CompilerInstance &CI, StringRef Text,
CompilerInvocation Invocation) {
Invocation.clearInputs();
Invocation.setModuleName("main");
Invocation.setInputKind(InputFileKind::IFK_Swift);

Expand Down Expand Up @@ -358,6 +359,7 @@ SwiftInterfaceGenContextRef
SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
StringRef SourceFileName,
ASTUnitRef AstUnit,
CompilerInvocation Invocation,
std::string &ErrMsg) {
SwiftInterfaceGenContextRef IFaceGenCtx{ new SwiftInterfaceGenContext() };
IFaceGenCtx->Impl.DocumentName = DocumentName;
Expand All @@ -371,7 +373,8 @@ SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
AnnotatingPrinter Printer(IFaceGenCtx->Impl.Info, OS);
printSwiftSourceInterface(AstUnit->getPrimarySourceFile(), Printer, Options);
IFaceGenCtx->Impl.Info.Text = OS.str();
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
Invocation)) {
ErrMsg = "Error during syntactic parsing";
return nullptr;
}
Expand Down Expand Up @@ -434,7 +437,8 @@ SwiftInterfaceGenContext::create(StringRef DocumentName,
return nullptr;
}

if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
Invocation)) {
ErrMsg = "Error during syntactic parsing";
return nullptr;
}
Expand Down Expand Up @@ -482,7 +486,8 @@ SwiftInterfaceGenContext::createForTypeInterface(CompilerInvocation Invocation,
IFaceGenCtx->Impl.DocumentName, ErrorMsg))
return nullptr;
IFaceGenCtx->Impl.Info.Text = OS.str();
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
Invocation)) {
ErrorMsg = "Error during syntactic parsing";
return nullptr;
}
Expand Down Expand Up @@ -738,22 +743,26 @@ class PrimaryFileInterfaceConsumer : public SwiftASTConsumer {
std::string SourceFileName;
SwiftInterfaceGenMap &Contexts;
std::shared_ptr<EditorConsumer> Consumer;
SwiftInvocationRef ASTInvok;

public:
PrimaryFileInterfaceConsumer(StringRef Name, StringRef SourceFileName,
SwiftInterfaceGenMap &Contexts,
std::shared_ptr<EditorConsumer> Consumer) :
std::shared_ptr<EditorConsumer> Consumer,
SwiftInvocationRef ASTInvok) :
Name(Name), SourceFileName(SourceFileName), Contexts(Contexts),
Consumer(Consumer) {}
Consumer(Consumer), ASTInvok(ASTInvok) {}

void failed(StringRef Error) override {
Consumer->handleRequestError(Error.data());
}

void handlePrimaryAST(ASTUnitRef AstUnit) override {
CompilerInvocation CompInvok;
ASTInvok->applyTo(CompInvok);
std::string Error;
auto IFaceGenRef = SwiftInterfaceGenContext::createForSwiftSource(Name,
SourceFileName, AstUnit, Error);
SourceFileName, AstUnit, CompInvok, Error);
if (!Error.empty())
Consumer->handleRequestError(Error.data());
Contexts.set(Name, IFaceGenRef);
Expand Down Expand Up @@ -782,7 +791,7 @@ void SwiftLangSupport::editorOpenSwiftSourceInterface(StringRef Name,
std::make_pair("SourceName", SourceName)});
}
auto AstConsumer = std::make_shared<PrimaryFileInterfaceConsumer>(Name,
SourceName, IFaceGenContexts, Consumer);
SourceName, IFaceGenContexts, Consumer, Invocation);
static const char OncePerASTToken = 0;
getASTManager().processASTAsync(Invocation, AstConsumer, &OncePerASTToken);
}
Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftInterfaceGenContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SwiftInterfaceGenContext :
static SwiftInterfaceGenContextRef createForSwiftSource(StringRef DocumentName,
StringRef SourceFileName,
ASTUnitRef AstUnit,
swift::CompilerInvocation Invocation,
std::string &ErrMsg);

~SwiftInterfaceGenContext();
Expand Down
22 changes: 15 additions & 7 deletions tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ set(sourcekitdInProc_args
)

if (SOURCEKIT_INSTALLING_INPROC)
add_sourcekit_framework(sourcekitdInProc
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/sourcekitd.h
${sourcekitdInProc_args}
MODULEMAP module.modulemap
INSTALL_IN_COMPONENT sourcekit-inproc
)
set_property(TARGET sourcekitdInProc APPEND_STRING PROPERTY LINK_FLAGS " -fapplication-extension")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
add_sourcekit_framework(sourcekitdInProc
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/sourcekitd.h
${sourcekitdInProc_args}
MODULEMAP module.modulemap
INSTALL_IN_COMPONENT sourcekit-inproc
)
set_property(TARGET sourcekitdInProc APPEND_STRING PROPERTY LINK_FLAGS " -fapplication-extension")
else()
add_sourcekit_library(sourcekitdInProc
${sourcekitdInProc_args}
INSTALL_IN_COMPONENT sourcekit-inproc
SHARED
)
endif()
else()
add_sourcekit_library(sourcekitdInProc
${sourcekitdInProc_args}
Expand Down
17 changes: 17 additions & 0 deletions tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-InProc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "sourcekitd/sourcekitd.h"
#include "sourcekitd/Internal.h"
#include "sourcekitd/CodeCompletionResultsArray.h"
#include "sourcekitd/DocStructureArray.h"
#include "sourcekitd/DocSupportAnnotationArray.h"
#include "sourcekitd/TokenAnnotationsArray.h"
#include "sourcekitd/Logging.h"
Expand Down Expand Up @@ -249,6 +250,10 @@ class SKDCustomData: public SKDObject {
case CustomBufferKind::TokenAnnotationsArray:
case CustomBufferKind::DocSupportAnnotationArray:
case CustomBufferKind::CodeCompletionResultsArray:
case CustomBufferKind::DocStructureArray:
case CustomBufferKind::InheritedTypesArray:
case CustomBufferKind::DocStructureElementArray:
case CustomBufferKind::AttributesArray:
return SOURCEKITD_VARIANT_TYPE_ARRAY;
}
llvm::report_fatal_error("sourcekitd object did not resolve to a known type");
Expand Down Expand Up @@ -927,6 +932,18 @@ static sourcekitd_variant_t variantFromSKDObject(SKDObjectRef Object) {
case CustomBufferKind::CodeCompletionResultsArray:
return {{ (uintptr_t)getVariantFunctionsForCodeCompletionResultsArray(),
(uintptr_t)DataObject->getDataPtr(), 0 }};
case CustomBufferKind::DocStructureArray:
return {{ (uintptr_t)getVariantFunctionsForDocStructureArray(),
(uintptr_t)DataObject->getDataPtr(), ~size_t(0) }};
case CustomBufferKind::InheritedTypesArray:
return {{ (uintptr_t)getVariantFunctionsForInheritedTypesArray(),
(uintptr_t)DataObject->getDataPtr(), 0 }};
case CustomBufferKind::DocStructureElementArray:
return {{ (uintptr_t)getVariantFunctionsForDocStructureElementArray(),
(uintptr_t)DataObject->getDataPtr(), 0 }};
case CustomBufferKind::AttributesArray:
return {{ (uintptr_t)getVariantFunctionsForAttributesArray(),
(uintptr_t)DataObject->getDataPtr(), 0 }};
}
}

Expand Down
Loading