forked from OSchip/llvm-project
[Reproducer] Add LoadBuffer<> helper (NFC)
Introduce a helper method named LoadBuffer in the Loader to abstract reading a reproducer file from disk. llvm-svn: 375060
This commit is contained in:
parent
27ef81cd48
commit
b2575da9aa
|
@ -302,6 +302,15 @@ public:
|
|||
return GetRoot().CopyByAppendingPathComponent(T::file);
|
||||
}
|
||||
|
||||
template <typename T> llvm::Expected<std::string> LoadBuffer() {
|
||||
FileSpec file = GetFile<typename T::Info>();
|
||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
|
||||
llvm::vfs::getRealFileSystem()->getBufferForFile(file.GetPath());
|
||||
if (!buffer)
|
||||
return llvm::errorCodeToError(buffer.getError());
|
||||
return (*buffer)->getBuffer().str();
|
||||
}
|
||||
|
||||
llvm::Error LoadIndex();
|
||||
|
||||
const FileSpec &GetRoot() const { return m_root; }
|
||||
|
|
|
@ -265,19 +265,12 @@ protected:
|
|||
return true;
|
||||
}
|
||||
case eReproducerProviderVersion: {
|
||||
FileSpec version_file = loader->GetFile<VersionProvider::Info>();
|
||||
|
||||
// Load the version info into a buffer.
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buffer =
|
||||
vfs::getRealFileSystem()->getBufferForFile(version_file.GetPath());
|
||||
if (!buffer) {
|
||||
SetError(result, errorCodeToError(buffer.getError()));
|
||||
Expected<std::string> version = loader->LoadBuffer<VersionProvider>();
|
||||
if (!version) {
|
||||
SetError(result, version.takeError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return the version string.
|
||||
StringRef version = (*buffer)->getBuffer();
|
||||
result.AppendMessage(version.str());
|
||||
result.AppendMessage(*version);
|
||||
result.SetStatus(eReturnStatusSuccessFinishResult);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue