2222#include " swift/AST/SourceFile.h"
2323#include " swift/AST/Stmt.h"
2424#include " swift/AST/Types.h"
25+ #include " swift/Basic/PathRemapper.h"
2526#include " swift/ClangImporter/ClangModule.h"
2627#include " swift/Index/Index.h"
2728#include " clang/Basic/FileManager.h"
@@ -381,6 +382,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
381382 const clang::CompilerInstance &clangCI,
382383 DiagnosticEngine &diags,
383384 IndexUnitWriter &parentUnitWriter,
385+ const PathRemapper &pathRemapper,
384386 SourceFile *initialFile);
385387
386388static void addModuleDependencies (ArrayRef<ImportedModule> imports,
@@ -392,6 +394,7 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
392394 DiagnosticEngine &diags,
393395 IndexUnitWriter &unitWriter,
394396 StringScratchSpace &moduleNameScratch,
397+ const PathRemapper &pathRemapper,
395398 SourceFile *initialFile = nullptr ) {
396399 auto &fileMgr = clangCI.getFileManager ();
397400
@@ -442,7 +445,9 @@ static void addModuleDependencies(ArrayRef<ImportedModule> imports,
442445 emitDataForSwiftSerializedModule (mod, indexStorePath,
443446 indexSystemModules, skipStdlib,
444447 targetTriple, clangCI, diags,
445- unitWriter, initialFile);
448+ unitWriter,
449+ pathRemapper,
450+ initialFile);
446451 withoutUnitName = false ;
447452 }
448453
@@ -473,6 +478,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
473478 const clang::CompilerInstance &clangCI,
474479 DiagnosticEngine &diags,
475480 IndexUnitWriter &parentUnitWriter,
481+ const PathRemapper &pathRemapper,
476482 SourceFile *initialFile) {
477483 StringRef filename = module ->getModuleFilename ();
478484 std::string moduleName = module ->getNameStr ().str ();
@@ -567,11 +573,13 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
567573 // For indexing serialized modules 'debug compilation' is irrelevant, so
568574 // set it to true by default.
569575 bool isDebugCompilation = true ;
576+ auto clangRemapper = pathRemapper.asClangPathRemapper ();
570577
571578 IndexUnitWriter unitWriter (fileMgr, indexStorePath,
572579 " swift" , swiftVersion, indexUnitToken, moduleName,
573580 /* MainFile=*/ nullptr , isSystem, /* IsModuleUnit=*/ true ,
574- isDebugCompilation, targetTriple, sysrootPath, getModuleInfoFromOpaqueModule);
581+ isDebugCompilation, targetTriple, sysrootPath,
582+ clangRemapper, getModuleInfoFromOpaqueModule);
575583
576584 auto FE = fileMgr.getFile (filename);
577585 bool isSystemModule = module ->isSystemModule ();
@@ -590,7 +598,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
590598 StringScratchSpace moduleNameScratch;
591599 addModuleDependencies (imports, indexStorePath, indexSystemModules, skipStdlib,
592600 targetTriple, clangCI, diags, unitWriter,
593- moduleNameScratch, initialFile);
601+ moduleNameScratch, pathRemapper, initialFile);
594602
595603 if (unitWriter.write (error)) {
596604 diags.diagnose (SourceLoc (), diag::error_write_index_unit, error);
@@ -607,19 +615,21 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
607615 StringRef targetTriple,
608616 ArrayRef<const clang::FileEntry *> fileDependencies,
609617 const clang::CompilerInstance &clangCI,
618+ const PathRemapper &pathRemapper,
610619 DiagnosticEngine &diags) {
611620 auto &fileMgr = clangCI.getFileManager ();
612621 auto *module = primarySourceFile->getParentModule ();
613622 bool isSystem = module ->isSystemModule ();
614623 auto mainFile = fileMgr.getFile (primarySourceFile->getFilename ());
624+ auto clangRemapper = pathRemapper.asClangPathRemapper ();
615625 // FIXME: Get real values for the following.
616626 StringRef swiftVersion;
617627 StringRef sysrootPath = clangCI.getHeaderSearchOpts ().Sysroot ;
618628 IndexUnitWriter unitWriter (
619629 fileMgr, indexStorePath, " swift" , swiftVersion, indexUnitToken,
620630 module ->getNameStr (), mainFile ? *mainFile : nullptr , isSystem,
621631 /* isModuleUnit=*/ false , isDebugCompilation, targetTriple, sysrootPath,
622- getModuleInfoFromOpaqueModule);
632+ clangRemapper, getModuleInfoFromOpaqueModule);
623633
624634 // Module dependencies.
625635 SmallVector<ImportedModule, 8 > imports;
@@ -630,7 +640,7 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
630640 StringScratchSpace moduleNameScratch;
631641 addModuleDependencies (imports, indexStorePath, indexSystemModules, skipStdlib,
632642 targetTriple, clangCI, diags, unitWriter,
633- moduleNameScratch, primarySourceFile);
643+ moduleNameScratch, pathRemapper, primarySourceFile);
634644
635645 // File dependencies.
636646 for (auto *F : fileDependencies)
@@ -684,7 +694,8 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
684694 bool skipStdlib,
685695 bool isDebugCompilation,
686696 StringRef targetTriple,
687- const DependencyTracker &dependencyTracker) {
697+ const DependencyTracker &dependencyTracker,
698+ const PathRemapper &pathRemapper) {
688699 auto &astContext = primarySourceFile->getASTContext ();
689700 auto &clangCI = astContext.getClangModuleLoader ()->getClangInstance ();
690701 auto &diags = astContext.Diags ;
@@ -712,7 +723,7 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
712723 indexStorePath, indexSystemModules, skipStdlib,
713724 isDebugCompilation, targetTriple,
714725 fileDependencies.getArrayRef (),
715- clangCI, diags);
726+ clangCI, pathRemapper, diags);
716727}
717728
718729bool index::indexAndRecord (ModuleDecl *module ,
@@ -723,7 +734,8 @@ bool index::indexAndRecord(ModuleDecl *module,
723734 bool skipStdlib,
724735 bool isDebugCompilation,
725736 StringRef targetTriple,
726- const DependencyTracker &dependencyTracker) {
737+ const DependencyTracker &dependencyTracker,
738+ const PathRemapper &pathRemapper) {
727739 auto &astContext = module ->getASTContext ();
728740 auto &clangCI = astContext.getClangModuleLoader ()->getClangInstance ();
729741 auto &diags = astContext.Diags ;
@@ -759,7 +771,7 @@ bool index::indexAndRecord(ModuleDecl *module,
759771 indexStorePath, indexSystemModules, skipStdlib,
760772 isDebugCompilation, targetTriple,
761773 fileDependencies.getArrayRef (),
762- clangCI, diags))
774+ clangCI, pathRemapper, diags))
763775 return true ;
764776 unitIndex += 1 ;
765777 }
0 commit comments