@@ -1848,90 +1848,6 @@ static void checkConfigMacros(Preprocessor &PP, Module *M,
18481848 }
18491849}
18501850
1851- // / Write a new timestamp file with the given path.
1852- static void writeTimestampFile (StringRef TimestampFile) {
1853- std::error_code EC;
1854- llvm::raw_fd_ostream Out (TimestampFile.str (), EC, llvm::sys::fs::OF_None);
1855- }
1856-
1857- // / Prune the module cache of modules that haven't been accessed in
1858- // / a long time.
1859- static void pruneModuleCache (const HeaderSearchOptions &HSOpts) {
1860- llvm::sys::fs::file_status StatBuf;
1861- llvm::SmallString<128 > TimestampFile;
1862- TimestampFile = HSOpts.ModuleCachePath ;
1863- assert (!TimestampFile.empty ());
1864- llvm::sys::path::append (TimestampFile, " modules.timestamp" );
1865-
1866- // Try to stat() the timestamp file.
1867- if (std::error_code EC = llvm::sys::fs::status (TimestampFile, StatBuf)) {
1868- // If the timestamp file wasn't there, create one now.
1869- if (EC == std::errc::no_such_file_or_directory) {
1870- writeTimestampFile (TimestampFile);
1871- }
1872- return ;
1873- }
1874-
1875- // Check whether the time stamp is older than our pruning interval.
1876- // If not, do nothing.
1877- time_t TimeStampModTime =
1878- llvm::sys::toTimeT (StatBuf.getLastModificationTime ());
1879- time_t CurrentTime = time (nullptr );
1880- if (CurrentTime - TimeStampModTime <= time_t (HSOpts.ModuleCachePruneInterval ))
1881- return ;
1882-
1883- // Write a new timestamp file so that nobody else attempts to prune.
1884- // There is a benign race condition here, if two Clang instances happen to
1885- // notice at the same time that the timestamp is out-of-date.
1886- writeTimestampFile (TimestampFile);
1887-
1888- // Walk the entire module cache, looking for unused module files and module
1889- // indices.
1890- std::error_code EC;
1891- for (llvm::sys::fs::directory_iterator Dir (HSOpts.ModuleCachePath , EC),
1892- DirEnd;
1893- Dir != DirEnd && !EC; Dir.increment (EC)) {
1894- // If we don't have a directory, there's nothing to look into.
1895- if (!llvm::sys::fs::is_directory (Dir->path ()))
1896- continue ;
1897-
1898- // Walk all of the files within this directory.
1899- for (llvm::sys::fs::directory_iterator File (Dir->path (), EC), FileEnd;
1900- File != FileEnd && !EC; File.increment (EC)) {
1901- // We only care about module and global module index files.
1902- StringRef Extension = llvm::sys::path::extension (File->path ());
1903- if (Extension != " .pcm" && Extension != " .timestamp" &&
1904- llvm::sys::path::filename (File->path ()) != " modules.idx" )
1905- continue ;
1906-
1907- // Look at this file. If we can't stat it, there's nothing interesting
1908- // there.
1909- if (llvm::sys::fs::status (File->path (), StatBuf))
1910- continue ;
1911-
1912- // If the file has been used recently enough, leave it there.
1913- time_t FileAccessTime = llvm::sys::toTimeT (StatBuf.getLastAccessedTime ());
1914- if (CurrentTime - FileAccessTime <=
1915- time_t (HSOpts.ModuleCachePruneAfter )) {
1916- continue ;
1917- }
1918-
1919- // Remove the file.
1920- llvm::sys::fs::remove (File->path ());
1921-
1922- // Remove the timestamp file.
1923- std::string TimpestampFilename = File->path () + " .timestamp" ;
1924- llvm::sys::fs::remove (TimpestampFilename);
1925- }
1926-
1927- // If we removed all of the files in the directory, remove the directory
1928- // itself.
1929- if (llvm::sys::fs::directory_iterator (Dir->path (), EC) ==
1930- llvm::sys::fs::directory_iterator () && !EC)
1931- llvm::sys::fs::remove (Dir->path ());
1932- }
1933- }
1934-
19351851void CompilerInstance::createASTReader () {
19361852 if (TheASTReader)
19371853 return ;
@@ -1942,11 +1858,10 @@ void CompilerInstance::createASTReader() {
19421858 // If we're implicitly building modules but not currently recursively
19431859 // building a module, check whether we need to prune the module cache.
19441860 if (getSourceManager ().getModuleBuildStack ().empty () &&
1945- !getPreprocessor ().getHeaderSearchInfo ().getModuleCachePath ().empty () &&
1946- getHeaderSearchOpts ().ModuleCachePruneInterval > 0 &&
1947- getHeaderSearchOpts ().ModuleCachePruneAfter > 0 ) {
1948- pruneModuleCache (getHeaderSearchOpts ());
1949- }
1861+ !getPreprocessor ().getHeaderSearchInfo ().getModuleCachePath ().empty ())
1862+ ModCache->maybePrune (getHeaderSearchOpts ().ModuleCachePath ,
1863+ getHeaderSearchOpts ().ModuleCachePruneInterval ,
1864+ getHeaderSearchOpts ().ModuleCachePruneAfter );
19501865
19511866 HeaderSearchOptions &HSOpts = getHeaderSearchOpts ();
19521867 std::string Sysroot = HSOpts.Sysroot ;
0 commit comments