aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp93
1 files changed, 4 insertions, 89 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index c989ad2..b1fb905 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1598,90 +1598,6 @@ static void checkConfigMacros(Preprocessor &PP, Module *M,
}
}
-/// Write a new timestamp file with the given path.
-static void writeTimestampFile(StringRef TimestampFile) {
- std::error_code EC;
- llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::OF_None);
-}
-
-/// Prune the module cache of modules that haven't been accessed in
-/// a long time.
-static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {
- llvm::sys::fs::file_status StatBuf;
- llvm::SmallString<128> TimestampFile;
- TimestampFile = HSOpts.ModuleCachePath;
- assert(!TimestampFile.empty());
- llvm::sys::path::append(TimestampFile, "modules.timestamp");
-
- // Try to stat() the timestamp file.
- if (std::error_code EC = llvm::sys::fs::status(TimestampFile, StatBuf)) {
- // If the timestamp file wasn't there, create one now.
- if (EC == std::errc::no_such_file_or_directory) {
- writeTimestampFile(TimestampFile);
- }
- return;
- }
-
- // Check whether the time stamp is older than our pruning interval.
- // If not, do nothing.
- time_t TimeStampModTime =
- llvm::sys::toTimeT(StatBuf.getLastModificationTime());
- time_t CurrentTime = time(nullptr);
- if (CurrentTime - TimeStampModTime <= time_t(HSOpts.ModuleCachePruneInterval))
- return;
-
- // Write a new timestamp file so that nobody else attempts to prune.
- // There is a benign race condition here, if two Clang instances happen to
- // notice at the same time that the timestamp is out-of-date.
- writeTimestampFile(TimestampFile);
-
- // Walk the entire module cache, looking for unused module files and module
- // indices.
- std::error_code EC;
- for (llvm::sys::fs::directory_iterator Dir(HSOpts.ModuleCachePath, EC),
- DirEnd;
- Dir != DirEnd && !EC; Dir.increment(EC)) {
- // If we don't have a directory, there's nothing to look into.
- if (!llvm::sys::fs::is_directory(Dir->path()))
- continue;
-
- // Walk all of the files within this directory.
- for (llvm::sys::fs::directory_iterator File(Dir->path(), EC), FileEnd;
- File != FileEnd && !EC; File.increment(EC)) {
- // We only care about module and global module index files.
- StringRef Extension = llvm::sys::path::extension(File->path());
- if (Extension != ".pcm" && Extension != ".timestamp" &&
- llvm::sys::path::filename(File->path()) != "modules.idx")
- continue;
-
- // Look at this file. If we can't stat it, there's nothing interesting
- // there.
- if (llvm::sys::fs::status(File->path(), StatBuf))
- continue;
-
- // If the file has been used recently enough, leave it there.
- time_t FileAccessTime = llvm::sys::toTimeT(StatBuf.getLastAccessedTime());
- if (CurrentTime - FileAccessTime <=
- time_t(HSOpts.ModuleCachePruneAfter)) {
- continue;
- }
-
- // Remove the file.
- llvm::sys::fs::remove(File->path());
-
- // Remove the timestamp file.
- std::string TimpestampFilename = File->path() + ".timestamp";
- llvm::sys::fs::remove(TimpestampFilename);
- }
-
- // If we removed all of the files in the directory, remove the directory
- // itself.
- if (llvm::sys::fs::directory_iterator(Dir->path(), EC) ==
- llvm::sys::fs::directory_iterator() && !EC)
- llvm::sys::fs::remove(Dir->path());
- }
-}
-
void CompilerInstance::createASTReader() {
if (TheASTReader)
return;
@@ -1692,11 +1608,10 @@ void CompilerInstance::createASTReader() {
// If we're implicitly building modules but not currently recursively
// building a module, check whether we need to prune the module cache.
if (getSourceManager().getModuleBuildStack().empty() &&
- !getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty() &&
- getHeaderSearchOpts().ModuleCachePruneInterval > 0 &&
- getHeaderSearchOpts().ModuleCachePruneAfter > 0) {
- pruneModuleCache(getHeaderSearchOpts());
- }
+ !getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty())
+ ModCache->maybePrune(getHeaderSearchOpts().ModuleCachePath,
+ getHeaderSearchOpts().ModuleCachePruneInterval,
+ getHeaderSearchOpts().ModuleCachePruneAfter);
HeaderSearchOptions &HSOpts = getHeaderSearchOpts();
std::string Sysroot = HSOpts.Sysroot;