@@ -22,35 +22,13 @@ using namespace tooling;
22
22
using namespace dependencies ;
23
23
using llvm::Error;
24
24
25
- static std::vector<std::string>
26
- makeTUCommandLineWithoutPaths (ArrayRef<std::string> OriginalCommandLine) {
27
- std::vector<std::string> Args = OriginalCommandLine;
28
-
29
- Args.push_back (" -fno-implicit-modules" );
30
- Args.push_back (" -fno-implicit-module-maps" );
31
-
32
- // These arguments are unused in explicit compiles.
33
- llvm::erase_if (Args, [](StringRef Arg) {
34
- if (Arg.consume_front (" -fmodules-" )) {
35
- return Arg.startswith (" cache-path=" ) ||
36
- Arg.startswith (" prune-interval=" ) ||
37
- Arg.startswith (" prune-after=" ) ||
38
- Arg == " validate-once-per-build-session" ;
39
- }
40
- return Arg.startswith (" -fbuild-session-file=" );
41
- });
42
-
43
- return Args;
44
- }
45
-
46
25
DependencyScanningTool::DependencyScanningTool (
47
26
DependencyScanningService &Service,
48
27
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
49
28
: Worker(Service, std::move(FS)) {}
50
29
51
30
llvm::Expected<std::string> DependencyScanningTool::getDependencyFile (
52
- const std::vector<std::string> &CommandLine, StringRef CWD,
53
- llvm::Optional<StringRef> ModuleName) {
31
+ const std::vector<std::string> &CommandLine, StringRef CWD) {
54
32
// / Prints out all of the gathered dependencies into a string.
55
33
class MakeDependencyPrinterConsumer : public DependencyConsumer {
56
34
public:
@@ -111,8 +89,7 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
111
89
};
112
90
113
91
MakeDependencyPrinterConsumer Consumer;
114
- auto Result =
115
- Worker.computeDependencies (CWD, CommandLine, Consumer, ModuleName);
92
+ auto Result = Worker.computeDependencies (CWD, CommandLine, Consumer);
116
93
if (Result)
117
94
return std::move (Result);
118
95
std::string Output;
@@ -144,8 +121,8 @@ class GetDependencyTree : public FullDependencyConsumer {
144
121
145
122
GetDependencyTree (llvm::cas::CachingOnDiskFileSystem &FS,
146
123
DepscanPrefixMapping PrefixMapping)
147
- : FullDependencyConsumer(AlreadySeen, nullptr , /* EagerModules= */ false ,
148
- &FS, std::move(PrefixMapping)),
124
+ : FullDependencyConsumer(AlreadySeen, nullptr , &FS ,
125
+ std::move (PrefixMapping)),
149
126
FS(FS) {}
150
127
151
128
private:
@@ -560,36 +537,32 @@ DependencyScanningTool::getIncludeTreeFromCompilerInvocation(
560
537
return Consumer.getIncludeTree ();
561
538
}
562
539
563
- llvm::Expected<FullDependenciesResult >
564
- DependencyScanningTool::getFullDependencies (
540
+ llvm::Expected<TranslationUnitDeps >
541
+ DependencyScanningTool::getTranslationUnitDependencies (
565
542
const std::vector<std::string> &CommandLine, StringRef CWD,
566
543
const llvm::StringSet<> &AlreadySeen,
567
544
LookupModuleOutputCallback LookupModuleOutput,
568
- llvm::Optional<StringRef> ModuleName, DepscanPrefixMapping PrefixMapping) {
545
+ DepscanPrefixMapping PrefixMapping) {
569
546
FullDependencyConsumer Consumer (AlreadySeen, LookupModuleOutput,
570
- Worker.shouldEagerLoadModules (),
571
547
Worker.getCASFS (), std::move (PrefixMapping));
572
- llvm::Error Result =
573
- Worker.computeDependencies (CWD, CommandLine, Consumer, ModuleName);
548
+ llvm::Error Result = Worker.computeDependencies (CWD, CommandLine, Consumer);
574
549
if (Result)
575
550
return std::move (Result);
576
- return Consumer.takeFullDependencies ();
551
+ return Consumer.takeTranslationUnitDeps ();
577
552
}
578
553
579
- llvm::Expected<FullDependenciesResult>
580
- DependencyScanningTool::getFullDependenciesLegacyDriverCommand (
581
- const std::vector<std::string> &CommandLine, StringRef CWD,
582
- const llvm::StringSet<> &AlreadySeen,
554
+ llvm::Expected<ModuleDepsGraph> DependencyScanningTool::getModuleDependencies (
555
+ StringRef ModuleName, const std::vector<std::string> &CommandLine,
556
+ StringRef CWD, const llvm::StringSet<> &AlreadySeen,
583
557
LookupModuleOutputCallback LookupModuleOutput,
584
- llvm::Optional<StringRef> ModuleName ) {
558
+ DepscanPrefixMapping PrefixMapping ) {
585
559
FullDependencyConsumer Consumer (AlreadySeen, LookupModuleOutput,
586
- Worker.shouldEagerLoadModules (),
587
- Worker.getCASFS ());
560
+ Worker.getCASFS (), std::move (PrefixMapping));
588
561
llvm::Error Result =
589
562
Worker.computeDependencies (CWD, CommandLine, Consumer, ModuleName);
590
563
if (Result)
591
564
return std::move (Result);
592
- return Consumer.getFullDependenciesLegacyDriverCommand (CommandLine );
565
+ return Consumer.takeModuleGraphDeps ( );
593
566
}
594
567
595
568
Error FullDependencyConsumer::initialize (CompilerInstance &ScanInstance,
@@ -733,75 +706,40 @@ Error FullDependencyConsumer::finalizeModuleInvocation(CompilerInvocation &CI,
733
706
return llvm::Error::success ();
734
707
}
735
708
736
- FullDependenciesResult FullDependencyConsumer::takeFullDependencies () {
737
- FullDependenciesResult FDR;
738
- FullDependencies &FD = FDR.FullDeps ;
709
+ TranslationUnitDeps FullDependencyConsumer::takeTranslationUnitDeps () {
710
+ TranslationUnitDeps TU;
739
711
740
- FD .ID .ContextHash = std::move (ContextHash);
741
- FD .FileDeps = std::move (Dependencies);
742
- FD .PrebuiltModuleDeps = std::move (PrebuiltModuleDeps);
743
- FD .Commands = std::move (Commands);
744
- FD .CASFileSystemRootID = CASFileSystemRootID;
712
+ TU .ID .ContextHash = std::move (ContextHash);
713
+ TU .FileDeps = std::move (Dependencies);
714
+ TU .PrebuiltModuleDeps = std::move (PrebuiltModuleDeps);
715
+ TU .Commands = std::move (Commands);
716
+ TU .CASFileSystemRootID = CASFileSystemRootID;
745
717
746
718
for (auto &&M : ClangModuleDeps) {
747
719
auto &MD = M.second ;
748
720
if (MD.ImportedByMainFile )
749
- FD .ClangModuleDeps .push_back (MD.ID );
721
+ TU .ClangModuleDeps .push_back (MD.ID );
750
722
// TODO: Avoid handleModuleDependency even being called for modules
751
723
// we've already seen.
752
724
if (AlreadySeen.count (M.first ))
753
725
continue ;
754
- FDR. DiscoveredModules .push_back (std::move (MD));
726
+ TU. ModuleGraph .push_back (std::move (MD));
755
727
}
756
728
757
- return FDR ;
729
+ return TU ;
758
730
}
759
731
760
- FullDependenciesResult
761
- FullDependencyConsumer::getFullDependenciesLegacyDriverCommand (
762
- const std::vector<std::string> &OriginalCommandLine) const {
763
- FullDependencies FD;
764
-
765
- FD.DriverCommandLine = makeTUCommandLineWithoutPaths (
766
- ArrayRef<std::string>(OriginalCommandLine).slice (1 ));
767
-
768
- FD.ID .ContextHash = std::move (ContextHash);
769
-
770
- FD.FileDeps .assign (Dependencies.begin (), Dependencies.end ());
771
-
772
- for (const PrebuiltModuleDep &PMD : PrebuiltModuleDeps)
773
- FD.DriverCommandLine .push_back (" -fmodule-file=" + PMD.PCMFile );
732
+ ModuleDepsGraph FullDependencyConsumer::takeModuleGraphDeps () {
733
+ ModuleDepsGraph ModuleGraph;
774
734
775
735
for (auto &&M : ClangModuleDeps) {
776
736
auto &MD = M.second ;
777
- if (MD.ImportedByMainFile ) {
778
- FD.ClangModuleDeps .push_back (MD.ID );
779
- auto PCMPath = LookupModuleOutput (MD.ID , ModuleOutputKind::ModuleFile);
780
- if (EagerLoadModules) {
781
- FD.DriverCommandLine .push_back (" -fmodule-file=" + PCMPath);
782
- } else {
783
- FD.DriverCommandLine .push_back (" -fmodule-map-file=" +
784
- MD.ClangModuleMapFile );
785
- FD.DriverCommandLine .push_back (" -fmodule-file=" + MD.ID .ModuleName +
786
- " =" + PCMPath);
787
- }
788
- }
789
- }
790
-
791
- FD.PrebuiltModuleDeps = std::move (PrebuiltModuleDeps);
792
-
793
- FD.CASFileSystemRootID = CASFileSystemRootID;
794
-
795
- FullDependenciesResult FDR;
796
-
797
- for (auto &&M : ClangModuleDeps) {
798
737
// TODO: Avoid handleModuleDependency even being called for modules
799
738
// we've already seen.
800
739
if (AlreadySeen.count (M.first ))
801
740
continue ;
802
- FDR. DiscoveredModules . push_back (std::move (M. second ));
741
+ ModuleGraph. push_back (std::move (MD ));
803
742
}
804
743
805
- FDR.FullDeps = std::move (FD);
806
- return FDR;
744
+ return ModuleGraph;
807
745
}
0 commit comments