Commit 25b82a62 authored by Jérome Perrin's avatar Jérome Perrin

WIP debugging patches to try shared

parent e0d96fc4
......@@ -44,7 +44,7 @@ class Recipe(object):
if shared:
# If shard is not a path
# use default one
if not os.path.isdir(shared):
if not os.path.isdir(shared): # XXX do we need this ??? isn't it enough to use download cache
# Check if provide default location in buildout
shared = buildout['buildout'].get('download-cache', None)
if not shared:
......@@ -57,14 +57,24 @@ class Recipe(object):
# create shared dir if not exist
if not os.path.exists(shared):
os.makedirs(shared)
self._debug_signature_text = []
# compute hash from options
# XXX we should include all referenced parts !!!
m = md5()
buildout_directory = buildout['buildout']['directory']
for k, v in sorted(options.items()):
m.update(('%r: %r' % (k, v)).encode())
option_signature = ('%r: %r' % (k, v)).encode()
log.debug("Updating hash with %s", option_signature)
self._debug_signature_text.append(option_signature)
assert buildout_directory not in option_signature # XXX or maybe warn and disable cache ?
m.update(option_signature)
shared = os.path.join(shared, m.hexdigest())
log.info('download cache directory %s set for %s' % (shared, self.name))
options['shared'] = shared
options['default-location'] = os.path.join(
default_location = options['default-location'] = os.path.join(
buildout['buildout']['parts-directory'],
self.name) if shared == '' else shared
options['location'] = options['default-location'] if shared == '' else shared
......@@ -110,6 +120,12 @@ class Recipe(object):
else:
options['compile-directory'] = options['path']
from copy import copy
for k, v in copy(options.items()):
# XXX options will no longer be reported as unused ?
if '@@LOCATION@@' in v:
options[k] = v.replace('@@LOCATION@@', default_location)
self.environ = {}
self.original_environment = os.environ.copy()
......@@ -336,6 +352,13 @@ class Recipe(object):
shutil.rmtree(tmp_path, True)
os.mkdir(tmp_path)
# Create a debug file with the signatures.
if self.options['shared']:
with open(os.path.join(
self.options["shared"],
".slapos.recipe.cmmi.signature"), 'w') as f:
f.write('\n'.join(self._debug_signature_text))
try:
try:
# We support packages that either extract contents to the $PWD
......@@ -398,10 +421,13 @@ class Recipe(object):
except:
log.error('Compilation error. The package is left as is at %s where '
'you can inspect what went wrong' % os.getcwd())
if self.options.get('shared'):
shutil.rmtree(self.options['shared'])
raise
finally:
os.chdir(current_dir)
shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path): # if it's in shared it was deleted. XXX use another path ??
shutil.rmtree(tmp_path)
# Check promises
self.check_promises(log)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment