@@ -599,120 +599,6 @@ void swift::dependencies::registerCxxInteropLibraries(
599
599
}
600
600
}
601
601
602
- ModuleDependencyInfo swift::dependencies::bridgeClangModuleDependency (
603
- const ASTContext &ctx,
604
- const clang::tooling::dependencies::ModuleDeps &clangModuleDep,
605
- LookupModuleOutputCallback lookupModuleOutput, RemapPathCallback callback) {
606
- auto remapPath = [&](StringRef path) {
607
- if (callback)
608
- return callback (path);
609
- return path.str ();
610
- };
611
-
612
- // File dependencies for this module.
613
- std::vector<std::string> fileDeps;
614
- clangModuleDep.forEachFileDep (
615
- [&fileDeps](StringRef fileDep) { fileDeps.emplace_back (fileDep); });
616
-
617
- std::vector<std::string> swiftArgs;
618
- auto addClangArg = [&](Twine arg) {
619
- swiftArgs.push_back (" -Xcc" );
620
- swiftArgs.push_back (arg.str ());
621
- };
622
-
623
- // We are using Swift frontend mode.
624
- swiftArgs.push_back (" -frontend" );
625
-
626
- // Swift frontend action: -emit-pcm
627
- swiftArgs.push_back (" -emit-pcm" );
628
- swiftArgs.push_back (" -module-name" );
629
- swiftArgs.push_back (clangModuleDep.ID .ModuleName );
630
-
631
- auto pcmPath = lookupModuleOutput (
632
- clangModuleDep,
633
- clang::tooling::dependencies::ModuleOutputKind::ModuleFile);
634
- swiftArgs.push_back (" -o" );
635
- swiftArgs.push_back (pcmPath);
636
-
637
- // Ensure that the resulting PCM build invocation uses Clang frontend
638
- // directly
639
- swiftArgs.push_back (" -direct-clang-cc1-module-build" );
640
-
641
- // Swift frontend option for input file path (Foo.modulemap).
642
- swiftArgs.push_back (remapPath (clangModuleDep.ClangModuleMapFile ));
643
-
644
- auto invocation = clangModuleDep.getUnderlyingCompilerInvocation ();
645
- // Clear some options from clang scanner.
646
- invocation.getMutFrontendOpts ().ModuleCacheKeys .clear ();
647
- invocation.getMutFrontendOpts ().PathPrefixMappings .clear ();
648
- invocation.getMutFrontendOpts ().OutputFile .clear ();
649
-
650
- // Reset CASOptions since that should be coming from swift.
651
- invocation.getMutCASOpts () = clang::CASOptions ();
652
- invocation.getMutFrontendOpts ().CASIncludeTreeID .clear ();
653
-
654
- // FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
655
- // from clang scanner and pass to swift.
656
- if (!ctx.CASOpts .EnableCaching ) {
657
- auto &overlayFiles = invocation.getMutHeaderSearchOpts ().VFSOverlayFiles ;
658
- for (auto overlay : overlayFiles) {
659
- swiftArgs.push_back (" -vfsoverlay" );
660
- swiftArgs.push_back (overlay);
661
- }
662
- }
663
-
664
- // Add args reported by the scanner.
665
- auto clangArgs = invocation.getCC1CommandLine ();
666
- llvm::for_each (clangArgs, addClangArg);
667
-
668
- // CASFileSystemRootID.
669
- std::string RootID = clangModuleDep.CASFileSystemRootID
670
- ? clangModuleDep.CASFileSystemRootID ->toString ()
671
- : " " ;
672
-
673
- std::string IncludeTree =
674
- clangModuleDep.IncludeTreeID ? *clangModuleDep.IncludeTreeID : " " ;
675
-
676
- ctx.CASOpts .enumerateCASConfigurationFlags (
677
- [&](StringRef Arg) { swiftArgs.push_back (Arg.str ()); });
678
-
679
- if (!IncludeTree.empty ()) {
680
- swiftArgs.push_back (" -clang-include-tree-root" );
681
- swiftArgs.push_back (IncludeTree);
682
- }
683
- std::string mappedPCMPath = remapPath (pcmPath);
684
-
685
- std::vector<LinkLibrary> LinkLibraries;
686
- for (const auto &ll : clangModuleDep.LinkLibraries )
687
- LinkLibraries.emplace_back (ll.Library ,
688
- ll.IsFramework ? LibraryKind::Framework
689
- : LibraryKind::Library,
690
- /* static=*/ false );
691
-
692
- // Module-level dependencies.
693
- llvm::StringSet<> alreadyAddedModules;
694
- auto bridgedDependencyInfo = ModuleDependencyInfo::forClangModule (
695
- pcmPath, mappedPCMPath, clangModuleDep.ClangModuleMapFile ,
696
- clangModuleDep.ID .ContextHash , swiftArgs, fileDeps, LinkLibraries, RootID,
697
- IncludeTree, /* module-cache-key*/ " " , clangModuleDep.IsSystem );
698
-
699
- std::vector<ModuleDependencyID> directDependencyIDs;
700
- for (const auto &moduleName : clangModuleDep.ClangModuleDeps ) {
701
- // FIXME: This assumes, conservatively, that all Clang module imports
702
- // are exported. We need to fix this once the clang scanner gains the
703
- // appropriate API to query this.
704
- bridgedDependencyInfo.addModuleImport (
705
- moduleName.ModuleName , /* isExported */ true , AccessLevel::Public,
706
- &alreadyAddedModules);
707
- // It is safe to assume that all dependencies of a Clang module are Clang
708
- // modules.
709
- directDependencyIDs.push_back (
710
- {moduleName.ModuleName , ModuleDependencyKind::Clang});
711
- }
712
- bridgedDependencyInfo.setImportedClangDependencies (directDependencyIDs);
713
- return bridgedDependencyInfo;
714
- }
715
-
716
602
void
717
603
swift::dependencies::registerBackDeployLibraries (
718
604
const IRGenOptions &IRGenOpts,
@@ -895,9 +781,8 @@ void ModuleDependenciesCache::recordDependency(
895
781
896
782
void ModuleDependenciesCache::recordClangDependencies (
897
783
const clang::tooling::dependencies::ModuleDepsGraph &dependencies,
898
- const ASTContext &ctx,
899
- dependencies::LookupModuleOutputCallback lookupModuleOutput,
900
- dependencies::RemapPathCallback remapPath) {
784
+ DiagnosticEngine &diags,
785
+ BridgeClangDependencyCallback bridgeClangModule) {
901
786
for (const auto &dep : dependencies) {
902
787
auto depID =
903
788
ModuleDependencyID{dep.ID .ModuleName , ModuleDependencyKind::Clang};
@@ -917,33 +802,29 @@ void ModuleDependenciesCache::recordClangDependencies(
917
802
//
918
803
// Emit a failure diagnostic here that is hopefully more actionable
919
804
// for the time being.
920
- ctx. Diags .diagnose (SourceLoc (),
805
+ diags .diagnose (SourceLoc (),
921
806
diag::dependency_scan_unexpected_variant,
922
807
dep.ID .ModuleName );
923
- ctx. Diags .diagnose (
808
+ diags .diagnose (
924
809
SourceLoc (),
925
810
diag::dependency_scan_unexpected_variant_context_hash_note,
926
811
priorContextHash, newContextHash);
927
- ctx. Diags .diagnose (
812
+ diags .diagnose (
928
813
SourceLoc (),
929
814
diag::dependency_scan_unexpected_variant_module_map_note,
930
815
priorClangModuleDetails->moduleMapFile , dep.ClangModuleMapFile );
931
816
932
- auto newClangModuleDetails =
933
- dependencies::bridgeClangModuleDependency (
934
- ctx, dep, lookupModuleOutput, remapPath)
935
- .getAsClangModule ();
936
-
817
+ auto newClangModuleDetails = bridgeClangModule (dep).getAsClangModule ();
937
818
auto diagnoseExtraCommandLineFlags =
938
- [&ctx ](const ClangModuleDependencyStorage *checkModuleDetails,
819
+ [&diags ](const ClangModuleDependencyStorage *checkModuleDetails,
939
820
const ClangModuleDependencyStorage *baseModuleDetails,
940
821
bool isNewlyDiscovered) -> void {
941
822
std::unordered_set<std::string> baseCommandLineSet (
942
823
baseModuleDetails->buildCommandLine .begin (),
943
824
baseModuleDetails->buildCommandLine .end ());
944
825
for (const auto &checkArg : checkModuleDetails->buildCommandLine )
945
826
if (baseCommandLineSet.find (checkArg) == baseCommandLineSet.end ())
946
- ctx. Diags .diagnose (
827
+ diags .diagnose (
947
828
SourceLoc (),
948
829
diag::dependency_scan_unexpected_variant_extra_arg_note,
949
830
isNewlyDiscovered, checkArg);
@@ -954,9 +835,7 @@ void ModuleDependenciesCache::recordClangDependencies(
954
835
priorClangModuleDetails, false );
955
836
}
956
837
} else {
957
- recordDependency (dep.ID .ModuleName ,
958
- dependencies::bridgeClangModuleDependency (
959
- ctx, dep, lookupModuleOutput, remapPath));
838
+ recordDependency (dep.ID .ModuleName , bridgeClangModule (dep));
960
839
addSeenClangModule (dep.ID );
961
840
}
962
841
}
0 commit comments