13#include "llvm/Support/FileSystem.h"
14#include "llvm/Support/LockFileManager.h"
15#include "llvm/Support/Path.h"
22 llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::OF_None);
27 if (PruneInterval <= 0 || PruneAfter <= 0)
31 llvm::sys::path::append(TimestampFile,
"modules.timestamp");
34 llvm::sys::fs::file_status StatBuf;
35 if (std::error_code EC = llvm::sys::fs::status(TimestampFile, StatBuf)) {
37 if (EC == std::errc::no_such_file_or_directory)
44 time_t TimestampModTime =
45 llvm::sys::toTimeT(StatBuf.getLastModificationTime());
46 time_t CurrentTime = time(
nullptr);
47 if (CurrentTime - TimestampModTime <= PruneInterval)
58 for (llvm::sys::fs::directory_iterator Dir(Path, EC), DirEnd;
59 Dir != DirEnd && !EC; Dir.increment(EC)) {
61 if (!llvm::sys::fs::is_directory(Dir->path()))
65 for (llvm::sys::fs::directory_iterator
File(Dir->path(), EC), FileEnd;
66 File != FileEnd && !EC;
File.increment(EC)) {
68 StringRef Extension = llvm::sys::path::extension(
File->path());
69 if (Extension !=
".pcm" && Extension !=
".timestamp" &&
70 llvm::sys::path::filename(
File->path()) !=
"modules.idx")
75 if (llvm::sys::fs::status(
File->path(), StatBuf))
79 time_t FileAccessTime = llvm::sys::toTimeT(StatBuf.getLastAccessedTime());
80 if (CurrentTime - FileAccessTime <= PruneAfter)
84 llvm::sys::fs::remove(
File->path());
87 std::string TimpestampFilename =
File->path() +
".timestamp";
88 llvm::sys::fs::remove(TimpestampFilename);
93 if (llvm::sys::fs::directory_iterator(Dir->path(), EC) ==
94 llvm::sys::fs::directory_iterator() &&
96 llvm::sys::fs::remove(Dir->path());
101class CrossProcessModuleCache :
public ModuleCache {
105 void prepareForGetLock(StringRef ModuleFilename)
override {
108 StringRef Dir = llvm::sys::path::parent_path(ModuleFilename);
109 llvm::sys::fs::create_directories(Dir);
112 std::unique_ptr<llvm::AdvisoryLock>
113 getLock(StringRef ModuleFilename)
override {
114 return std::make_unique<llvm::LockFileManager>(ModuleFilename);
117 std::time_t getModuleTimestamp(StringRef ModuleFilename)
override {
118 std::string TimestampFilename =
120 llvm::sys::fs::file_status Status;
121 if (llvm::sys::fs::status(TimestampFilename, Status) != std::error_code{})
123 return llvm::sys::toTimeT(Status.getLastModificationTime());
126 void updateModuleTimestamp(StringRef ModuleFilename)
override {
129 llvm::raw_fd_ostream
OS(
131 llvm::sys::fs::OF_TextWithCRLF);
134 OS <<
"Timestamp file\n";
139 void maybePrune(StringRef Path, time_t PruneInterval,
140 time_t PruneAfter)
override {
144 InMemoryModuleCache &getInMemoryModuleCache()
override {
return InMemory; }
145 const InMemoryModuleCache &getInMemoryModuleCache()
const override {
152 return llvm::makeIntrusiveRefCnt<CrossProcessModuleCache>();
static void writeTimestampFile(StringRef TimestampFile)
Write a new timestamp file with the given path.
In-memory cache for modules.
The module cache used for compiling modules implicitly.
static std::string getTimestampFilename(StringRef FileName)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
The JSON file list parser is used to communicate input to InstallAPI.
IntrusiveRefCntPtr< ModuleCache > createCrossProcessModuleCache()
Creates new ModuleCache backed by a file system directory that may be operated on by multiple process...
void maybePruneImpl(StringRef Path, time_t PruneInterval, time_t PruneAfter)
Shared implementation of ModuleCache::maybePrune().