import os.path
import stat
-import string
import sys
import SCons.Action
+cache_enabled = True
cache_debug = False
cache_force = False
cache_show = False
if fs.islink(cachefile):
fs.symlink(fs.readlink(cachefile), t.path)
else:
- fs.copy2(cachefile, t.path)
+ env.copy_from_cache(cachefile, t.path)
st = fs.stat(cachefile)
fs.chmod(t.path, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
return 0
# has beaten us creating the directory.
if not fs.isdir(cachedir):
msg = errfmt % (str(target), cachefile)
- raise SCons.Errors.EnvironmentError, msg
+ raise SCons.Errors.EnvironmentError(msg)
try:
if fs.islink(t.path):
except ImportError:
msg = "No hashlib or MD5 module available, CacheDir() not supported"
SCons.Warnings.warn(SCons.Warnings.NoMD5ModuleWarning, msg)
+ self.path = None
else:
self.path = path
+ self.current_cache_debug = None
+ self.debugFP = None
- def CacheDebugWrite(self, fmt, target, cachefile):
- self.debugFP.write(fmt % (target, os.path.split(cachefile)[1]))
-
- def CacheDebugQuiet(self, fmt, target, cachefile):
- pass
-
- def CacheDebugInit(self, fmt, target, cachefile):
- if cache_debug:
+ def CacheDebug(self, fmt, target, cachefile):
+ if cache_debug != self.current_cache_debug:
if cache_debug == '-':
self.debugFP = sys.stdout
- else:
+ elif cache_debug:
self.debugFP = open(cache_debug, 'w')
- self.CacheDebug = self.CacheDebugWrite
- self.CacheDebug(fmt, target, cachefile)
- else:
- self.CacheDebug = self.CacheDebugQuiet
+ else:
+ self.debugFP = None
+ self.current_cache_debug = cache_debug
+ if self.debugFP:
+ self.debugFP.write(fmt % (target, os.path.split(cachefile)[1]))
- CacheDebug = CacheDebugInit
+ def is_enabled(self):
+ return (cache_enabled and not self.path is None)
def cachepath(self, node):
"""
"""
+ if not self.is_enabled():
+ return None, None
+
sig = node.get_cachedir_bsig()
- subdir = string.upper(sig[0])
+ subdir = sig[0].upper()
dir = os.path.join(self.path, subdir)
return dir, os.path.join(dir, sig)
execute the CacheRetrieveFunc and then have the latter
explicitly check SCons.Action.execute_actions itself.
"""
- retrieved = False
+ if not self.is_enabled():
+ return False
+ env = node.get_build_env()
if cache_show:
- if CacheRetrieveSilent(node, [], node.get_build_env(), execute=1) == 0:
+ if CacheRetrieveSilent(node, [], env, execute=1) == 0:
node.build(presub=0, execute=0)
- retrieved = 1
+ return True
else:
- if CacheRetrieve(node, [], node.get_build_env(), execute=1) == 0:
- retrieved = 1
- if retrieved:
- # Record build signature information, but don't
- # push it out to cache. (We just got it from there!)
- node.set_state(SCons.Node.executed)
- SCons.Node.Node.built(node)
+ if CacheRetrieve(node, [], env, execute=1) == 0:
+ return True
- return retrieved
+ return False
def push(self, node):
+ if not self.is_enabled():
+ return
return CachePush(node, [], node.get_build_env())
def push_if_forced(self, node):
if cache_force:
return self.push(node)
-class Null(SCons.Util.Null):
- def repr(self):
- return 'CacheDir.Null()'
- def cachepath(self, node):
- return None, None
- def retrieve(self, node):
- return False
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: