Skip to content

Support mapping path prefixes for index stores #21893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/Index/IndexRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace swift {
class DependencyTracker;
class ModuleDecl;
class SourceFile;
class PathRemapper;

namespace index {

Expand All @@ -44,7 +45,8 @@ namespace index {
bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
StringRef indexStorePath, bool indexSystemModules,
bool isDebugCompilation, StringRef targetTriple,
const DependencyTracker &dependencyTracker);
const DependencyTracker &dependencyTracker,
const PathRemapper &debugPrefixMap);

/// Index the given module and store the results to \p indexStorePath.
///
Expand Down
3 changes: 2 additions & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,8 @@ static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
if (index::indexAndRecord(PrimarySourceFile, PSPs.OutputFilename,
opts.IndexStorePath, opts.IndexSystemModules,
isDebugCompilation, Invocation.getTargetTriple(),
*Instance.getDependencyTracker())) {
*Instance.getDependencyTracker(),
Invocation.getIRGenOptions().DebugPrefixMap)) {
return true;
}
} else {
Expand Down
29 changes: 16 additions & 13 deletions lib/Index/IndexRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "swift/AST/Types.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/AST/ModuleLoader.h"
#include "swift/Basic/PathRemapper.h"
#include "swift/ClangImporter/ClangModule.h"
#include "swift/Index/Index.h"
#include "clang/Basic/FileManager.h"
Expand Down Expand Up @@ -582,11 +583,14 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
bool isDebugCompilation, StringRef targetTriple,
ArrayRef<const clang::FileEntry *> fileDependencies,
const clang::CompilerInstance &clangCI,
DiagnosticEngine &diags) {
DiagnosticEngine &diags, const PathRemapper &debugPrefixMap) {
auto &fileMgr = clangCI.getFileManager();
auto *module = primarySourceFile->getParentModule();
bool isSystem = module->isSystemModule();
auto *mainFile = fileMgr.getFile(primarySourceFile->getFilename());
auto mainFilename =
debugPrefixMap.remapPath(primarySourceFile->getFilename());
auto *mainFile = fileMgr.getVirtualFile(mainFilename, 0, 0);

// FIXME: Get real values for the following.
StringRef swiftVersion;
StringRef sysrootPath = clangCI.getHeaderSearchOpts().Sysroot;
Expand Down Expand Up @@ -652,7 +656,8 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
bool indexSystemModules,
bool isDebugCompilation,
StringRef targetTriple,
const DependencyTracker &dependencyTracker) {
const DependencyTracker &dependencyTracker,
const PathRemapper &debugPrefixMap) {
auto &astContext = primarySourceFile->getASTContext();
auto &clangCI = astContext.getClangModuleLoader()->getClangInstance();
auto &diags = astContext.Diags;
Expand All @@ -676,11 +681,10 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
collectFileDependencies(fileDependencies, dependencyTracker, module, fileMgr);
#endif

return recordSourceFileUnit(primarySourceFile, indexUnitToken,
indexStorePath, indexSystemModules,
isDebugCompilation, targetTriple,
fileDependencies.getArrayRef(),
clangCI, diags);
return recordSourceFileUnit(primarySourceFile, indexUnitToken, indexStorePath,
indexSystemModules, isDebugCompilation,
targetTriple, fileDependencies.getArrayRef(),
clangCI, diags, debugPrefixMap);
}

bool index::indexAndRecord(ModuleDecl *module,
Expand Down Expand Up @@ -722,11 +726,10 @@ bool index::indexAndRecord(ModuleDecl *module,
diags.diagnose(SourceLoc(), diag::error_index_inputs_more_than_outputs);
return true;
}
if (recordSourceFileUnit(SF, indexUnitTokens[unitIndex],
indexStorePath, indexSystemModules,
isDebugCompilation, targetTriple,
fileDependencies.getArrayRef(),
clangCI, diags))
if (recordSourceFileUnit(SF, indexUnitTokens[unitIndex], indexStorePath,
indexSystemModules, isDebugCompilation,
targetTriple, fileDependencies.getArrayRef(),
clangCI, diags, {}))
return true;
unitIndex += 1;
}
Expand Down