@@ -422,9 +422,6 @@ namespace {
422422
423423 // / \brief Builder that generates the global module index file.
424424 class GlobalModuleIndexBuilder {
425- FileManager &FileMgr;
426- const PCHContainerReader &PCHContainerRdr;
427-
428425 // / Mapping from files to module file information.
429426 typedef llvm::MapVector<const FileEntry *, ModuleFileInfo> ModuleFilesMap;
430427
@@ -464,14 +461,20 @@ namespace {
464461 }
465462
466463 public:
467- explicit GlobalModuleIndexBuilder (
468- FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr)
469- : FileMgr(FileMgr), PCHContainerRdr(PCHContainerRdr) {}
464+ explicit GlobalModuleIndexBuilder (GlobalModuleIndex::UserDefinedInterestingIDs* ExternalIDs) {
465+ if (!ExternalIDs)
466+ return ;
467+
468+ for (const auto & I : *ExternalIDs)
469+ for (const FileEntry * J : I.getValue ())
470+ InterestingIdentifiers[I.getKey ()].push_back (getModuleFileInfo (J).ID );
471+ }
470472
471473 // / \brief Load the contents of the given module file into the builder.
472474 // /
473475 // / \returns true if an error occurred, false otherwise.
474- bool loadModuleFile (const FileEntry *File);
476+ bool loadModuleFile (const FileEntry *File, FileManager &FileMgr,
477+ const PCHContainerReader &PCHContainerRdr);
475478
476479 // / \brief Write the index to the given bitstream.
477480 // / \returns true if an error occurred, false otherwise.
@@ -542,7 +545,9 @@ namespace {
542545 };
543546}
544547
545- bool GlobalModuleIndexBuilder::loadModuleFile (const FileEntry *File) {
548+ bool GlobalModuleIndexBuilder::loadModuleFile (const FileEntry *File,
549+ FileManager &FileMgr,
550+ const PCHContainerReader &PCHContainerRdr) {
546551 // Open the module file.
547552
548553 auto Buffer = FileMgr.getBufferForFile (File, /* isVolatile=*/ true );
@@ -693,7 +698,10 @@ bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
693698 DEnd = Table->data_end ();
694699 D != DEnd; ++D) {
695700 std::pair<StringRef, bool > Ident = *D;
696- InterestingIdentifiers[Ident.first ].push_back (ID);
701+ if (Ident.second )
702+ InterestingIdentifiers[Ident.first ].push_back (ID);
703+ else
704+ (void )InterestingIdentifiers[Ident.first ];
697705 }
698706 }
699707
@@ -755,14 +763,15 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
755763 for (auto MapEntry : ImportedModuleFiles) {
756764 auto *File = MapEntry.first ;
757765 ImportedModuleFileInfo &Info = MapEntry.second ;
758- // if (getModuleFileInfo(File).Signature) {
759- // if (getModuleFileInfo(File).Signature != Info.StoredSignature)
760- // // Verify Signature.
761- // return true;
762- // } else if (Info.StoredSize != File->getSize() ||
763- // Info.StoredModTime != File->getModificationTime())
764- // // Verify Size and ModTime.
765- // return true;
766+ if (getModuleFileInfo (File).Signature ) {
767+ if (getModuleFileInfo (File).Signature != Info.StoredSignature )
768+ // Verify Signature.
769+ return true ;
770+ } else if (Info.StoredSize != File->getSize () ||
771+ (Info.StoredModTime &&
772+ Info.StoredModTime != File->getModificationTime ()))
773+ // Verify Size and ModTime.
774+ return true ;
766775 }
767776
768777 using namespace llvm ;
@@ -846,7 +855,9 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
846855GlobalModuleIndex::ErrorCode
847856GlobalModuleIndex::writeIndex (FileManager &FileMgr,
848857 const PCHContainerReader &PCHContainerRdr,
849- StringRef Path) {
858+ StringRef Path,
859+ UserDefinedInterestingIDs *ExternalIDs /* = nullptr */ ) {
860+
850861 llvm::SmallString<128 > IndexPath;
851862 IndexPath += Path;
852863 llvm::sys::path::append (IndexPath, IndexFileName);
@@ -869,32 +880,34 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
869880 }
870881
871882 // The module index builder.
872- GlobalModuleIndexBuilder Builder (FileMgr, PCHContainerRdr);
873-
874- // Load each of the module files.
875- std::error_code EC;
876- for (llvm::sys::fs::directory_iterator D (Path, EC), DEnd;
877- D != DEnd && !EC;
878- D.increment (EC)) {
879- // If this isn't a module file, we don't care.
880- if (llvm::sys::path::extension (D->path ()) != " .pcm" ) {
881- // ... unless it's a .pcm.lock file, which indicates that someone is
882- // in the process of rebuilding a module. They'll rebuild the index
883- // at the end of that translation unit, so we don't have to.
884- if (llvm::sys::path::extension (D->path ()) == " .pcm.lock" )
885- return EC_Building;
883+ GlobalModuleIndexBuilder Builder (ExternalIDs);
884+
885+ if (!ExternalIDs) {
886+ // Load each of the module files.
887+ std::error_code EC;
888+ for (llvm::sys::fs::directory_iterator D (Path, EC), DEnd;
889+ D != DEnd && !EC;
890+ D.increment (EC)) {
891+ // If this isn't a module file, we don't care.
892+ if (llvm::sys::path::extension (D->path ()) != " .pcm" ) {
893+ // ... unless it's a .pcm.lock file, which indicates that someone is
894+ // in the process of rebuilding a module. They'll rebuild the index
895+ // at the end of that translation unit, so we don't have to.
896+ if (llvm::sys::path::extension (D->path ()) == " .pcm.lock" )
897+ return EC_Building;
886898
887- continue ;
888- }
899+ continue ;
900+ }
889901
890- // If we can't find the module file, skip it.
891- const FileEntry *ModuleFile = FileMgr.getFile (D->path ());
892- if (!ModuleFile)
893- continue ;
902+ // If we can't find the module file, skip it.
903+ const FileEntry *ModuleFile = FileMgr.getFile (D->path ());
904+ if (!ModuleFile)
905+ continue ;
894906
895- // Load this module file.
896- if (Builder.loadModuleFile (ModuleFile))
897- return EC_IOError;
907+ // Load this module file.
908+ if (Builder.loadModuleFile (ModuleFile, FileMgr, PCHContainerRdr))
909+ return EC_IOError;
910+ }
898911 }
899912
900913 // The output buffer, into which the global index will be written.
0 commit comments