@@ -577,47 +577,58 @@ std::error_code ImplicitSerializedModuleLoader::findModuleFilesInDirectory(
577
577
return std::error_code ();
578
578
}
579
579
580
- bool ImplicitSerializedModuleLoader::maybeDiagnoseTargetMismatch (
581
- SourceLoc sourceLocation, StringRef moduleName,
582
- const SerializedModuleBaseName &absoluteBaseName,
583
- bool isCanImportLookup) {
580
+ void SerializedModuleLoaderBase::identifyArchitectureVariants (
581
+ ASTContext &Ctx, const SerializedModuleBaseName &absoluteBaseName,
582
+ std::vector<std::string> &incompatibleArchModules) {
584
583
llvm::vfs::FileSystem &fs = *Ctx.SourceMgr .getFileSystem ();
585
584
586
- // Get the last component of the base name, which is the target-specific one.
587
- auto target = llvm::sys::path::filename (absoluteBaseName.baseName );
588
-
589
585
// Strip off the last component to get the .swiftmodule folder.
590
586
auto dir = absoluteBaseName.baseName ;
591
587
llvm::sys::path::remove_filename (dir);
592
588
593
589
std::error_code errorCode;
594
- std::string foundArchs;
595
590
for (llvm::vfs::directory_iterator directoryIterator =
596
591
fs.dir_begin (dir, errorCode), endIterator;
597
592
directoryIterator != endIterator;
598
593
directoryIterator.increment (errorCode)) {
599
594
if (errorCode)
600
- return false ;
595
+ continue ;
601
596
StringRef filePath = directoryIterator->path ();
602
597
StringRef extension = llvm::sys::path::extension (filePath);
603
598
if (file_types::lookupTypeForExtension (extension) ==
604
599
file_types::TY_SwiftModuleFile) {
605
- if (!foundArchs.empty ())
606
- foundArchs += " , " ;
607
- foundArchs += llvm::sys::path::stem (filePath).str ();
600
+ incompatibleArchModules.push_back (filePath.str ());
608
601
}
609
602
}
603
+ }
610
604
611
- if (foundArchs.empty ()) {
612
- // Maybe this swiftmodule directory only contains swiftinterfaces, or
613
- // maybe something else is going on. Regardless, we shouldn't emit a
614
- // possibly incorrect diagnostic.
605
+ bool ImplicitSerializedModuleLoader::handlePossibleTargetMismatch (
606
+ SourceLoc sourceLocation, StringRef moduleName,
607
+ const SerializedModuleBaseName &absoluteBaseName,
608
+ bool isCanImportLookup) {
609
+ std::string foundArchs;
610
+ std::vector<std::string> foundIncompatibleArchModules;
611
+ identifyArchitectureVariants (Ctx, absoluteBaseName,
612
+ foundIncompatibleArchModules);
613
+
614
+ // Maybe this swiftmodule directory only contains swiftinterfaces, or
615
+ // maybe something else is going on. Regardless, we shouldn't emit a
616
+ // possibly incorrect diagnostic.
617
+ if (foundIncompatibleArchModules.empty ())
615
618
return false ;
619
+
620
+ // Generate combined list of discovered architectures
621
+ // for the diagnostic
622
+ for (const auto &modulePath : foundIncompatibleArchModules) {
623
+ if (!foundArchs.empty ())
624
+ foundArchs += " , " ;
625
+ foundArchs += llvm::sys::path::stem (modulePath).str ();
616
626
}
617
627
618
628
Ctx.Diags
619
- .diagnose (sourceLocation, diag::sema_no_import_target, moduleName, target,
620
- foundArchs, dir)
629
+ .diagnose (sourceLocation, diag::sema_no_import_target, moduleName,
630
+ llvm::sys::path::filename (absoluteBaseName.baseName ),
631
+ foundArchs, absoluteBaseName.baseName )
621
632
.limitBehaviorIf (isCanImportLookup, DiagnosticBehavior::Warning);
622
633
return !isCanImportLookup;
623
634
}
@@ -782,8 +793,8 @@ bool SerializedModuleLoaderBase::findModule(
782
793
// We can only get here if all targetFileNamePairs failed with
783
794
// 'std::errc::no_such_file_or_directory'.
784
795
if (firstAbsoluteBaseName &&
785
- maybeDiagnoseTargetMismatch (moduleID.Loc , moduleName,
786
- *firstAbsoluteBaseName, isCanImportLookup))
796
+ handlePossibleTargetMismatch (moduleID.Loc , moduleName,
797
+ *firstAbsoluteBaseName, isCanImportLookup))
787
798
return SearchResult::Error;
788
799
789
800
return SearchResult::NotFound;
0 commit comments