@@ -287,10 +287,11 @@ class DependencyScanningAction : public tooling::ToolAction {
287287 DependencyScanningService &Service, StringRef WorkingDirectory,
288288 DependencyConsumer &Consumer, DependencyActionController &Controller,
289289 llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
290- bool DisableFree, std::optional<StringRef> ModuleName = std::nullopt )
290+ bool DisableFree,
291+ std::optional<ArrayRef<StringRef>> ModuleNames = std::nullopt )
291292 : Service(Service), WorkingDirectory(WorkingDirectory),
292293 Consumer (Consumer), Controller(Controller), DepFS(std::move(DepFS)),
293- DisableFree(DisableFree), ModuleName(ModuleName ) {}
294+ DisableFree(DisableFree), ModuleNames(ModuleNames ) {}
294295
295296 bool runInvocation (std::shared_ptr<CompilerInvocation> Invocation,
296297 FileManager *DriverFileMgr,
@@ -431,8 +432,9 @@ class DependencyScanningAction : public tooling::ToolAction {
431432
432433 if (Service.getFormat () == ScanningOutputFormat::P1689)
433434 Action = std::make_unique<PreprocessOnlyAction>();
434- else if (ModuleName)
435- Action = std::make_unique<GetDependenciesByModuleNameAction>(*ModuleName);
435+ else if (ModuleNames)
436+ Action =
437+ std::make_unique<GetDependenciesByModuleNameAction>(*ModuleNames);
436438 else
437439 Action = std::make_unique<ReadPCHAndPreprocessAction>();
438440
@@ -478,7 +480,7 @@ class DependencyScanningAction : public tooling::ToolAction {
478480 DependencyActionController &Controller;
479481 llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
480482 bool DisableFree;
481- std::optional<StringRef> ModuleName ;
483+ std::optional<ArrayRef< StringRef>> ModuleNames ;
482484 std::optional<CompilerInstance> ScanInstanceStorage;
483485 std::shared_ptr<ModuleDepCollector> MDC;
484486 std::vector<std::string> LastCC1Arguments;
@@ -546,7 +548,7 @@ llvm::Error DependencyScanningWorker::computeDependencies(
546548llvm::Error DependencyScanningWorker::computeDependencies (
547549 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
548550 DependencyConsumer &Consumer, DependencyActionController &Controller,
549- StringRef ModuleName ) {
551+ ArrayRef< StringRef> ModuleNames ) {
550552 // Capture the emitted diagnostics and report them to the client
551553 // in the case of a failure.
552554 std::string DiagnosticOutput;
@@ -555,7 +557,7 @@ llvm::Error DependencyScanningWorker::computeDependencies(
555557 TextDiagnosticPrinter DiagPrinter (DiagnosticsOS, DiagOpts.release ());
556558
557559 if (computeDependencies (WorkingDirectory, CommandLine, Consumer, Controller,
558- DiagPrinter, ModuleName ))
560+ DiagPrinter, ModuleNames ))
559561 return llvm::Error::success ();
560562 return llvm::make_error<llvm::StringError>(DiagnosticsOS.str (),
561563 llvm::inconvertibleErrorCode ());
@@ -625,7 +627,7 @@ bool DependencyScanningWorker::scanDependencies(
625627 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
626628 DependencyConsumer &Consumer, DependencyActionController &Controller,
627629 DiagnosticConsumer &DC, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
628- std::optional<StringRef> ModuleName ) {
630+ std::optional<ArrayRef< StringRef>> ModuleNames ) {
629631 auto FileMgr =
630632 llvm::makeIntrusiveRefCnt<FileManager>(FileSystemOptions{}, FS);
631633
@@ -648,7 +650,7 @@ bool DependencyScanningWorker::scanDependencies(
648650 // always true for a driver invocation.
649651 bool DisableFree = true ;
650652 DependencyScanningAction Action (Service, WorkingDirectory, Consumer,
651- Controller, DepFS, DisableFree, ModuleName );
653+ Controller, DepFS, DisableFree, ModuleNames );
652654
653655 bool Success = false ;
654656 if (CommandLine[1 ] == " -cc1" ) {
@@ -729,13 +731,14 @@ bool DependencyScanningWorker::computeDependencies(
729731 auto &FinalFS = ModifiedFS ? ModifiedFS : BaseFS;
730732
731733 return scanDependencies (WorkingDirectory, FinalCommandLine, Consumer,
732- Controller, DC, FinalFS, /* ModuleName=*/ std::nullopt );
734+ Controller, DC, FinalFS,
735+ /* ModuleNames=*/ std::nullopt );
733736}
734737
735738bool DependencyScanningWorker::computeDependencies (
736739 StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
737740 DependencyConsumer &Consumer, DependencyActionController &Controller,
738- DiagnosticConsumer &DC, StringRef ModuleName ) {
741+ DiagnosticConsumer &DC, ArrayRef< StringRef> ModuleNames ) {
739742 // Reset what might have been modified in the previous worker invocation.
740743 BaseFS->setCurrentWorkingDirectory (WorkingDirectory);
741744
@@ -748,17 +751,21 @@ bool DependencyScanningWorker::computeDependencies(
748751 InMemoryFS->setCurrentWorkingDirectory (WorkingDirectory);
749752 SmallString<128 > FakeInputPath;
750753 // TODO: We should retry the creation if the path already exists.
751- llvm::sys::fs::createUniquePath (ModuleName + " -%%%%%%%%.input" , FakeInputPath,
754+ // FIXME: should we create files for multiple modules? I think so?
755+ llvm::sys::fs::createUniquePath (ModuleNames[0 ] + " -%%%%%%%%.input" ,
756+ FakeInputPath,
752757 /* MakeAbsolute=*/ false );
753- InMemoryFS->addFile (FakeInputPath, 0 , llvm::MemoryBuffer::getMemBuffer (" " ));
758+ std::string FakeString (ModuleNames.size (), ' ' );
759+ InMemoryFS->addFile (FakeInputPath, 0 ,
760+ llvm::MemoryBuffer::getMemBuffer (FakeString));
754761 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> InMemoryOverlay = InMemoryFS;
755762
756763 OverlayFS->pushOverlay (InMemoryOverlay);
757764 auto ModifiedCommandLine = CommandLine;
758765 ModifiedCommandLine.emplace_back (FakeInputPath);
759766
760767 return scanDependencies (WorkingDirectory, ModifiedCommandLine, Consumer,
761- Controller, DC, OverlayFS, ModuleName );
768+ Controller, DC, OverlayFS, ModuleNames );
762769}
763770
764771DependencyActionController::~DependencyActionController () {}
0 commit comments