Skip to content
Closed
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
50 changes: 41 additions & 9 deletions index-import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,27 @@ static const FileEntry *getFileEntry(FileManager &fileMgr, StringRef path) {
}
}

static IndexUnitWriter remapUnit(const std::unique_ptr<IndexUnitReader> &reader,
const Remapper &remapper, FileManager &fileMgr,
ModuleNameScope &moduleNames) {
// Returns true if the Unit file of given output file already exists and is
// older than the input file.
static bool isUnitUpToDate(StringRef outputFile, StringRef inputFile,
IndexUnitWriter &writer) {
std::string error;
auto isUpToDateOpt =
writer.isUnitUpToDateForOutputFile(outputFile, inputFile, error);
if (!isUpToDateOpt.hasValue()) {
errs() << "error: failed file status check:\n" << error << "\n";
return false;
}

return *isUpToDateOpt;
}

// Returns None if the Unit file is already up to date
static Optional<IndexUnitWriter>
remapUnit(StringRef inputUnitPath,
const std::unique_ptr<IndexUnitReader> &reader,
const Remapper &remapper, FileManager &fileMgr,
ModuleNameScope &moduleNames) {
// The set of remapped paths.
auto workingDir = remapper.remap(reader->getWorkingDirectory());
auto outputFile = remapper.remap(reader->getOutputFile());
Expand All @@ -122,6 +140,18 @@ static IndexUnitWriter remapUnit(const std::unique_ptr<IndexUnitReader> &reader,
reader->isModuleUnit(), reader->isDebugCompilation(), reader->getTarget(),
sysrootPath, moduleNames.getModuleInfo);

// Check if the unit file is already up to date
SmallString<256> remappedOutputFilePath;
if (outputFile[0] != '/') {
// Convert outputFile to absolute path
path::append(remappedOutputFilePath, workingDir, outputFile);
} else {
remappedOutputFilePath = outputFile;
}
if (isUnitUpToDate(remappedOutputFilePath, inputUnitPath, writer)) {
return None;
}

reader->foreachDependency([&](const IndexUnitReader::DependencyInfo &info) {
const auto name = info.UnitOrRecordName;
const auto moduleNameRef = moduleNames.getReference(info.ModuleName);
Expand Down Expand Up @@ -285,13 +315,15 @@ static bool remapIndex(const Remapper &remapper,
}

ModuleNameScope moduleNames;
auto writer = remapUnit(reader, remapper, fileMgr, moduleNames);
auto writer = remapUnit(unitPath, reader, remapper, fileMgr, moduleNames);

std::string unitWriteError;
if (writer.write(unitWriteError)) {
errs() << "error: failed to write index store; " << unitWriteError
<< "\n";
success = false;
if (writer.hasValue()) {
std::string unitWriteError;
if (writer->write(unitWriteError)) {
errs() << "error: failed to write index store; " << unitWriteError
<< "\n";
success = false;
}
}
}

Expand Down