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

Commit

Permalink
Add CLCACHE_RECACHE feature
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oktal3700 committed Feb 17, 2019
1 parent dd7bf50 commit ee043e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ CLCACHE_LOG::
CLCACHE_DISABLE::
Setting this variable will disable 'clcache.py' completely. The script will
relay all calls to the real compiler.
CLCACHE_RECACHE::
Setting this variable will prevent clcache from retrieving files stored in its
cache. It will still store object files in the cache (possibly overwriting
those already present) but they will always be rebuilt using the real compiler.
CLCACHE_HARDLINK::
If this variable is set, cached object files won't be copied to their
final location. Instead, hard links pointing to the cached object files
Expand Down
9 changes: 8 additions & 1 deletion clcache/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ def cachedObjectName(self, key):
return os.path.join(self.cacheEntryDir(key), CompilerArtifactsSection.OBJECT_FILE)

def hasEntry(self, key):
if 'CLCACHE_RECACHE' in os.environ:
return False
return os.path.exists(self.cacheEntryDir(key))

def setEntry(self, key, artifacts):
Expand All @@ -395,6 +397,10 @@ def setEntry(self, key, artifacts):
if artifacts.stderr != '':
setCachedCompilerConsoleOutput(os.path.join(tempEntryDir, CompilerArtifactsSection.STDERR_FILE),
artifacts.stderr)
if 'CLCACHE_RECACHE' in os.environ:
if os.path.exists(cacheEntryDir):
rmtree(cacheEntryDir)
size = -1
# Replace the full cache entry atomically
os.replace(tempEntryDir, cacheEntryDir)
return size
Expand Down Expand Up @@ -1493,7 +1499,8 @@ def addObjectToCache(stats, cache, cachekey, artifacts):
size = cache.setEntry(cachekey, artifacts)
if size is None:
size = os.path.getsize(artifacts.objectFilePath)
stats.registerCacheEntry(size)
if size >= 0: # negative size means an existing cache entry was overwritten
stats.registerCacheEntry(size)

with cache.configuration as cfg:
return stats.currentCacheSize() >= cfg.maximumCacheSize()
Expand Down

0 comments on commit ee043e3

Please sign in to comment.