41
41
#include " swift/AST/PropertyWrappers.h"
42
42
#include " swift/AST/ProtocolConformance.h"
43
43
#include " swift/AST/RawComment.h"
44
+ #include " swift/AST/SearchPathOptions.h"
44
45
#include " swift/AST/SILLayout.h"
45
46
#include " swift/AST/SemanticAttrs.h"
46
47
#include " swift/AST/SourceFile.h"
@@ -1645,29 +1646,32 @@ Optional<ModuleDependencies> ASTContext::getModuleDependencies(
1645
1646
bool cacheOnly) {
1646
1647
// Retrieve the dependencies for this module.
1647
1648
if (cacheOnly) {
1649
+ auto searchPathSet = getAllModuleSearchPathsSet ();
1648
1650
// Check whether we've cached this result.
1649
1651
if (!isUnderlyingClangModule) {
1650
- if (auto found = cache.findDependencies (moduleName,
1651
- ModuleDependenciesKind::SwiftTextual))
1652
+ if (auto found = cache.findDependencies (
1653
+ moduleName,
1654
+ {ModuleDependenciesKind::SwiftTextual, searchPathSet}))
1652
1655
return found;
1653
- if (auto found = cache.findDependencies (moduleName,
1654
- ModuleDependenciesKind::SwiftTextual ))
1656
+ if (auto found = cache.findDependencies (
1657
+ moduleName, { ModuleDependenciesKind::SwiftBinary, searchPathSet} ))
1655
1658
return found;
1656
- if (auto found = cache.findDependencies (moduleName,
1657
- ModuleDependenciesKind::SwiftPlaceholder))
1659
+ if (auto found = cache.findDependencies (
1660
+ moduleName,
1661
+ {ModuleDependenciesKind::SwiftPlaceholder, searchPathSet}))
1658
1662
return found;
1659
1663
}
1660
- if (auto found = cache.findDependencies (moduleName,
1661
- ModuleDependenciesKind::Clang))
1664
+ if (auto found = cache.findDependencies (
1665
+ moduleName, { ModuleDependenciesKind::Clang, searchPathSet} ))
1662
1666
return found;
1663
1667
} else {
1664
1668
for (auto &loader : getImpl ().ModuleLoaders ) {
1665
1669
if (isUnderlyingClangModule &&
1666
1670
loader.get () != getImpl ().TheClangModuleLoader )
1667
1671
continue ;
1668
1672
1669
- if (auto dependencies = loader-> getModuleDependencies (moduleName, cache,
1670
- delegate))
1673
+ if (auto dependencies =
1674
+ loader-> getModuleDependencies (moduleName, cache, delegate))
1671
1675
return dependencies;
1672
1676
}
1673
1677
}
@@ -1690,6 +1694,65 @@ ASTContext::getSwiftModuleDependencies(StringRef moduleName,
1690
1694
return None;
1691
1695
}
1692
1696
1697
+ namespace {
1698
+ static StringRef
1699
+ pathStringFromFrameworkSearchPath (const SearchPathOptions::FrameworkSearchPath &next) {
1700
+ return next.Path ;
1701
+ };
1702
+ }
1703
+
1704
+ std::vector<std::string> ASTContext::getDarwinImplicitFrameworkSearchPaths ()
1705
+ const {
1706
+ assert (LangOpts.Target .isOSDarwin ());
1707
+ SmallString<128 > systemFrameworksScratch;
1708
+ systemFrameworksScratch = SearchPathOpts.SDKPath ;
1709
+ llvm::sys::path::append (systemFrameworksScratch, " System" , " Library" , " Frameworks" );
1710
+
1711
+ SmallString<128 > frameworksScratch;
1712
+ frameworksScratch = SearchPathOpts.SDKPath ;
1713
+ llvm::sys::path::append (frameworksScratch, " Library" , " Frameworks" );
1714
+ return {systemFrameworksScratch.str ().str (), frameworksScratch.str ().str ()};
1715
+ }
1716
+
1717
+ llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet ()
1718
+ const {
1719
+ llvm::StringSet<> result;
1720
+ result.insert (SearchPathOpts.ImportSearchPaths .begin (),
1721
+ SearchPathOpts.ImportSearchPaths .end ());
1722
+
1723
+ // Framework paths are "special", they contain more than path strings,
1724
+ // but path strings are all we care about here.
1725
+ using FrameworkPathView = ArrayRefView<SearchPathOptions::FrameworkSearchPath,
1726
+ StringRef,
1727
+ pathStringFromFrameworkSearchPath>;
1728
+ FrameworkPathView frameworkPathsOnly{SearchPathOpts.FrameworkSearchPaths };
1729
+ result.insert (frameworkPathsOnly.begin (), frameworkPathsOnly.end ());
1730
+
1731
+ if (LangOpts.Target .isOSDarwin ()) {
1732
+ auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths ();
1733
+ result.insert (implicitFrameworkSearchPaths.begin (),
1734
+ implicitFrameworkSearchPaths.end ());
1735
+ }
1736
+ result.insert (SearchPathOpts.RuntimeLibraryImportPaths .begin (),
1737
+ SearchPathOpts.RuntimeLibraryImportPaths .end ());
1738
+
1739
+ // ClangImporter special-cases the path for SwiftShims, so do the same here
1740
+ // If there are no shims in the resource dir, add a search path in the SDK.
1741
+ SmallString<128 > shimsPath (SearchPathOpts.RuntimeResourcePath );
1742
+ llvm::sys::path::append (shimsPath, " shims" );
1743
+ if (!llvm::sys::fs::exists (shimsPath)) {
1744
+ shimsPath = SearchPathOpts.SDKPath ;
1745
+ llvm::sys::path::append (shimsPath, " usr" , " lib" , " swift" , " shims" );
1746
+ }
1747
+ result.insert (shimsPath.str ());
1748
+
1749
+ // Clang system modules are found in the SDK root
1750
+ SmallString<128 > clangSysRootPath (SearchPathOpts.SDKPath );
1751
+ llvm::sys::path::append (clangSysRootPath, " usr" , " include" );
1752
+ result.insert (clangSysRootPath.str ());
1753
+ return result;
1754
+ }
1755
+
1693
1756
void ASTContext::loadExtensions (NominalTypeDecl *nominal,
1694
1757
unsigned previousGeneration) {
1695
1758
PrettyStackTraceDecl stackTrace (" loading extensions for" , nominal);
0 commit comments