|
21 | 21 | #include "swift/Frontend/Frontend.h" |
22 | 22 | #include "llvm/CAS/CASProvidingFileSystem.h" |
23 | 23 | #include "llvm/CAS/CachingOnDiskFileSystem.h" |
| 24 | +#include "llvm/Config/config.h" |
24 | 25 | #include "llvm/Support/FileSystem.h" |
25 | 26 | #include "llvm/Support/Path.h" |
26 | 27 | #include "llvm/Support/PrefixMapper.h" |
@@ -480,6 +481,58 @@ void SwiftDependencyTracker::addCommonSearchPathDeps( |
480 | 481 | // Add VFSOverlay file. |
481 | 482 | for (auto &Overlay: Opts.VFSOverlayFiles) |
482 | 483 | FS->status(Overlay); |
| 484 | + |
| 485 | + // Add plugin dylibs from the toolchain only by look through the plugin search |
| 486 | + // directory. |
| 487 | + auto recordFiles = [&](StringRef Path) { |
| 488 | + std::error_code EC; |
| 489 | + for (auto I = FS->dir_begin(Path, EC); |
| 490 | + !EC && I != llvm::vfs::directory_iterator(); I = I.increment(EC)) { |
| 491 | + if (I->type() != llvm::sys::fs::file_type::regular_file) |
| 492 | + continue; |
| 493 | +#if defined(_WIN32) |
| 494 | + constexpr StringRef libPrefix{}; |
| 495 | + constexpr StringRef libSuffix = ".dll"; |
| 496 | +#else |
| 497 | + constexpr StringRef libPrefix = "lib"; |
| 498 | + constexpr StringRef libSuffix = LTDL_SHLIB_EXT; |
| 499 | +#endif |
| 500 | + StringRef filename = llvm::sys::path::filename(I->path()); |
| 501 | + if (filename.starts_with(libPrefix) && filename.ends_with(libSuffix)) |
| 502 | + FS->status(I->path()); |
| 503 | + } |
| 504 | + }; |
| 505 | + for (auto &entry : Opts.PluginSearchOpts) { |
| 506 | + switch (entry.getKind()) { |
| 507 | + |
| 508 | + // '-load-plugin-library <library path>'. |
| 509 | + case PluginSearchOption::Kind::LoadPluginLibrary: { |
| 510 | + auto &val = entry.get<PluginSearchOption::LoadPluginLibrary>(); |
| 511 | + FS->status(val.LibraryPath); |
| 512 | + break; |
| 513 | + } |
| 514 | + |
| 515 | + // '-load-plugin-executable <executable path>#<module name>, ...'. |
| 516 | + case PluginSearchOption::Kind::LoadPluginExecutable: { |
| 517 | + // We don't have executable plugin in toolchain. |
| 518 | + break; |
| 519 | + } |
| 520 | + |
| 521 | + // '-plugin-path <library search path>'. |
| 522 | + case PluginSearchOption::Kind::PluginPath: { |
| 523 | + auto &val = entry.get<PluginSearchOption::PluginPath>(); |
| 524 | + recordFiles(val.SearchPath); |
| 525 | + break; |
| 526 | + } |
| 527 | + |
| 528 | + // '-external-plugin-path <library search path>#<server path>'. |
| 529 | + case PluginSearchOption::Kind::ExternalPluginPath: { |
| 530 | + auto &val = entry.get<PluginSearchOption::ExternalPluginPath>(); |
| 531 | + recordFiles(val.SearchPath); |
| 532 | + break; |
| 533 | + } |
| 534 | + } |
| 535 | + } |
483 | 536 | } |
484 | 537 |
|
485 | 538 | void SwiftDependencyTracker::startTracking() { |
@@ -739,6 +792,13 @@ ModuleDependenciesCache::findDependency(StringRef moduleName) const { |
739 | 792 | return std::nullopt; |
740 | 793 | } |
741 | 794 |
|
| 795 | +const ModuleDependencyInfo &ModuleDependenciesCache::findKnownDependency( |
| 796 | + const ModuleDependencyID &moduleID) const { |
| 797 | + auto dep = findDependency(moduleID); |
| 798 | + assert(dep && "dependency unknown"); |
| 799 | + return **dep; |
| 800 | +} |
| 801 | + |
742 | 802 | bool ModuleDependenciesCache::hasDependency(const ModuleDependencyID &moduleID) const { |
743 | 803 | return hasDependency(moduleID.ModuleName, moduleID.Kind); |
744 | 804 | } |
|
0 commit comments