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