SourceKit: Use actual diagnostics for arg parsing

With this change, you will no longer receive
"error when parsing the compiler arguments". Instead, you will
receive the underlying error, like
"error: unable to load output file map 'output_file_map.json': No such file or directory"
This commit is contained in:
David Goldman
2019-01-03 11:10:31 -05:00
parent c932f60403
commit 3c9f3c8815

View File

@@ -438,14 +438,18 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
Args.push_back(Impl.RuntimeResourcePath.c_str());
Args.append(OrigArgs.begin(), OrigArgs.end());
SmallString<32> ErrStr;
llvm::raw_svector_ostream ErrOS(ErrStr);
StreamDiagConsumer DiagConsumer(ErrOS);
Diags.addConsumer(DiagConsumer);
bool HadError = driver::getSingleFrontendInvocationFromDriverArguments(
Args, Diags, [&](ArrayRef<const char *> FrontendArgs) {
return Invocation.parseArgs(FrontendArgs, Diags);
});
if (HadError) {
// FIXME: Get the actual diagnostic.
Error = "error when parsing the compiler arguments";
Error = ErrOS.str();
return true;
}
@@ -493,20 +497,9 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &CompInvok,
ArrayRef<const char *> OrigArgs,
StringRef PrimaryFile,
std::string &Error) {
SmallString<32> ErrStr;
llvm::raw_svector_ostream ErrOS(ErrStr);
DiagnosticEngine Diagnostics(Impl.SourceMgr);
StreamDiagConsumer DiagConsumer(ErrOS);
Diagnostics.addConsumer(DiagConsumer);
if (initCompilerInvocation(CompInvok, OrigArgs, Diagnostics, PrimaryFile,
Error)) {
if (!ErrOS.str().empty())
Error = ErrOS.str();
return true;
}
return false;
return initCompilerInvocation(CompInvok, OrigArgs, Diagnostics, PrimaryFile,
Error);
}
bool SwiftASTManager::initCompilerInvocationNoInputs(