Skip to content

Commit 3facf1f

Browse files
generate cross-import overlay symbol graphs if available
1 parent 632c9ff commit 3facf1f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tools/driver/swift_symbolgraph_extract_main.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
217217
}
218218

219219
auto M = CI.getASTContext().getModuleByName(options::ModuleName);
220+
SmallVector<Identifier, 32> VisibleModuleNames;
221+
CI.getASTContext().getVisibleTopLevelModuleNames(VisibleModuleNames);
220222
if (!M) {
221223
llvm::errs()
222224
<< "Couldn't load module '" << options::ModuleName << '\''
223225
<< " in the current SDK and search paths.\n";
224-
SmallVector<Identifier, 32> VisibleModuleNames;
225-
CI.getASTContext().getVisibleTopLevelModuleNames(VisibleModuleNames);
226226

227227
if (VisibleModuleNames.empty()) {
228228
llvm::errs() << "Could not find any modules.\n";
@@ -241,7 +241,29 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
241241

242242
const auto &MainFile = M->getMainFile(FileUnitKind::SerializedAST);
243243
llvm::errs() << "Emitting symbol graph for module file: " << MainFile.getModuleDefiningPath() << '\n';
244+
245+
int Success = symbolgraphgen::emitSymbolGraphForModule(M, Options);
246+
247+
// Look for cross-import overlays that the given module imports.
248+
249+
// Clear out the diagnostic printer before looking for cross-import overlay modules,
250+
// since some SDK modules can cause errors in the getModuleByName() call. The call
251+
// itself will properly return nullptr after this failure, so for our purposes we
252+
// don't need to print these errors.
253+
CI.getDiags().removeConsumer(DiagPrinter);
254+
255+
for (const auto &ModuleName : VisibleModuleNames) {
256+
if (ModuleName.str().startswith("_")) {
257+
auto CIM = CI.getASTContext().getModuleByName(ModuleName.str());
258+
if (CIM && CIM->isCrossImportOverlayOf(M)) {
259+
const auto &CIMainFile = CIM->getMainFile(FileUnitKind::SerializedAST);
260+
llvm::errs() << "Emitting symbol graph for cross-import overlay module file: "
261+
<< CIMainFile.getModuleDefiningPath() << '\n';
262+
263+
Success |= symbolgraphgen::emitSymbolGraphForModule(CIM, Options);
264+
}
265+
}
266+
}
244267

245-
return symbolgraphgen::emitSymbolGraphForModule(M,
246-
Options);
268+
return Success;
247269
}

0 commit comments

Comments
 (0)