Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit ee043e3

Browse files
committed
Add CLCACHE_RECACHE feature
Just like in ccache, this puts clcache into a "write-only" mode. Objects will be stored in the cache, but objects already in the cache will not be reused. The real compiler is always used. This is useful in CI when you have a release branch that you want to always use the real compiler, and feature branches that you want to reap the benefit of the cache generated from the release branch. In that case you would enable CLCACHE_RECACHE only when building from the release branch.
1 parent dd7bf50 commit ee043e3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ CLCACHE_LOG::
6565
CLCACHE_DISABLE::
6666
Setting this variable will disable 'clcache.py' completely. The script will
6767
relay all calls to the real compiler.
68+
CLCACHE_RECACHE::
69+
Setting this variable will prevent clcache from retrieving files stored in its
70+
cache. It will still store object files in the cache (possibly overwriting
71+
those already present) but they will always be rebuilt using the real compiler.
6872
CLCACHE_HARDLINK::
6973
If this variable is set, cached object files won't be copied to their
7074
final location. Instead, hard links pointing to the cached object files

clcache/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ def cachedObjectName(self, key):
377377
return os.path.join(self.cacheEntryDir(key), CompilerArtifactsSection.OBJECT_FILE)
378378

379379
def hasEntry(self, key):
380+
if 'CLCACHE_RECACHE' in os.environ:
381+
return False
380382
return os.path.exists(self.cacheEntryDir(key))
381383

382384
def setEntry(self, key, artifacts):
@@ -395,6 +397,10 @@ def setEntry(self, key, artifacts):
395397
if artifacts.stderr != '':
396398
setCachedCompilerConsoleOutput(os.path.join(tempEntryDir, CompilerArtifactsSection.STDERR_FILE),
397399
artifacts.stderr)
400+
if 'CLCACHE_RECACHE' in os.environ:
401+
if os.path.exists(cacheEntryDir):
402+
rmtree(cacheEntryDir)
403+
size = -1
398404
# Replace the full cache entry atomically
399405
os.replace(tempEntryDir, cacheEntryDir)
400406
return size
@@ -1493,7 +1499,8 @@ def addObjectToCache(stats, cache, cachekey, artifacts):
14931499
size = cache.setEntry(cachekey, artifacts)
14941500
if size is None:
14951501
size = os.path.getsize(artifacts.objectFilePath)
1496-
stats.registerCacheEntry(size)
1502+
if size >= 0: # negative size means an existing cache entry was overwritten
1503+
stats.registerCacheEntry(size)
14971504

14981505
with cache.configuration as cfg:
14991506
return stats.currentCacheSize() >= cfg.maximumCacheSize()

0 commit comments

Comments
 (0)