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"
@@ -1573,29 +1574,32 @@ Optional<ModuleDependencies> ASTContext::getModuleDependencies(
1573
1574
bool cacheOnly) {
1574
1575
// Retrieve the dependencies for this module.
1575
1576
if (cacheOnly) {
1577
+ auto searchPathSet = getAllModuleSearchPathsSet ();
1576
1578
// Check whether we've cached this result.
1577
1579
if (!isUnderlyingClangModule) {
1578
- if (auto found = cache.findDependencies (moduleName,
1579
- ModuleDependenciesKind::SwiftTextual))
1580
+ if (auto found = cache.findDependencies (
1581
+ moduleName,
1582
+ {ModuleDependenciesKind::SwiftTextual, searchPathSet}))
1580
1583
return found;
1581
- if (auto found = cache.findDependencies (moduleName,
1582
- ModuleDependenciesKind::SwiftTextual ))
1584
+ if (auto found = cache.findDependencies (
1585
+ moduleName, { ModuleDependenciesKind::SwiftBinary, searchPathSet} ))
1583
1586
return found;
1584
- if (auto found = cache.findDependencies (moduleName,
1585
- ModuleDependenciesKind::SwiftPlaceholder))
1587
+ if (auto found = cache.findDependencies (
1588
+ moduleName,
1589
+ {ModuleDependenciesKind::SwiftPlaceholder, searchPathSet}))
1586
1590
return found;
1587
1591
}
1588
- if (auto found = cache.findDependencies (moduleName,
1589
- ModuleDependenciesKind::Clang))
1592
+ if (auto found = cache.findDependencies (
1593
+ moduleName, { ModuleDependenciesKind::Clang, searchPathSet} ))
1590
1594
return found;
1591
1595
} else {
1592
1596
for (auto &loader : getImpl ().ModuleLoaders ) {
1593
1597
if (isUnderlyingClangModule &&
1594
1598
loader.get () != getImpl ().TheClangModuleLoader )
1595
1599
continue ;
1596
1600
1597
- if (auto dependencies = loader-> getModuleDependencies (moduleName, cache,
1598
- delegate))
1601
+ if (auto dependencies =
1602
+ loader-> getModuleDependencies (moduleName, cache, delegate))
1599
1603
return dependencies;
1600
1604
}
1601
1605
}
@@ -1618,6 +1622,65 @@ ASTContext::getSwiftModuleDependencies(StringRef moduleName,
1618
1622
return None;
1619
1623
}
1620
1624
1625
+ namespace {
1626
+ static StringRef
1627
+ pathStringFromFrameworkSearchPath (const SearchPathOptions::FrameworkSearchPath &next) {
1628
+ return next.Path ;
1629
+ };
1630
+ }
1631
+
1632
+ std::vector<std::string> ASTContext::getDarwinImplicitFrameworkSearchPaths ()
1633
+ const {
1634
+ assert (LangOpts.Target .isOSDarwin ());
1635
+ SmallString<128 > systemFrameworksScratch;
1636
+ systemFrameworksScratch = SearchPathOpts.SDKPath ;
1637
+ llvm::sys::path::append (systemFrameworksScratch, " System" , " Library" , " Frameworks" );
1638
+
1639
+ SmallString<128 > frameworksScratch;
1640
+ frameworksScratch = SearchPathOpts.SDKPath ;
1641
+ llvm::sys::path::append (frameworksScratch, " Library" , " Frameworks" );
1642
+ return {systemFrameworksScratch.str ().str (), frameworksScratch.str ().str ()};
1643
+ }
1644
+
1645
+ llvm::StringSet<> ASTContext::getAllModuleSearchPathsSet ()
1646
+ const {
1647
+ llvm::StringSet<> result;
1648
+ result.insert (SearchPathOpts.ImportSearchPaths .begin (),
1649
+ SearchPathOpts.ImportSearchPaths .end ());
1650
+
1651
+ // Framework paths are "special", they contain more than path strings,
1652
+ // but path strings are all we care about here.
1653
+ using FrameworkPathView = ArrayRefView<SearchPathOptions::FrameworkSearchPath,
1654
+ StringRef,
1655
+ pathStringFromFrameworkSearchPath>;
1656
+ FrameworkPathView frameworkPathsOnly{SearchPathOpts.FrameworkSearchPaths };
1657
+ result.insert (frameworkPathsOnly.begin (), frameworkPathsOnly.end ());
1658
+
1659
+ if (LangOpts.Target .isOSDarwin ()) {
1660
+ auto implicitFrameworkSearchPaths = getDarwinImplicitFrameworkSearchPaths ();
1661
+ result.insert (implicitFrameworkSearchPaths.begin (),
1662
+ implicitFrameworkSearchPaths.end ());
1663
+ }
1664
+ result.insert (SearchPathOpts.RuntimeLibraryImportPaths .begin (),
1665
+ SearchPathOpts.RuntimeLibraryImportPaths .end ());
1666
+
1667
+ // ClangImporter special-cases the path for SwiftShims, so do the same here
1668
+ // If there are no shims in the resource dir, add a search path in the SDK.
1669
+ SmallString<128 > shimsPath (SearchPathOpts.RuntimeResourcePath );
1670
+ llvm::sys::path::append (shimsPath, " shims" );
1671
+ if (!llvm::sys::fs::exists (shimsPath)) {
1672
+ shimsPath = SearchPathOpts.SDKPath ;
1673
+ llvm::sys::path::append (shimsPath, " usr" , " lib" , " swift" , " shims" );
1674
+ }
1675
+ result.insert (shimsPath.str ());
1676
+
1677
+ // Clang system modules are found in the SDK root
1678
+ SmallString<128 > clangSysRootPath (SearchPathOpts.SDKPath );
1679
+ llvm::sys::path::append (clangSysRootPath, " usr" , " include" );
1680
+ result.insert (clangSysRootPath.str ());
1681
+ return result;
1682
+ }
1683
+
1621
1684
void ASTContext::loadExtensions (NominalTypeDecl *nominal,
1622
1685
unsigned previousGeneration) {
1623
1686
PrettyStackTraceDecl stackTrace (" loading extensions for" , nominal);
0 commit comments