@@ -217,12 +217,12 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
217
217
}
218
218
219
219
auto M = CI.getASTContext ().getModuleByName (options::ModuleName);
220
+ SmallVector<Identifier, 32 > VisibleModuleNames;
221
+ CI.getASTContext ().getVisibleTopLevelModuleNames (VisibleModuleNames);
220
222
if (!M) {
221
223
llvm::errs ()
222
224
<< " Couldn't load module '" << options::ModuleName << ' \' '
223
225
<< " in the current SDK and search paths.\n " ;
224
- SmallVector<Identifier, 32 > VisibleModuleNames;
225
- CI.getASTContext ().getVisibleTopLevelModuleNames (VisibleModuleNames);
226
226
227
227
if (VisibleModuleNames.empty ()) {
228
228
llvm::errs () << " Could not find any modules.\n " ;
@@ -241,7 +241,29 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
241
241
242
242
const auto &MainFile = M->getMainFile (FileUnitKind::SerializedAST);
243
243
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
+ }
244
267
245
- return symbolgraphgen::emitSymbolGraphForModule (M,
246
- Options);
268
+ return Success;
247
269
}
0 commit comments