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