@@ -1598,90 +1598,6 @@ static void checkConfigMacros(Preprocessor &PP, Module *M,
15981598 }
15991599}
16001600
1601- // / Write a new timestamp file with the given path.
1602- static void writeTimestampFile (StringRef TimestampFile) {
1603- std::error_code EC;
1604- llvm::raw_fd_ostream Out (TimestampFile.str (), EC, llvm::sys::fs::OF_None);
1605- }
1606-
1607- // / Prune the module cache of modules that haven't been accessed in
1608- // / a long time.
1609- static void pruneModuleCache (const HeaderSearchOptions &HSOpts) {
1610- llvm::sys::fs::file_status StatBuf;
1611- llvm::SmallString<128 > TimestampFile;
1612- TimestampFile = HSOpts.ModuleCachePath ;
1613- assert (!TimestampFile.empty ());
1614- llvm::sys::path::append (TimestampFile, " modules.timestamp" );
1615-
1616- // Try to stat() the timestamp file.
1617- if (std::error_code EC = llvm::sys::fs::status (TimestampFile, StatBuf)) {
1618- // If the timestamp file wasn't there, create one now.
1619- if (EC == std::errc::no_such_file_or_directory) {
1620- writeTimestampFile (TimestampFile);
1621- }
1622- return ;
1623- }
1624-
1625- // Check whether the time stamp is older than our pruning interval.
1626- // If not, do nothing.
1627- time_t TimeStampModTime =
1628- llvm::sys::toTimeT (StatBuf.getLastModificationTime ());
1629- time_t CurrentTime = time (nullptr );
1630- if (CurrentTime - TimeStampModTime <= time_t (HSOpts.ModuleCachePruneInterval ))
1631- return ;
1632-
1633- // Write a new timestamp file so that nobody else attempts to prune.
1634- // There is a benign race condition here, if two Clang instances happen to
1635- // notice at the same time that the timestamp is out-of-date.
1636- writeTimestampFile (TimestampFile);
1637-
1638- // Walk the entire module cache, looking for unused module files and module
1639- // indices.
1640- std::error_code EC;
1641- for (llvm::sys::fs::directory_iterator Dir (HSOpts.ModuleCachePath , EC),
1642- DirEnd;
1643- Dir != DirEnd && !EC; Dir.increment (EC)) {
1644- // If we don't have a directory, there's nothing to look into.
1645- if (!llvm::sys::fs::is_directory (Dir->path ()))
1646- continue ;
1647-
1648- // Walk all of the files within this directory.
1649- for (llvm::sys::fs::directory_iterator File (Dir->path (), EC), FileEnd;
1650- File != FileEnd && !EC; File.increment (EC)) {
1651- // We only care about module and global module index files.
1652- StringRef Extension = llvm::sys::path::extension (File->path ());
1653- if (Extension != " .pcm" && Extension != " .timestamp" &&
1654- llvm::sys::path::filename (File->path ()) != " modules.idx" )
1655- continue ;
1656-
1657- // Look at this file. If we can't stat it, there's nothing interesting
1658- // there.
1659- if (llvm::sys::fs::status (File->path (), StatBuf))
1660- continue ;
1661-
1662- // If the file has been used recently enough, leave it there.
1663- time_t FileAccessTime = llvm::sys::toTimeT (StatBuf.getLastAccessedTime ());
1664- if (CurrentTime - FileAccessTime <=
1665- time_t (HSOpts.ModuleCachePruneAfter )) {
1666- continue ;
1667- }
1668-
1669- // Remove the file.
1670- llvm::sys::fs::remove (File->path ());
1671-
1672- // Remove the timestamp file.
1673- std::string TimpestampFilename = File->path () + " .timestamp" ;
1674- llvm::sys::fs::remove (TimpestampFilename);
1675- }
1676-
1677- // If we removed all of the files in the directory, remove the directory
1678- // itself.
1679- if (llvm::sys::fs::directory_iterator (Dir->path (), EC) ==
1680- llvm::sys::fs::directory_iterator () && !EC)
1681- llvm::sys::fs::remove (Dir->path ());
1682- }
1683- }
1684-
16851601void CompilerInstance::createASTReader () {
16861602 if (TheASTReader)
16871603 return ;
@@ -1692,11 +1608,10 @@ void CompilerInstance::createASTReader() {
16921608 // If we're implicitly building modules but not currently recursively
16931609 // building a module, check whether we need to prune the module cache.
16941610 if (getSourceManager ().getModuleBuildStack ().empty () &&
1695- !getPreprocessor ().getHeaderSearchInfo ().getModuleCachePath ().empty () &&
1696- getHeaderSearchOpts ().ModuleCachePruneInterval > 0 &&
1697- getHeaderSearchOpts ().ModuleCachePruneAfter > 0 ) {
1698- pruneModuleCache (getHeaderSearchOpts ());
1699- }
1611+ !getPreprocessor ().getHeaderSearchInfo ().getModuleCachePath ().empty ())
1612+ ModCache->maybePrune (getHeaderSearchOpts ().ModuleCachePath ,
1613+ getHeaderSearchOpts ().ModuleCachePruneInterval ,
1614+ getHeaderSearchOpts ().ModuleCachePruneAfter );
17001615
17011616 HeaderSearchOptions &HSOpts = getHeaderSearchOpts ();
17021617 std::string Sysroot = HSOpts.Sysroot ;
0 commit comments