Commit 772a4579 authored by Julien Muchembled's avatar Julien Muchembled

Small clean-up

parent 2b2df332
...@@ -31,9 +31,9 @@ class Recipe(object): ...@@ -31,9 +31,9 @@ class Recipe(object):
self.name = name self.name = name
log = logging.getLogger(self.name) log = logging.getLogger(self.name)
# Merge options if there is a matched platform section # Merge options if there is a matched platform section
platform_options = self.buildout.get( platform_options = buildout.get(
"%s:%s:%s" % (name, sys.platform, self.get_machine()), "%s:%s:%s" % (name, sys.platform, self.get_machine()),
self.buildout.get("%s:%s" % (name, sys.platform))) buildout.get("%s:%s" % (name, sys.platform)))
if platform_options is None: if platform_options is None:
self.original_options = options self.original_options = options
else: else:
...@@ -43,7 +43,8 @@ class Recipe(object): ...@@ -43,7 +43,8 @@ class Recipe(object):
shared = ((options.get('shared', '').lower() == 'true') and shared = ((options.get('shared', '').lower() == 'true') and
buildout['buildout'].get('shared-part-list', None)) buildout['buildout'].get('shared-part-list', None))
if shared: if shared:
self._signature = slapos.recipe.downloadunpacked.Signature('.slapos.recipe.cmmi.signature') self._signature = slapos.recipe.downloadunpacked.Signature(
'.slapos.recipe.cmmi.signature')
buildout_directory = buildout['buildout']['directory'] buildout_directory = buildout['buildout']['directory']
profile_base_location = options.get('_profile_base_location_', '') profile_base_location = options.get('_profile_base_location_', '')
for k, v in sorted(options.items()): for k, v in sorted(options.items()):
...@@ -52,24 +53,22 @@ class Recipe(object): ...@@ -52,24 +53,22 @@ class Recipe(object):
v = v.replace(profile_base_location, '${:_profile_base_location_}') v = v.replace(profile_base_location, '${:_profile_base_location_}')
self._signature.update(k, v) self._signature.update(k, v)
shared_parts = [part.strip().rstrip('/') signature_digest = self._signature.hexdigest()
for part in buildout['buildout']['shared-part-list'].splitlines() for x in shared.splitlines():
if part.strip()] x = x.strip().rstrip('/')
for shared in shared_parts: if x:
shared = os.path.join(os.path.join(shared, self.name), self._signature.hexdigest()) shared = os.path.join(os.path.join(x, self.name),
if os.path.exists(shared): signature_digest)
break if os.path.exists(shared):
else: break
shared = os.path.join(os.path.join(shared_parts[-1], self.name), self._signature.hexdigest()) log.info('shared at %s', shared)
log.info('shared directory %s set for %s', shared, self.name)
else: else:
shared = '' shared = ''
options['shared'] = shared options['shared'] = shared
default_location = options['default-location'] = os.path.join( location = options['location'] = shared or os.path.join(
buildout['buildout']['parts-directory'], buildout['buildout']['parts-directory'],
self.name) if shared == '' else shared self.name)
options['location'] = options['default-location']
prefix = options.get('prefix', '').strip() prefix = options.get('prefix', '').strip()
if prefix == '': if prefix == '':
...@@ -78,7 +77,7 @@ class Recipe(object): ...@@ -78,7 +77,7 @@ class Recipe(object):
self.buildout_prefix = '' self.buildout_prefix = ''
else: else:
self.buildout_prefix = '' self.buildout_prefix = ''
options['prefix'] = options['location'] if prefix == '' else prefix options['prefix'] = prefix or location
options['url'] = options.get('url', '').strip() options['url'] = options.get('url', '').strip()
options['path'] = options.get('path', '').strip() options['path'] = options.get('path', '').strip()
options['promises'] = options.get('promises', '') options['promises'] = options.get('promises', '')
...@@ -108,13 +107,13 @@ class Recipe(object): ...@@ -108,13 +107,13 @@ class Recipe(object):
raise zc.buildout.UserError('You must provide either "url" or "path".') raise zc.buildout.UserError('You must provide either "url" or "path".')
if options['url']: if options['url']:
options['compile-directory'] = '%s__compile__' % options['default-location'] options['compile-directory'] = location + '__compile__'
else: else:
options['compile-directory'] = options['path'] options['compile-directory'] = options['path']
for k, v in list(options.items()): for k, v in list(options.items()):
if '@@LOCATION@@' in v: if '@@LOCATION@@' in v:
options[k] = v.replace('@@LOCATION@@', default_location) options[k] = v.replace('@@LOCATION@@', location)
self.environ = {} self.environ = {}
self.original_environment = os.environ.copy() self.original_environment = os.environ.copy()
...@@ -123,7 +122,7 @@ class Recipe(object): ...@@ -123,7 +122,7 @@ class Recipe(object):
if environment_section and environment_section in buildout: if environment_section and environment_section in buildout:
# Use environment variables from the designated config section. # Use environment variables from the designated config section.
self.environ.update(buildout[environment_section]) self.environ.update(buildout[environment_section])
for variable in self.options.get('environment', '').splitlines(): for variable in options.get('environment', '').splitlines():
if variable.strip(): if variable.strip():
try: try:
key, value = variable.split('=', 1) key, value = variable.split('=', 1)
...@@ -138,7 +137,7 @@ class Recipe(object): ...@@ -138,7 +137,7 @@ class Recipe(object):
self.environ['CXXFLAGS'] = '-I%s/include %s' % (self.buildout_prefix, self.environ.get('CXXFLAGS', '')) self.environ['CXXFLAGS'] = '-I%s/include %s' % (self.buildout_prefix, self.environ.get('CXXFLAGS', ''))
self.environ['LDFLAGS'] = '-L%s/lib %s' % (self.buildout_prefix, self.environ.get('LDFLAGS', '')) self.environ['LDFLAGS'] = '-L%s/lib %s' % (self.buildout_prefix, self.environ.get('LDFLAGS', ''))
if self.options.get('configure-command', '').strip() == 'cygport': if options.get('configure-command') == 'cygport':
self.environ.setdefault('CYGCONF_PREFIX', options['prefix']) self.environ.setdefault('CYGCONF_PREFIX', options['prefix'])
# Extrapolate the environment variables using values from the current # Extrapolate the environment variables using values from the current
...@@ -324,15 +323,14 @@ class Recipe(object): ...@@ -324,15 +323,14 @@ class Recipe(object):
compile_dir = self.options['path'] compile_dir = self.options['path']
current_dir = os.getcwd() current_dir = os.getcwd()
location = self.options['default-location'] location = self.options['location']
# Clean the install directory if it already exists as it is # Clean the install directory if it already exists as it is
# a remain from a previous failed installation # a remain from a previous failed installation
if os.path.exists(location): if os.path.exists(location):
shutil.rmtree(location) shutil.rmtree(location)
os.mkdir(location) os.mkdir(location)
os.chdir(compile_dir)
try: try:
os.chdir(compile_dir)
try: try:
# We support packages that either extract contents to the $PWD # We support packages that either extract contents to the $PWD
# or alternatively have a single directory. # or alternatively have a single directory.
......
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