@@ -1118,9 +1118,14 @@ static void printASTValidationError(
1118
1118
}
1119
1119
1120
1120
void SwiftASTContext::DiagnoseWarnings (Process &process, Module &module ) const {
1121
- if (HasDiagnostics ())
1122
- process.PrintWarningCantLoadSwiftModule (module ,
1123
- GetAllDiagnostics ().AsCString ());
1121
+ if (!HasDiagnostics ())
1122
+ return ;
1123
+ auto debugger_id = process.GetTarget ().GetDebugger ().GetID ();
1124
+ std::string msg;
1125
+ llvm::raw_string_ostream (msg) << " Cannot load Swift type information for "
1126
+ << module .GetFileSpec ().GetPath ();
1127
+ Debugger::ReportWarning (msg, debugger_id, &m_swift_import_warning);
1128
+ StreamAllDiagnostics (debugger_id);
1124
1129
}
1125
1130
1126
1131
// / Locate the swift-plugin-server for a plugin library,
@@ -1503,8 +1508,8 @@ bool ShouldUnique(StringRef arg) {
1503
1508
} // namespace
1504
1509
1505
1510
// static
1506
- void SwiftASTContext::AddExtraClangArgs (const std::vector<std::string>& source,
1507
- std::vector<std::string>& dest) {
1511
+ void SwiftASTContext::AddExtraClangArgs (const std::vector<std::string> & source,
1512
+ std::vector<std::string> & dest) {
1508
1513
llvm::StringSet<> unique_flags;
1509
1514
for (auto &arg : dest)
1510
1515
unique_flags.insert (arg);
@@ -1648,6 +1653,41 @@ void SwiftASTContext::RemapClangImporterOptions(
1648
1653
}
1649
1654
}
1650
1655
1656
+ void SwiftASTContext::FilterClangImporterOptions (
1657
+ std::vector<std::string> &extra_args, SwiftASTContext *ctx) {
1658
+ std::string ivfs_arg;
1659
+ // Copy back a filtered version of ExtraArgs.
1660
+ std::vector<std::string> orig_args (std::move (extra_args));
1661
+ for (auto &arg : orig_args) {
1662
+ // The VFS options turn into fatal errors when the referenced file
1663
+ // is not found. Since the Xcode build system tends to create a
1664
+ // lot of VFS overlays by default, stat them and emit a warning if
1665
+ // the yaml file couldn't be found.
1666
+ if (StringRef (arg).startswith (" -ivfs" )) {
1667
+ // Stash the argument.
1668
+ ivfs_arg = arg;
1669
+ continue ;
1670
+ }
1671
+ if (!ivfs_arg.empty ()) {
1672
+ auto clear_ivfs_arg = llvm::make_scope_exit ([&] { ivfs_arg.clear (); });
1673
+ if (!FileSystem::Instance ().Exists (arg)) {
1674
+ if (ctx) {
1675
+ std::string error;
1676
+ llvm::raw_string_ostream (error)
1677
+ << " Ignoring missing VFS file: " << arg
1678
+ << " \n This is the likely root cause for any subsequent compiler "
1679
+ " errors." ;
1680
+ ctx->AddDiagnostic (eDiagnosticSeverityWarning, error);
1681
+ }
1682
+ continue ;
1683
+ }
1684
+ // Keep it.
1685
+ extra_args.push_back (ivfs_arg);
1686
+ }
1687
+ extra_args.push_back (std::move (arg));
1688
+ }
1689
+ }
1690
+
1651
1691
// / Retrieve the .dSYM bundle for \p module.
1652
1692
static llvm::Optional<StringRef> GetDSYMBundle (Module &module ) {
1653
1693
auto sym_file = module .GetSymbolFile ();
@@ -1904,6 +1944,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1904
1944
1905
1945
// Apply source path remappings found in the module's dSYM.
1906
1946
swift_ast_sp->RemapClangImporterOptions (module .GetSourceMappingList ());
1947
+ swift_ast_sp->FilterClangImporterOptions (
1948
+ swift_ast_sp->GetClangImporterOptions ().ExtraArgs , swift_ast_sp.get ());
1907
1949
1908
1950
// Add Swift interfaces in the .dSYM at the end of the search paths.
1909
1951
// .swiftmodules win over .swiftinterfaces, when they are loaded
@@ -2396,6 +2438,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2396
2438
2397
2439
// Apply source path remappings found in the target settings.
2398
2440
swift_ast_sp->RemapClangImporterOptions (target.GetSourcePathMap ());
2441
+ swift_ast_sp->FilterClangImporterOptions (
2442
+ swift_ast_sp->GetClangImporterOptions ().ExtraArgs , swift_ast_sp.get ());
2399
2443
2400
2444
// This needs to happen once all the import paths are set, or
2401
2445
// otherwise no modules will be found.
@@ -2483,6 +2527,35 @@ Status SwiftASTContext::GetAllDiagnostics() const {
2483
2527
return error;
2484
2528
}
2485
2529
2530
+ void SwiftASTContext::StreamAllDiagnostics (
2531
+ llvm::Optional<lldb::user_id_t > debugger_id) const {
2532
+ Status error = m_fatal_errors;
2533
+ if (!error.Success ()) {
2534
+ Debugger::ReportWarning (error.AsCString (), debugger_id,
2535
+ &m_swift_diags_streamed);
2536
+ return ;
2537
+ }
2538
+
2539
+ // Retrieve the error message from the DiagnosticConsumer.
2540
+ DiagnosticManager diagnostic_manager;
2541
+ PrintDiagnostics (diagnostic_manager);
2542
+ for (auto &diag : diagnostic_manager.Diagnostics ())
2543
+ if (diag) {
2544
+ std::string msg = diag->GetMessage ().str ();
2545
+ switch (diag->GetSeverity ()) {
2546
+ case eDiagnosticSeverityError:
2547
+ Debugger::ReportError (msg, debugger_id, &m_swift_diags_streamed);
2548
+ break ;
2549
+ case eDiagnosticSeverityWarning:
2550
+ case eDiagnosticSeverityRemark:
2551
+ Debugger::ReportWarning (msg, debugger_id, &m_swift_warning_streamed);
2552
+ break ;
2553
+ }
2554
+ }
2555
+ static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
2556
+ ->Clear ();
2557
+ }
2558
+
2486
2559
void SwiftASTContext::LogFatalErrors () const {
2487
2560
// Avoid spamming the health log with redundant copies of the fatal error.
2488
2561
if (m_logged_fatal_error) {
0 commit comments