def rmOldLocalCachedDirs(cacheDir): """Remove old local cached directories, which were created four weeks ago.""" # This is in autoBisect because it has a lock so we do not race while removing directories # Adapted from http://stackoverflow.com/a/11337407 SECONDS_IN_A_DAY = 24 * 60 * 60 s3CacheObj = s3cache.S3Cache(compileShell.S3_SHELL_CACHE_DIRNAME) if s3CacheObj.connect(): NUMBER_OF_DAYS = 1 # EC2 VMs generally have less disk space for local shell caches elif sps.isARMv7l: NUMBER_OF_DAYS = 3 # native ARM boards usually have less disk space else: NUMBER_OF_DAYS = 28 cacheDir = sps.normExpUserPath(cacheDir) names = [os.path.join(cacheDir, fname) for fname in os.listdir(cacheDir)] for name in names: if os.path.isdir(name): timediff = time.mktime(time.gmtime()) - os.stat(name).st_atime if timediff > SECONDS_IN_A_DAY * NUMBER_OF_DAYS: shutil.rmtree(name)
def obtainShell(shell, updateToRev=None, updateLatestTxt=False): """Obtain a js shell. Keep the objdir for now, especially .a files, for symbols.""" assert os.path.isdir(getLockDirPath(shell.buildOptions.repoDir)) cachedNoShell = shell.getShellCacheFullPath() + ".busted" if os.path.isfile(shell.getShellCacheFullPath()): # Don't remove the comma at the end of this line, and thus remove the newline printed. # We would break JSBugMon. print("Found cached shell...") # Assuming that since the binary is present, everything else (e.g. symbols) is also present verifyFullWinPageHeap(shell.getShellCacheFullPath()) return elif os.path.isfile(cachedNoShell): raise Exception("Found a cached shell that failed compilation...") elif os.path.isdir(shell.getShellCacheDir()): print("Found a cache dir without a successful/failed shell...") sps.rmTreeIncludingReadOnly(shell.getShellCacheDir()) os.mkdir(shell.getShellCacheDir()) hgCmds.destroyPyc(shell.buildOptions.repoDir) s3CacheObj = s3cache.S3Cache(S3_SHELL_CACHE_DIRNAME) useS3Cache = s3CacheObj.connect() if useS3Cache: if s3CacheObj.downloadFile(shell.getShellNameWithoutExt() + '.busted', shell.getShellCacheFullPath() + '.busted'): raise Exception('Found a .busted file for rev ' + shell.getHgHash()) if s3CacheObj.downloadFile(shell.getShellNameWithoutExt() + '.tar.bz2', shell.getS3TarballWithExtFullPath()): print("Extracting shell...") with tarfile.open(shell.getS3TarballWithExtFullPath(), 'r') as z: z.extractall(shell.getShellCacheDir()) # Delete tarball after downloading from S3 os.remove(shell.getS3TarballWithExtFullPath()) verifyFullWinPageHeap(shell.getShellCacheFullPath()) return try: if updateToRev: updateRepo(shell.buildOptions.repoDir, updateToRev) if shell.buildOptions.patchFile: hgCmds.patchHgRepoUsingMq(shell.buildOptions.patchFile, shell.getRepoDir()) cfgJsCompile(shell) verifyFullWinPageHeap(shell.getShellCacheFullPath()) except KeyboardInterrupt: sps.rmTreeIncludingReadOnly(shell.getShellCacheDir()) raise except Exception as e: # Remove the cache dir, but recreate it with only the .busted file. sps.rmTreeIncludingReadOnly(shell.getShellCacheDir()) os.mkdir(shell.getShellCacheDir()) createBustedFile(cachedNoShell, e) if useS3Cache: s3CacheObj.uploadFileToS3(shell.getShellCacheFullPath() + '.busted') raise finally: if shell.buildOptions.patchFile: hgCmds.hgQpopQrmAppliedPatch(shell.buildOptions.patchFile, shell.getRepoDir()) if useS3Cache: s3CacheObj.compressAndUploadDirTarball(shell.getShellCacheDir(), shell.getS3TarballWithExtFullPath()) if updateLatestTxt: # So js-dbg-64-dm-darwin-cdcd33fd6e39 becomes js-dbg-64-dm-darwin-latest.txt with # js-dbg-64-dm-darwin-cdcd33fd6e39 as its contents. txtInfo = '-'.join(shell.getS3TarballWithExt().split('-')[:-1] + ['latest']) + '.txt' s3CacheObj.uploadStrToS3('', txtInfo, shell.getS3TarballWithExt()) os.remove(shell.getS3TarballWithExtFullPath())