@@ -552,6 +552,7 @@ void ABIDependencyEvaluator::printABIExportMap(llvm::raw_ostream &os) const {
552
552
// FIXME: Use the VFS instead of handling paths directly. We are particularly
553
553
// sloppy about handling relative paths in the dependency tracker.
554
554
static void computeSwiftModuleTraceInfo (
555
+ ASTContext &ctx,
555
556
const SmallPtrSetImpl<ModuleDecl *> &abiDependencies,
556
557
const llvm::DenseMap<StringRef, ModuleDecl *> &pathToModuleDecl,
557
558
const DependencyTracker &depTracker, StringRef prebuiltCachePath,
@@ -569,6 +570,8 @@ static void computeSwiftModuleTraceInfo(
569
570
SmallVector<std::string, 16 > dependencies{deps.begin (), deps.end ()};
570
571
auto incrDeps = depTracker.getIncrementalDependencyPaths ();
571
572
dependencies.append (incrDeps.begin (), incrDeps.end ());
573
+ auto sharedLibraryExtRegex =
574
+ llvm::Regex (" dylib|so|dll" , llvm::Regex::IgnoreCase);
572
575
for (const auto &depPath : dependencies) {
573
576
574
577
// Decide if this is a swiftmodule based on the extension of the raw
@@ -580,8 +583,10 @@ static void computeSwiftModuleTraceInfo(
580
583
auto isSwiftmodule = moduleFileType == file_types::TY_SwiftModuleFile;
581
584
auto isSwiftinterface =
582
585
moduleFileType == file_types::TY_SwiftModuleInterfaceFile;
586
+ auto isSharedLibrary =
587
+ sharedLibraryExtRegex.match (llvm::sys::path::extension (depPath));
583
588
584
- if (!(isSwiftmodule || isSwiftinterface))
589
+ if (!(isSwiftmodule || isSwiftinterface || isSharedLibrary ))
585
590
continue ;
586
591
587
592
auto dep = pathToModuleDecl.find (depPath);
@@ -637,6 +642,34 @@ static void computeSwiftModuleTraceInfo(
637
642
continue ;
638
643
}
639
644
645
+ // If we found a shared library, it must be a compiler plugin dependency.
646
+ if (isSharedLibrary) {
647
+ // Infer the module name by dropping the library prefix and extension.
648
+ // e.g "/path/to/lib/libPlugin.dylib" -> "Plugin"
649
+ auto moduleName = llvm::sys::path::stem (depPath);
650
+ #if !defined(_WIN32)
651
+ moduleName.consume_front (" lib" );
652
+ #endif
653
+
654
+ StringRef realDepPath =
655
+ fs::real_path (depPath, buffer, /* expand_tile*/ true )
656
+ ? StringRef (depPath)
657
+ : buffer.str ();
658
+
659
+ traceInfo.push_back (
660
+ {/* Name=*/
661
+ ctx.getIdentifier (moduleName),
662
+ /* Path=*/
663
+ realDepPath.str (),
664
+ /* IsImportedDirectly=*/
665
+ false ,
666
+ /* SupportsLibraryEvolution=*/
667
+ false });
668
+ buffer.clear ();
669
+
670
+ continue ;
671
+ }
672
+
640
673
// Skip cached modules in the prebuilt cache. We will add the corresponding
641
674
// swiftinterface from the SDK directly, but this isn't checked. :-/
642
675
//
@@ -731,8 +764,9 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
731
764
}
732
765
733
766
std::vector<SwiftModuleTraceInfo> swiftModules;
734
- computeSwiftModuleTraceInfo (abiDependencies, pathToModuleDecl, *depTracker,
735
- opts.PrebuiltModuleCachePath , swiftModules);
767
+ computeSwiftModuleTraceInfo (ctxt, abiDependencies, pathToModuleDecl,
768
+ *depTracker, opts.PrebuiltModuleCachePath ,
769
+ swiftModules);
736
770
737
771
LoadedModuleTraceFormat trace = {
738
772
/* version=*/ LoadedModuleTraceFormat::CurrentVersion,
0 commit comments