Skip to content

Commit 71987b9

Browse files
authored
Merge pull request #8485 from norio-nomura/enable-sourcekit-test
Enable SourceKit tests if building SourceKit
2 parents cd262be + 07803b1 commit 71987b9

18 files changed

+98
-32
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ endif()
381381
option(SWIFT_BUILD_SOURCEKIT
382382
"Build SourceKit"
383383
${SWIFT_BUILD_SOURCEKIT_default})
384+
option(SWIFT_ENABLE_SOURCEKIT_TESTS
385+
"Enable running SourceKit tests"
386+
${SWIFT_BUILD_SOURCEKIT_default})
384387

385388
#
386389
# Assume a new enough ar to generate the index at construction time. This avoids

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ normalize_boolean_spelling(LLVM_ENABLE_ASSERTIONS)
128128
normalize_boolean_spelling(SWIFT_STDLIB_ASSERTIONS)
129129
normalize_boolean_spelling(SWIFT_AST_VERIFIER)
130130
normalize_boolean_spelling(SWIFT_ASAN_BUILD)
131+
normalize_boolean_spelling(SWIFT_ENABLE_SOURCEKIT_TESTS)
131132
is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED)
132133

133134
set(profdata_merge_worker

test/SourceKit/CodeComplete/complete_moduleimportdepth.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ func test() {
66
}
77

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

test/SourceKit/CodeComplete/complete_sort_order.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func test() {
77

88
}
99

10-
// XFAIL: broken_std_regex
10+
// XFAIL: broken_std_regex, linux
1111
// RUN: %sourcekitd-test -req=complete -req-opts=hidelowpriority=0 -pos=7:1 %s -- %s > %t.orig
1212
// RUN: %FileCheck -check-prefix=NAME %s < %t.orig
1313
// Make sure the order is as below, foo(Int) should come before foo(String).

test/SourceKit/CursorInfo/cursor_info.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct HasLocalizationKey {}
214214
/// - LocalizationKey: ABC
215215
func hasLocalizationKey2() {}
216216

217+
// REQUIRES: objc_interop
217218
// RUN: rm -rf %t.tmp
218219
// RUN: mkdir -p %t.tmp
219220
// RUN: %swiftc_driver -emit-module -o %t.tmp/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift

test/SourceKit/CursorInfo/cursor_stdlib.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func foo2(_ a : inout [S1]) {
2121
import Swift
2222
func foo3(a: Float, b: Bool) {}
2323

24+
// REQUIRES: objc_interop
2425
// RUN: %sourcekitd-test -req=cursor -pos=3:18 %s -- %s %mcp_opt %clang-importer-sdk | %FileCheck -check-prefix=CHECK-OVERLAY %s
2526
// CHECK-OVERLAY: source.lang.swift.ref.var.global
2627
// CHECK-OVERLAY-NEXT: NSUTF8StringEncoding

test/SourceKit/CursorInfo/cursor_usr.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct S1 {}
88

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

11+
// REQUIRES: objc_interop
1112
// RUN: rm -rf %t
1213
// RUN: mkdir -p %t
1314
// RUN: %swiftc_driver -emit-module -o %t/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift

test/SourceKit/DocumentStructure/structure.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66

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

test/SourceKit/Indexing/index_is_test_candidate.swift.response

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{
3737
key.kind: source.lang.swift.decl.class,
3838
key.name: "XCTestCase",
39-
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
39+
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
4040
key.line: 15,
4141
key.column: 7
4242
},
@@ -50,7 +50,7 @@
5050
{
5151
key.kind: source.lang.swift.ref.class,
5252
key.name: "XCTestCase",
53-
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
53+
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
5454
key.line: 16,
5555
key.column: 32
5656
}
@@ -59,7 +59,7 @@
5959
{
6060
key.kind: source.lang.swift.ref.class,
6161
key.name: "XCTestCase",
62-
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
62+
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
6363
key.line: 16,
6464
key.column: 32
6565
},
@@ -68,9 +68,11 @@
6868
key.name: "test_startsWithTest_takesNoParams_returnsVoid_butIsPrivate()",
6969
key.usr: "s:23index_is_test_candidate14MyPrivateClass33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B9LLC0c47_startsWithTest_takesNoParams_returnsVoid_butIsF0yyF",
7070
key.line: 17,
71-
key.column: 8
71+
key.column: 8,
72+
key.is_dynamic: 1
7273
}
73-
]
74+
],
75+
key.is_test_candidate: 1
7476
},
7577
{
7678
key.kind: source.lang.swift.decl.class,
@@ -82,7 +84,7 @@
8284
{
8385
key.kind: source.lang.swift.ref.class,
8486
key.name: "XCTestCase",
85-
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
87+
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
8688
key.line: 20,
8789
key.column: 24
8890
}
@@ -91,7 +93,7 @@
9193
{
9294
key.kind: source.lang.swift.ref.class,
9395
key.name: "XCTestCase",
94-
key.usr: "s:C28index_is_test_candidate_objc10XCTestCase",
96+
key.usr: "s:23index_is_test_candidate10XCTestCaseC",
9597
key.line: 20,
9698
key.column: 24
9799
},
@@ -100,14 +102,16 @@
100102
key.name: "doesNotStartWithTest()",
101103
key.usr: "s:23index_is_test_candidate7MyClassC20doesNotStartWithTestyyF",
102104
key.line: 21,
103-
key.column: 8
105+
key.column: 8,
106+
key.is_dynamic: 1
104107
},
105108
{
106109
key.kind: source.lang.swift.decl.function.method.instance,
107110
key.name: "test_startsWithTest_butTakesAParam(param:)",
108111
key.usr: "s:23index_is_test_candidate7MyClassC0C30_startsWithTest_butTakesAParamySi5param_tF",
109112
key.line: 22,
110113
key.column: 8,
114+
key.is_dynamic: 1,
111115
key.entities: [
112116
{
113117
key.kind: source.lang.swift.ref.struct,
@@ -124,6 +128,7 @@
124128
key.usr: "s:23index_is_test_candidate7MyClassC0C50_startsWithTest_andTakesNoParams_butReturnsNonVoidSiyF",
125129
key.line: 23,
126130
key.column: 8,
131+
key.is_dynamic: 1,
127132
key.entities: [
128133
{
129134
key.kind: source.lang.swift.ref.struct,
@@ -139,14 +144,16 @@
139144
key.name: "test_startsWithTest_takesNoParams_andReturnsVoid_butIsPrivate()",
140145
key.usr: "s:23index_is_test_candidate7MyClassC0C57_startsWithTest_takesNoParams_andReturnsVoid_butIsPrivate33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B9LLyyF",
141146
key.line: 24,
142-
key.column: 16
147+
key.column: 16,
148+
key.is_dynamic: 1
143149
},
144150
{
145151
key.kind: source.lang.swift.decl.function.method.instance,
146152
key.name: "test_startsWithTest_takesNoParams_returnsVoid()",
147153
key.usr: "s:23index_is_test_candidate7MyClassC0C41_startsWithTest_takesNoParams_returnsVoidyyF",
148154
key.line: 25,
149155
key.column: 8,
156+
key.is_dynamic: 1,
150157
key.is_test_candidate: 1
151158
},
152159
{
@@ -155,9 +162,11 @@
155162
key.usr: "s:23index_is_test_candidate7MyClassC0C51_startsWithTest_takesNoParams_returnsVoid_andThrowsyyKF",
156163
key.line: 26,
157164
key.column: 8,
165+
key.is_dynamic: 1,
158166
key.is_test_candidate: 1
159167
}
160-
]
168+
],
169+
key.is_test_candidate: 1
161170
}
162171
]
163172
}

test/SourceKit/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if 'OS=macosx' not in config.available_features:
1+
if 'sourcekit' not in config.available_features:
22
config.unsupported = True
33

44
else:

test/lit.site.cfg.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ if "@CMAKE_GENERATOR@" == "Xcode":
8383

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

86+
if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE":
87+
config.available_features.add('sourcekit')
88+
8689
# Let the main config do the real work.
8790
if config.test_exec_root is None:
8891
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,9 @@ class DocSyntaxWalker : public SyntaxModelWalker {
762762
};
763763
} // end anonymous namespace
764764

765-
static bool makeParserAST(CompilerInstance &CI, StringRef Text) {
766-
CompilerInvocation Invocation;
765+
static bool makeParserAST(CompilerInstance &CI, StringRef Text,
766+
CompilerInvocation Invocation) {
767+
Invocation.clearInputs();
767768
Invocation.setModuleName("main");
768769
Invocation.setInputKind(InputFileKind::IFK_Swift);
769770

@@ -974,7 +975,7 @@ static bool reportModuleDocInfo(CompilerInvocation Invocation,
974975
return true;
975976

976977
CompilerInstance ParseCI;
977-
if (makeParserAST(ParseCI, IFaceInfo.Text))
978+
if (makeParserAST(ParseCI, IFaceInfo.Text, Invocation))
978979
return true;
979980
addParameterEntities(ParseCI, IFaceInfo);
980981

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ class DocSyntaxWalker : public SyntaxModelWalker {
225225

226226
} // end anonymous namespace
227227

228-
static bool makeParserAST(CompilerInstance &CI, StringRef Text) {
229-
CompilerInvocation Invocation;
228+
static bool makeParserAST(CompilerInstance &CI, StringRef Text,
229+
CompilerInvocation Invocation) {
230+
Invocation.clearInputs();
230231
Invocation.setModuleName("main");
231232
Invocation.setInputKind(InputFileKind::IFK_Swift);
232233

@@ -358,6 +359,7 @@ SwiftInterfaceGenContextRef
358359
SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
359360
StringRef SourceFileName,
360361
ASTUnitRef AstUnit,
362+
CompilerInvocation Invocation,
361363
std::string &ErrMsg) {
362364
SwiftInterfaceGenContextRef IFaceGenCtx{ new SwiftInterfaceGenContext() };
363365
IFaceGenCtx->Impl.DocumentName = DocumentName;
@@ -371,7 +373,8 @@ SwiftInterfaceGenContext::createForSwiftSource(StringRef DocumentName,
371373
AnnotatingPrinter Printer(IFaceGenCtx->Impl.Info, OS);
372374
printSwiftSourceInterface(AstUnit->getPrimarySourceFile(), Printer, Options);
373375
IFaceGenCtx->Impl.Info.Text = OS.str();
374-
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
376+
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
377+
Invocation)) {
375378
ErrMsg = "Error during syntactic parsing";
376379
return nullptr;
377380
}
@@ -434,7 +437,8 @@ SwiftInterfaceGenContext::create(StringRef DocumentName,
434437
return nullptr;
435438
}
436439

437-
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
440+
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
441+
Invocation)) {
438442
ErrMsg = "Error during syntactic parsing";
439443
return nullptr;
440444
}
@@ -482,7 +486,8 @@ SwiftInterfaceGenContext::createForTypeInterface(CompilerInvocation Invocation,
482486
IFaceGenCtx->Impl.DocumentName, ErrorMsg))
483487
return nullptr;
484488
IFaceGenCtx->Impl.Info.Text = OS.str();
485-
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text)) {
489+
if (makeParserAST(IFaceGenCtx->Impl.TextCI, IFaceGenCtx->Impl.Info.Text,
490+
Invocation)) {
486491
ErrorMsg = "Error during syntactic parsing";
487492
return nullptr;
488493
}
@@ -738,22 +743,26 @@ class PrimaryFileInterfaceConsumer : public SwiftASTConsumer {
738743
std::string SourceFileName;
739744
SwiftInterfaceGenMap &Contexts;
740745
std::shared_ptr<EditorConsumer> Consumer;
746+
SwiftInvocationRef ASTInvok;
741747

742748
public:
743749
PrimaryFileInterfaceConsumer(StringRef Name, StringRef SourceFileName,
744750
SwiftInterfaceGenMap &Contexts,
745-
std::shared_ptr<EditorConsumer> Consumer) :
751+
std::shared_ptr<EditorConsumer> Consumer,
752+
SwiftInvocationRef ASTInvok) :
746753
Name(Name), SourceFileName(SourceFileName), Contexts(Contexts),
747-
Consumer(Consumer) {}
754+
Consumer(Consumer), ASTInvok(ASTInvok) {}
748755

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

753760
void handlePrimaryAST(ASTUnitRef AstUnit) override {
761+
CompilerInvocation CompInvok;
762+
ASTInvok->applyTo(CompInvok);
754763
std::string Error;
755764
auto IFaceGenRef = SwiftInterfaceGenContext::createForSwiftSource(Name,
756-
SourceFileName, AstUnit, Error);
765+
SourceFileName, AstUnit, CompInvok, Error);
757766
if (!Error.empty())
758767
Consumer->handleRequestError(Error.data());
759768
Contexts.set(Name, IFaceGenRef);
@@ -782,7 +791,7 @@ void SwiftLangSupport::editorOpenSwiftSourceInterface(StringRef Name,
782791
std::make_pair("SourceName", SourceName)});
783792
}
784793
auto AstConsumer = std::make_shared<PrimaryFileInterfaceConsumer>(Name,
785-
SourceName, IFaceGenContexts, Consumer);
794+
SourceName, IFaceGenContexts, Consumer, Invocation);
786795
static const char OncePerASTToken = 0;
787796
getASTManager().processASTAsync(Invocation, AstConsumer, &OncePerASTToken);
788797
}

tools/SourceKit/lib/SwiftLang/SwiftInterfaceGenContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SwiftInterfaceGenContext :
5050
static SwiftInterfaceGenContextRef createForSwiftSource(StringRef DocumentName,
5151
StringRef SourceFileName,
5252
ASTUnitRef AstUnit,
53+
swift::CompilerInvocation Invocation,
5354
std::string &ErrMsg);
5455

5556
~SwiftInterfaceGenContext();

tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ set(sourcekitdInProc_args
1010
)
1111

1212
if (SOURCEKIT_INSTALLING_INPROC)
13-
add_sourcekit_framework(sourcekitdInProc
14-
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/sourcekitd.h
15-
${sourcekitdInProc_args}
16-
MODULEMAP module.modulemap
17-
INSTALL_IN_COMPONENT sourcekit-inproc
18-
)
19-
set_property(TARGET sourcekitdInProc APPEND_STRING PROPERTY LINK_FLAGS " -fapplication-extension")
13+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
14+
add_sourcekit_framework(sourcekitdInProc
15+
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/sourcekitd.h
16+
${sourcekitdInProc_args}
17+
MODULEMAP module.modulemap
18+
INSTALL_IN_COMPONENT sourcekit-inproc
19+
)
20+
set_property(TARGET sourcekitdInProc APPEND_STRING PROPERTY LINK_FLAGS " -fapplication-extension")
21+
else()
22+
add_sourcekit_library(sourcekitdInProc
23+
${sourcekitdInProc_args}
24+
INSTALL_IN_COMPONENT sourcekit-inproc
25+
SHARED
26+
)
27+
endif()
2028
else()
2129
add_sourcekit_library(sourcekitdInProc
2230
${sourcekitdInProc_args}

tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-InProc.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "sourcekitd/sourcekitd.h"
1515
#include "sourcekitd/Internal.h"
1616
#include "sourcekitd/CodeCompletionResultsArray.h"
17+
#include "sourcekitd/DocStructureArray.h"
1718
#include "sourcekitd/DocSupportAnnotationArray.h"
1819
#include "sourcekitd/TokenAnnotationsArray.h"
1920
#include "sourcekitd/Logging.h"
@@ -249,6 +250,10 @@ class SKDCustomData: public SKDObject {
249250
case CustomBufferKind::TokenAnnotationsArray:
250251
case CustomBufferKind::DocSupportAnnotationArray:
251252
case CustomBufferKind::CodeCompletionResultsArray:
253+
case CustomBufferKind::DocStructureArray:
254+
case CustomBufferKind::InheritedTypesArray:
255+
case CustomBufferKind::DocStructureElementArray:
256+
case CustomBufferKind::AttributesArray:
252257
return SOURCEKITD_VARIANT_TYPE_ARRAY;
253258
}
254259
llvm::report_fatal_error("sourcekitd object did not resolve to a known type");
@@ -927,6 +932,18 @@ static sourcekitd_variant_t variantFromSKDObject(SKDObjectRef Object) {
927932
case CustomBufferKind::CodeCompletionResultsArray:
928933
return {{ (uintptr_t)getVariantFunctionsForCodeCompletionResultsArray(),
929934
(uintptr_t)DataObject->getDataPtr(), 0 }};
935+
case CustomBufferKind::DocStructureArray:
936+
return {{ (uintptr_t)getVariantFunctionsForDocStructureArray(),
937+
(uintptr_t)DataObject->getDataPtr(), ~size_t(0) }};
938+
case CustomBufferKind::InheritedTypesArray:
939+
return {{ (uintptr_t)getVariantFunctionsForInheritedTypesArray(),
940+
(uintptr_t)DataObject->getDataPtr(), 0 }};
941+
case CustomBufferKind::DocStructureElementArray:
942+
return {{ (uintptr_t)getVariantFunctionsForDocStructureElementArray(),
943+
(uintptr_t)DataObject->getDataPtr(), 0 }};
944+
case CustomBufferKind::AttributesArray:
945+
return {{ (uintptr_t)getVariantFunctionsForAttributesArray(),
946+
(uintptr_t)DataObject->getDataPtr(), 0 }};
930947
}
931948
}
932949

0 commit comments

Comments
 (0)