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