Skip to content

Commit

Permalink
[SourceKit] Fix “Assertion `!GlibcModuleMapPath.empty()' failed” on L…
Browse files Browse the repository at this point in the history
  • Loading branch information
norio-nomura committed Apr 7, 2017
1 parent 3a3acec commit 8ca7c1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
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

0 comments on commit 8ca7c1d

Please sign in to comment.