Commit d6ddf139 authored by Jondy Zhao's avatar Jondy Zhao

Set the value of 'location' as 'share' in case 'share' is not blank

parent ae9f451f
......@@ -37,6 +37,11 @@ Supported options
In share mode, ``promises`` should be set so that recipe can tell
whether the package is installed. Otherwise nohting to do.
If ``share`` is not empty, ``location`` will be set to value of
``share``, and remove trailing '/'. So in case ``share`` is '/',
``location`` will be set to blank. Thus any reference like
"${part:location}/bin" in other parts will get the correct value.
This option is experiment now. Recipe doesn't try to set prefix
with the valule of this opton in the configure or make command,
you should specify them accordingly by yourself.
......@@ -1078,19 +1083,19 @@ Use option ``share`` to install a share pacakge.
... [package]
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... share = /usr/local/bin
... promises = ${:share}/mypackage.exe
... share = /usr/local
... promises = ${:share}/bin/mypackage.exe
... """ % (src,))
>>> print system(buildout)
Uninstalling package.
Uninstalling package-2.
Installing package.
package: Checking whether package is installed at share path: /usr/local/bin
package: Checking whether package is installed at share path: /usr/local
package: could not find promise "/usr/local/bin/mypackage.exe"
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: Extracting package to /sample_buildout/parts/package__compile__
configure --prefix=/sample_buildout/parts/package
configure --prefix=/usr/local
building package
installing package
package: could not find promise "/usr/local/bin/mypackage.exe"
......
......@@ -29,10 +29,14 @@ class Recipe(object):
else:
self.original_options = options.copy()
options.update(platform_options)
options['location'] = os.path.join(
options['share'] = options.get('share', '').strip()
options['default-location'] = os.path.join(
buildout['buildout']['parts-directory'],
self.name)
share = options['share']
options['location'] = options['default-location'] if share == '' else share.rstrip('/')
prefix = options.get('prefix', '').strip()
if prefix == '':
prefix = self.buildout_prefix = buildout['buildout'].get('prefix', '').strip()
......@@ -44,8 +48,7 @@ class Recipe(object):
options['url'] = options.get('url', '').strip()
options['path'] = options.get('path', '').strip()
options['promises'] = options.get('promises', '')
options['share'] = options.get('share', '').strip()
# Check dependencies, all the dependent parts will be installed first. It
# seems once part is referenced, for example, self.buildout[part], it will
# be appended as an install part.
......@@ -71,7 +74,7 @@ class Recipe(object):
raise zc.buildout.UserError('You must provide either "url" or "path".')
if options['url']:
options['compile-directory'] = '%s__compile__' % options['location']
options['compile-directory'] = '%s__compile__' % options['default-location']
else:
options['compile-directory'] = options['path']
......@@ -101,7 +104,7 @@ class Recipe(object):
# environment.
for key in self.environ:
self.environ[key] = self.environ[key] % os.environ
self.environ['TMP'] = os.path.join(options['location'], 'tmp')
self.environ['TMP'] = os.path.join(options['default-location'], 'tmp')
def augmented_environment(self):
"""Returns a dictionary containing the current environment variables
......@@ -181,7 +184,7 @@ class Recipe(object):
log.error('Command failed: %s: %s' % (e, cmd))
raise zc.buildout.UserError('System error')
return files.split()
def check_promises(self, log=None):
result = True
log = logging.getLogger(self.name)
......@@ -190,7 +193,7 @@ class Recipe(object):
result = False
log.warning('could not find promise "%s"' % path)
return result
def call_script(self, script):
"""This method is copied from z3c.recipe.runscript.
......@@ -239,7 +242,7 @@ class Recipe(object):
if self.check_promises(log):
log.info('This shared package has been installed by other package')
return parts
make_cmd = self.options.get('make-binary', 'make').strip()
make_options = ' '.join(self.options.get('make-options', '').split())
make_targets = ' '.join(self.options.get('make-targets', 'install').split())
......@@ -286,7 +289,7 @@ class Recipe(object):
current_dir = os.getcwd()
try:
os.mkdir(self.options['location'])
os.mkdir(self.options['default-location'])
except OSError as e:
if e.errno == errno.EEXIST:
pass
......@@ -349,8 +352,8 @@ class Recipe(object):
if post_install_cmd != '':
log.info('Executing post-install')
self.run(post_install_cmd)
if (self.buildout_prefix != ''
and self.options['share'] == ''
if (self.buildout_prefix != ''
and self.options['share'] == ''
and os.path.exists(self.buildout_prefix)):
log.info('Getting installed file lists')
parts.extend(self.get_installed_files(tmp_path))
......@@ -364,7 +367,7 @@ class Recipe(object):
# Check promises
self.check_promises(log)
if self.options['url']:
if self.options.get('keep-compile-dir',
self.buildout['buildout'].get('keep-compile-dir', '')).lower() in ('true', 'yes', '1', 'on'):
......@@ -377,5 +380,5 @@ class Recipe(object):
del self.options['compile-directory']
if self.options['share'] == '':
parts.append(self.options['location'])
parts.append(self.options['default-location'])
return parts
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