@@ -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.removeDiagnosticConsumer (&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