@@ -187,6 +187,82 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
187
187
std::vector<std::pair<std::string, MacroPluginDependency>> macroDependencies;
188
188
std::vector<std::string> auxiliaryFiles;
189
189
190
+ auto addCommonDependencyInfo =
191
+ [¤tModuleImports,
192
+ ¤tOptionalModuleImports,
193
+ &importedClangDependenciesIDs,
194
+ &auxiliaryFiles,
195
+ ¯oDependencies] (ModuleDependencyInfo &moduleDep) {
196
+ // Add imports of this module
197
+ for (const auto &moduleName : currentModuleImports)
198
+ moduleDep.addModuleImport (moduleName.importIdentifier );
199
+ // Add optional imports of this module
200
+ for (const auto &moduleName : currentOptionalModuleImports)
201
+ moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
202
+
203
+ // Add qualified dependencies of this module
204
+ moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
205
+
206
+ // Add any auxiliary files
207
+ moduleDep.setAuxiliaryFiles (auxiliaryFiles);
208
+
209
+ // Add macro dependencies
210
+ for (const auto &md: macroDependencies)
211
+ moduleDep.addMacroDependency (md.first ,
212
+ md.second .LibraryPath ,
213
+ md.second .ExecutablePath );
214
+
215
+ moduleDep.setIsFinalized (true );
216
+ };
217
+
218
+ auto addSwiftTextualDependencyInfo =
219
+ [this ,
220
+ &importedSwiftDependenciesIDs,
221
+ &crossImportOverlayDependenciesIDs,
222
+ &swiftOverlayDependenciesIDs] (ModuleDependencyInfo &moduleDep,
223
+ unsigned bridgingHeaderFileID,
224
+ unsigned bridgingSourceFilesArrayID,
225
+ unsigned bridgingModuleDependenciesArrayID,
226
+ unsigned bridgingHeaderIncludeTreeID) {
227
+
228
+ moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
229
+ moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
230
+ moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
231
+
232
+ // Add bridging header file path
233
+ if (bridgingHeaderFileID != 0 ) {
234
+ auto bridgingHeaderFile = getIdentifier (bridgingHeaderFileID);
235
+ if (!bridgingHeaderFile)
236
+ llvm::report_fatal_error (" Bad bridging header path" );
237
+
238
+ moduleDep.addBridgingHeader (*bridgingHeaderFile);
239
+ }
240
+
241
+ // Add bridging source files
242
+ auto bridgingSourceFiles = getStringArray (bridgingSourceFilesArrayID);
243
+ if (!bridgingSourceFiles)
244
+ llvm::report_fatal_error (" Bad bridging source files" );
245
+ for (const auto &file : *bridgingSourceFiles)
246
+ moduleDep.addHeaderSourceFile (file);
247
+
248
+ // Add bridging module dependencies
249
+ auto bridgingModuleDeps = getStringArray (bridgingModuleDependenciesArrayID);
250
+ if (!bridgingModuleDeps)
251
+ llvm::report_fatal_error (" Bad bridging module dependencies" );
252
+ llvm::StringSet<> alreadyAdded;
253
+ std::vector<ModuleDependencyID> bridgingModuleDepIDs;
254
+ for (const auto &mod : bridgingModuleDeps.value ())
255
+ bridgingModuleDepIDs.push_back (ModuleDependencyID{mod, ModuleDependencyKind::Clang});
256
+ moduleDep.setHeaderClangDependencies (bridgingModuleDepIDs);
257
+
258
+ // Add bridging header include tree
259
+ auto bridgingHeaderIncludeTree = getIdentifier (bridgingHeaderIncludeTreeID);
260
+ if (!bridgingHeaderIncludeTree)
261
+ llvm::report_fatal_error (" Bad bridging header include tree" );
262
+ if (!bridgingHeaderIncludeTree->empty ())
263
+ moduleDep.addBridgingHeaderIncludeTree (*bridgingHeaderIncludeTree);
264
+ };
265
+
190
266
while (!Cursor.AtEndOfStream ()) {
191
267
auto entry = cantFail (Cursor.advance (), " Advance bitstream cursor" );
192
268
@@ -307,9 +383,10 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
307
383
if (!moduleName)
308
384
llvm::report_fatal_error (" Bad module name" );
309
385
currentModuleName = *moduleName;
386
+
387
+ // ACTODO: Proper import infos.
310
388
auto importStrings = getStringArray (moduleImportsArrayID);
311
389
auto optionalImportStrings = getStringArray (optionalModuleImportsArrayID);
312
- // ACTODO: Proper import infos.
313
390
currentModuleImports.clear ();
314
391
currentOptionalModuleImports.clear ();
315
392
if (importStrings.has_value ())
@@ -420,76 +497,19 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
420
497
if (!userModuleVersion)
421
498
llvm::report_fatal_error (" Bad userModuleVersion" );
422
499
423
- // TODO: MacroDependencies
424
500
// Form the dependencies storage object
425
501
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule (
426
502
outputModulePath.value (), optionalSwiftInterfaceFile.value (),
427
503
compiledCandidatesRefs, buildCommandRefs, linkLibraries, extraPCMRefs,
428
504
*contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey,
429
505
*userModuleVersion);
430
506
431
- // Add imports of this module
432
- for (const auto &moduleName : currentModuleImports)
433
- moduleDep.addModuleImport (moduleName.importIdentifier );
434
- // Add optional imports of this module
435
- for (const auto &moduleName : currentOptionalModuleImports)
436
- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
437
-
438
- // Add qualified dependencies of this module
439
- moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
440
- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
441
- moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
442
- moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
443
- moduleDep.setAuxiliaryFiles (auxiliaryFiles);
444
-
445
- // Add bridging header file path
446
- if (bridgingHeaderFileID != 0 ) {
447
- auto bridgingHeaderFile = getIdentifier (bridgingHeaderFileID);
448
- if (!bridgingHeaderFile)
449
- llvm::report_fatal_error (" Bad bridging header path" );
450
-
451
- moduleDep.addBridgingHeader (*bridgingHeaderFile);
452
- }
453
-
454
- // Add bridging source files
455
- auto bridgingSourceFiles = getStringArray (bridgingSourceFilesArrayID);
456
- if (!bridgingSourceFiles)
457
- llvm::report_fatal_error (" Bad bridging source files" );
458
- for (const auto &file : *bridgingSourceFiles)
459
- moduleDep.addHeaderSourceFile (file);
460
-
461
- // Add source files
462
- auto sourceFiles = getStringArray (sourceFilesArrayID);
463
- if (!sourceFiles)
464
- llvm::report_fatal_error (" Bad bridging source files" );
465
- for (const auto &file : *sourceFiles)
466
- moduleDep.addSourceFile (file);
507
+ addCommonDependencyInfo (moduleDep);
508
+ addSwiftTextualDependencyInfo (moduleDep, bridgingHeaderFileID,
509
+ bridgingSourceFilesArrayID,
510
+ bridgingModuleDependenciesArrayID,
511
+ bridgingHeaderIncludeTreeID);
467
512
468
- // Add bridging module dependencies
469
- auto bridgingModuleDeps = getStringArray (bridgingModuleDependenciesArrayID);
470
- if (!bridgingModuleDeps)
471
- llvm::report_fatal_error (" Bad bridging module dependencies" );
472
- llvm::StringSet<> alreadyAdded;
473
- std::vector<ModuleDependencyID> bridgingModuleDepIDs;
474
- for (const auto &mod : bridgingModuleDeps.value ())
475
- bridgingModuleDepIDs.push_back (ModuleDependencyID{mod, ModuleDependencyKind::Clang});
476
- moduleDep.setHeaderClangDependencies (bridgingModuleDepIDs);
477
-
478
- // Add bridging header include tree
479
- auto bridgingHeaderIncludeTree =
480
- getIdentifier (bridgingHeaderIncludeTreeID);
481
- if (!bridgingHeaderIncludeTree)
482
- llvm::report_fatal_error (" Bad bridging header include tree" );
483
- if (!bridgingHeaderIncludeTree->empty ())
484
- moduleDep.addBridgingHeaderIncludeTree (*bridgingHeaderIncludeTree);
485
-
486
- // Add macro dependencies
487
- for (const auto &md: macroDependencies)
488
- moduleDep.addMacroDependency (md.first ,
489
- md.second .LibraryPath ,
490
- md.second .ExecutablePath );
491
-
492
- moduleDep.setIsFinalized (true );
493
513
cache.recordDependency (currentModuleName, std::move (moduleDep));
494
514
hasCurrentModule = false ;
495
515
break ;
@@ -540,68 +560,19 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
540
560
*rootFileSystemID, buildCommandRefs, bridgingHeaderBuildCommandRefs,
541
561
extraPCMRefs);
542
562
543
- // Add imports of this module
544
- for (const auto &moduleName : currentModuleImports)
545
- moduleDep.addModuleImport (moduleName.importIdentifier );
546
- // Add optional imports of this module
547
- for (const auto &moduleName : currentOptionalModuleImports)
548
- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
549
-
550
- // Add qualified dependencies of this module
551
- moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
552
- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
553
- moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
554
- moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
555
-
556
- // Add bridging header file path
557
- if (bridgingHeaderFileID != 0 ) {
558
- auto bridgingHeaderFile = getIdentifier (bridgingHeaderFileID);
559
- if (!bridgingHeaderFile)
560
- llvm::report_fatal_error (" Bad bridging header path" );
561
-
562
- moduleDep.addBridgingHeader (*bridgingHeaderFile);
563
- }
564
-
565
- // Add bridging source files
566
- auto bridgingSourceFiles = getStringArray (bridgingSourceFilesArrayID);
567
- if (!bridgingSourceFiles)
568
- llvm::report_fatal_error (" Bad bridging source files" );
569
- for (const auto &file : *bridgingSourceFiles)
570
- moduleDep.addHeaderSourceFile (file);
571
-
572
563
// Add source files
573
564
auto sourceFiles = getStringArray (sourceFilesArrayID);
574
565
if (!sourceFiles)
575
566
llvm::report_fatal_error (" Bad bridging source files" );
576
567
for (const auto &file : *sourceFiles)
577
568
moduleDep.addSourceFile (file);
578
569
579
- // Add bridging module dependencies
580
- auto bridgingModuleDeps = getStringArray (bridgingModuleDependenciesArrayID);
581
- if (!bridgingModuleDeps)
582
- llvm::report_fatal_error ( " Bad bridging module dependencies " );
583
- llvm::StringSet<> alreadyAdded ;
570
+ addCommonDependencyInfo (moduleDep);
571
+ addSwiftTextualDependencyInfo (moduleDep, bridgingHeaderFileID,
572
+ bridgingSourceFilesArrayID,
573
+ bridgingModuleDependenciesArrayID,
574
+ bridgingHeaderIncludeTreeID) ;
584
575
585
- std::vector<ModuleDependencyID> headerDependencyIDs;
586
- for (const auto &mod : *bridgingModuleDeps)
587
- headerDependencyIDs.push_back ({mod, ModuleDependencyKind::Clang});
588
- moduleDep.setHeaderClangDependencies (headerDependencyIDs);
589
-
590
- // Add bridging header include tree
591
- auto bridgingHeaderIncludeTree =
592
- getIdentifier (bridgingHeaderIncludeTreeID);
593
- if (!bridgingHeaderIncludeTree)
594
- llvm::report_fatal_error (" Bad bridging header include tree" );
595
- if (!bridgingHeaderIncludeTree->empty ())
596
- moduleDep.addBridgingHeaderIncludeTree (*bridgingHeaderIncludeTree);
597
-
598
- // Add macro dependencies
599
- for (const auto &md: macroDependencies)
600
- moduleDep.addMacroDependency (md.first ,
601
- md.second .LibraryPath ,
602
- md.second .ExecutablePath );
603
-
604
- moduleDep.setIsFinalized (true );
605
576
cache.recordDependency (currentModuleName, std::move (moduleDep));
606
577
hasCurrentModule = false ;
607
578
break ;
@@ -651,18 +622,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
651
622
*headerImport, *definingInterfacePath, isFramework, isStatic,
652
623
*moduleCacheKey, *userModuleVersion);
653
624
654
- // Add imports of this module
655
- for (const auto &moduleName : currentModuleImports)
656
- moduleDep.addModuleImport (moduleName.importIdentifier );
657
- // Add optional imports of this module
658
- for (const auto &moduleName : currentOptionalModuleImports)
659
- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
660
-
661
- // Add qualified dependencies of this module
662
- moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
663
- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
664
- moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
665
- moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
625
+ addCommonDependencyInfo (moduleDep);
666
626
667
627
auto headerModuleDependencies = getStringArray (headerModuleDependenciesArrayID);
668
628
if (!headerModuleDependencies)
@@ -682,13 +642,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
682
642
for (const auto &depSource : *headerImportsSourceFiles)
683
643
moduleDep.addHeaderSourceFile (depSource);
684
644
685
- // Add macro dependencies
686
- for (const auto &md: macroDependencies)
687
- moduleDep.addMacroDependency (md.first ,
688
- md.second .LibraryPath ,
689
- md.second .ExecutablePath );
690
-
691
- moduleDep.setIsFinalized (true );
692
645
cache.recordDependency (currentModuleName, std::move (moduleDep));
693
646
hasCurrentModule = false ;
694
647
break ;
@@ -717,14 +670,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
717
670
auto moduleDep = ModuleDependencyInfo::forPlaceholderSwiftModuleStub (
718
671
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath);
719
672
720
-
721
- // Add dependencies of this module
722
- for (const auto &moduleName : currentModuleImports)
723
- moduleDep.addModuleImport (moduleName.importIdentifier );
724
- // Add optional imports of this module
725
- for (const auto &moduleName : currentOptionalModuleImports)
726
- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
727
-
728
673
cache.recordDependency (currentModuleName, std::move (moduleDep));
729
674
hasCurrentModule = false ;
730
675
break ;
@@ -777,20 +722,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
777
722
*pcmOutputPath, *mappedPCMPath, *moduleMapPath, *contextHash,
778
723
*commandLineArgs, *fileDependencies, *capturedPCMArgs, linkLibraries,
779
724
*rootFileSystemID, *clangIncludeTreeRoot, *moduleCacheKey, isSystem);
725
+ addCommonDependencyInfo (moduleDep);
780
726
781
- // Add imports of this module
782
- for (const auto &moduleName : currentModuleImports)
783
- moduleDep.addModuleImport (moduleName.importIdentifier );
784
- // Add qualified dependencies of this module
785
- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
786
-
787
- // Add macro dependencies
788
- for (const auto &md: macroDependencies)
789
- moduleDep.addMacroDependency (md.first ,
790
- md.second .LibraryPath ,
791
- md.second .ExecutablePath );
792
-
793
- moduleDep.setIsFinalized (true );
794
727
cache.recordDependency (currentModuleName, std::move (moduleDep));
795
728
hasCurrentModule = false ;
796
729
break ;
0 commit comments