21
21
#include " swift/Basic/Defer.h"
22
22
#include " swift/Basic/LLVM.h"
23
23
#include " swift/Basic/STLExtras.h"
24
- #include " swift/ClangImporter/ClangImporter.h"
25
24
#include " swift/Frontend/FrontendOptions.h"
26
25
#include " clang/Basic/Module.h"
27
26
#include " llvm/ADT/SetVector.h"
28
27
#include " llvm/ADT/StringMap.h"
29
28
#include " llvm/ADT/StringRef.h"
29
+ #include " llvm/ADT/StringSet.h"
30
30
#include " llvm/Support/FileSystem.h"
31
31
#include < set>
32
32
33
33
using namespace swift ;
34
34
35
+ // / Find all of the imported Clang modules starting with the given module name.
36
+ static void findAllImportedClangModules (ASTContext &ctx, StringRef moduleName,
37
+ ModuleDependenciesCache &cache,
38
+ std::vector<std::string> &allModules,
39
+ llvm::StringSet<> &knownModules) {
40
+ if (!knownModules.insert (moduleName).second )
41
+ return ;
42
+ allModules.push_back (moduleName);
43
+
44
+ auto dependencies = cache.findDependencies (
45
+ moduleName, ModuleDependenciesKind::Clang);
46
+ if (!dependencies)
47
+ return ;
48
+
49
+ for (const auto &dep : dependencies->getModuleDependencies ()) {
50
+ findAllImportedClangModules (ctx, dep, cache, allModules, knownModules);
51
+ }
52
+ }
53
+
35
54
// / Resolve the direct dependencies of the given module.
36
55
static std::vector<ModuleDependencyID> resolveDirectDependencies (
37
56
ASTContext &ctx, ModuleDependencyID module ,
@@ -55,7 +74,25 @@ static std::vector<ModuleDependencyID> resolveDirectDependencies(
55
74
// For a Swift module, look for overlays for each of the Clang modules it
56
75
// depends on.
57
76
if (isSwift) {
58
- // FIXME: Implement this.
77
+ // Find all of the Clang modules this Swift module depends on.
78
+ std::vector<std::string> allClangModules;
79
+ llvm::StringSet<> knownModules;
80
+ for (const auto &dep : result) {
81
+ if (dep.second != ModuleDependenciesKind::Clang)
82
+ continue ;
83
+
84
+ findAllImportedClangModules (ctx, dep.first , cache, allClangModules,
85
+ knownModules);
86
+ }
87
+
88
+ // Look for overlays for each of the Clang modules.
89
+ for (const auto &clangDep : allClangModules) {
90
+ if (auto found = ctx.getModuleDependencies (
91
+ clangDep, /* onlyClangModule=*/ false , cache)) {
92
+ if (found->getKind () == ModuleDependenciesKind::Swift)
93
+ result.push_back ({clangDep, found->getKind ()});
94
+ }
95
+ }
59
96
}
60
97
61
98
return result;
@@ -317,7 +354,7 @@ bool swift::scanDependencies(ASTContext &Context, ModuleDecl *mainModule,
317
354
writeJSON (out, Context, cache, allModules.getArrayRef ());
318
355
319
356
// This process succeeds regardless of whether any errors occurred.
320
- // FIXME: We shouldn't need this, but it's masking bugs on our scanning
357
+ // FIXME: We shouldn't need this, but it's masking bugs in our scanning
321
358
// logic where we don't create a fresh context when scanning Swift interfaces
322
359
// that includes their own command-line flags.
323
360
Context.Diags .resetHadAnyError ();
0 commit comments