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): ...@@ -44,7 +44,7 @@ class Recipe(object):
if shared: if shared:
# If shard is not a path # If shard is not a path
# use default one # 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 # Check if provide default location in buildout
shared = buildout['buildout'].get('download-cache', None) shared = buildout['buildout'].get('download-cache', None)
if not shared: if not shared:
...@@ -57,14 +57,24 @@ class Recipe(object): ...@@ -57,14 +57,24 @@ class Recipe(object):
# create shared dir if not exist # create shared dir if not exist
if not os.path.exists(shared): if not os.path.exists(shared):
os.makedirs(shared) os.makedirs(shared)
self._debug_signature_text = []
# compute hash from options
# XXX we should include all referenced parts !!!
m = md5() m = md5()
buildout_directory = buildout['buildout']['directory']
for k, v in sorted(options.items()): 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()) shared = os.path.join(shared, m.hexdigest())
log.info('download cache directory %s set for %s' % (shared, self.name)) log.info('download cache directory %s set for %s' % (shared, self.name))
options['shared'] = shared options['shared'] = shared
options['default-location'] = os.path.join( default_location = options['default-location'] = os.path.join(
buildout['buildout']['parts-directory'], buildout['buildout']['parts-directory'],
self.name) if shared == '' else shared self.name) if shared == '' else shared
options['location'] = options['default-location'] if shared == '' else shared options['location'] = options['default-location'] if shared == '' else shared
...@@ -110,6 +120,12 @@ class Recipe(object): ...@@ -110,6 +120,12 @@ class Recipe(object):
else: else:
options['compile-directory'] = options['path'] 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.environ = {}
self.original_environment = os.environ.copy() self.original_environment = os.environ.copy()
...@@ -336,6 +352,13 @@ class Recipe(object): ...@@ -336,6 +352,13 @@ class Recipe(object):
shutil.rmtree(tmp_path, True) shutil.rmtree(tmp_path, True)
os.mkdir(tmp_path) 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:
try: try:
# We support packages that either extract contents to the $PWD # We support packages that either extract contents to the $PWD
...@@ -398,9 +421,12 @@ class Recipe(object): ...@@ -398,9 +421,12 @@ class Recipe(object):
except: except:
log.error('Compilation error. The package is left as is at %s where ' log.error('Compilation error. The package is left as is at %s where '
'you can inspect what went wrong' % os.getcwd()) 'you can inspect what went wrong' % os.getcwd())
if self.options.get('shared'):
shutil.rmtree(self.options['shared'])
raise raise
finally: finally:
os.chdir(current_dir) os.chdir(current_dir)
if os.path.isdir(tmp_path): # if it's in shared it was deleted. XXX use another path ??
shutil.rmtree(tmp_path) shutil.rmtree(tmp_path)
# Check promises # Check promises
......
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