22 using namespace llvm::lto;
33 if (
auto EC = ReloadedBufferOrErr.getError())
35 "': " + EC.message() +
"\n");
40 " to save cached entry\n");
43 OS << (*ReloadedBufferOrErr)->getBuffer();
56 AddFile(Task, EntryPath);
64 std::string TempFilename;
65 std::string EntryPath;
68 CacheStream(std::unique_ptr<raw_pwrite_stream> OS,
AddFileFn AddFile,
69 std::string TempFilename, std::string EntryPath,
72 TempFilename(TempFilename), EntryPath(EntryPath), Task(Task) {}
78 AddFile(Task, EntryPath);
82 return [=](
size_t Task) -> std::unique_ptr<NativeObjectStream> {
89 errs() <<
"Error: " << EC.message() <<
"\n";
94 return llvm::make_unique<CacheStream>(
95 llvm::make_unique<raw_fd_ostream>(TempFD,
true),
96 AddFile, TempFilename.
str(), EntryPath.
str(), Task);
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
std::function< std::unique_ptr< NativeObjectStream >unsigned Task)> AddStreamFn
This type defines the callback to add a native object that is generated on the fly.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
static void commitEntry(StringRef TempFilename, StringRef EntryPath)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::function< void(unsigned Task, StringRef Path)> AddFileFn
This type defines the callback to add a pre-existing native object file (e.g.
std::function< AddStreamFn(unsigned Task, StringRef Key)> NativeObjectCache
This is the type of a native object cache.
This class wraps an output stream for a native object.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
StringRef str() const
Explicit conversion to StringRef.
A raw_ostream that writes to a file descriptor.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
StringRef - Represent a constant reference to a string, i.e.
bool exists(file_status status)
Does file exist?
NativeObjectCache localCache(std::string CacheDirectoryPath, AddFileFn AddFile)
Create a local file system cache which uses the given cache directory and file callback.