Commit fc93b83f authored by Jondy Zhao's avatar Jondy Zhao

Merge branch 'share-install'

parents 5b03245c e296d03b
...@@ -26,6 +26,21 @@ Supported options ...@@ -26,6 +26,21 @@ Supported options
``--prefix`` injection takes place. You can also set the ``--prefix`` ``--prefix`` injection takes place. You can also set the ``--prefix``
parameter explicitly in ``configure-options``. parameter explicitly in ``configure-options``.
``share``
Specify the path in which this package is shared by many other
packages. When it's unset or blank, it means the package isn't
shared. Otherwise, it shared by many packages. Recipe will return
an empty list so that buildout will not uninstall the package when
uninstalling part.
In share mode, ``promises`` should be set so that recipe can tell
whether the package is installed. Otherwise nohting to do.
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.
``md5sum`` ``md5sum``
MD5 checksum for the package file. If available the MD5 MD5 checksum for the package file. If available the MD5
...@@ -212,11 +227,7 @@ Supported options ...@@ -212,11 +227,7 @@ Supported options
the former will be overridden by the latter allowing per-part customization. the former will be overridden by the latter allowing per-part customization.
The recipe uses separated part to support custom options in different The recipe uses separated part to support custom options in different
platforms. These platform's part has a pattern "platform-part" or platforms. These platform's part has a pattern "part:platform".
"arch-platform-part".
arch could be 'x86', 'x86_64', 'ia64' ... which equals
platform.machine().
platform could be 'linux', 'cygwin', 'macos', 'sunos', 'freebsd', platform could be 'linux', 'cygwin', 'macos', 'sunos', 'freebsd',
'netbsd', 'unixware' ... which equals a formatted sys.platform. 'netbsd', 'unixware' ... which equals a formatted sys.platform.
...@@ -226,10 +237,10 @@ For example, ...@@ -226,10 +237,10 @@ For example,
[bzip2] [bzip2]
recipe = slapos.recipe.cmmi recipe = slapos.recipe.cmmi
[x86-cygwin-bzip2] [bzip2:cygwin]
patches = cygwin-bzip2-1.0.6.src.patch patches = cygwin-bzip2-1.0.6.src.patch
All the options in the platform-part have high priority level. All the options in the [part:platform] have high priority level.
The recipe first searches the exact match, if no found. Ignore arch The recipe first searches the exact match, if no found. Ignore arch
and search again, if still found nothing. Use no platform part. and search again, if still found nothing. Use no platform part.
...@@ -361,7 +372,7 @@ a custom location within the buildout:: ...@@ -361,7 +372,7 @@ a custom location within the buildout::
... """ % src) ... """ % src)
>>> print(system(buildout)) >>> print(system(buildout))
Uninstalling package. Uninstalling packagex.
Installing foobar. Installing foobar.
foobar: [ENV] TMP = /sample_buildout/parts/foobar/tmp foobar: [ENV] TMP = /sample_buildout/parts/foobar/tmp
foobar: Extracting package to /sample_buildout/parts/foobar__compile__ foobar: Extracting package to /sample_buildout/parts/foobar__compile__
...@@ -660,7 +671,7 @@ The recipe can specify build options for each platform. For example, ...@@ -660,7 +671,7 @@ The recipe can specify build options for each platform. For example,
... pre-configure = echo "Configure in common platform" ... pre-configure = echo "Configure in common platform"
... post-install = echo "Finished." ... post-install = echo "Finished."
... ...
... [cygwin-package] ... [package:cygwin]
... pre-configure = echo "Configure in the CYGWIN platform" ... pre-configure = echo "Configure in the CYGWIN platform"
... pre-install = echo "Installing in the CYGWIN" ... pre-install = echo "Installing in the CYGWIN"
... post-install = echo -n "CYGWIN " && ${package:post-install} ... post-install = echo -n "CYGWIN " && ${package:post-install}
...@@ -683,7 +694,7 @@ are only ``pre-configure`` and ``post-install``. the output will be ...@@ -683,7 +694,7 @@ are only ``pre-configure`` and ``post-install``. the output will be
Finished. Finished.
In the cygwin, the recipe merges the options in the parts 'package' In the cygwin, the recipe merges the options in the parts 'package'
and 'cygwin-package'. The output will be and 'package:cygwin'. The output will be
>>> print system(buildout) >>> print system(buildout)
Uninstalling package. Uninstalling package.
...@@ -700,14 +711,6 @@ and 'cygwin-package'. The output will be ...@@ -700,14 +711,6 @@ and 'cygwin-package'. The output will be
package: Executing post-install package: Executing post-install
CYGWIN Finished. CYGWIN Finished.
Arch is supported either, For example,
[x86-cygwin-package]
...
The recipe will first search part looks like "arch-platform-part",
then "platform-part".
Union prefix Union prefix
============ ============
...@@ -1062,6 +1065,53 @@ Look, "package" is reinstalled either: ...@@ -1062,6 +1065,53 @@ Look, "package" is reinstalled either:
building package building package
installing package installing package
Install share package
=====================
Use option ``share`` to install a share pacakge.
>>> write('buildout.cfg',
... """
... [buildout]
... newest = false
... parts = package
...
... [package]
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... share = /usr/local/bin
... promises = ${:share}/mypackage.exe
... """ % (src,))
>>> print system(buildout)
Uninstalling package.
Uninstalling package-2.
Installing package.
package: [ENV] TMP = /sample_buildout/parts/package/tmp
package: Extracting package to /sample_buildout/parts/package__compile__
configure --prefix=/sample_buildout/parts/package
building package
installing package
package: could not find promise "/usr/local/bin/mypackage.exe"
Do nothing if one package has been installed.
>>> write('buildout.cfg',
... """
... [buildout]
... newest = false
... parts = package
...
... [package]
... recipe = slapos.recipe.cmmi
... url = file://%s/package-0.0.0.tar.gz
... share = /usr/local/bin
... promises =
... """ % (src,))
>>> print system(buildout)
Uninstalling package.
Installing package.
package: This shared package has been installed by other package
For even more specific needs you can write your own recipe that uses For even more specific needs you can write your own recipe that uses
``slapos.recipe.cmmi`` and set the ``keep-compile-dir`` option to ``true``. ``slapos.recipe.cmmi`` and set the ``keep-compile-dir`` option to ``true``.
You can then continue from where this recipe finished by reading the location You can then continue from where this recipe finished by reading the location
......
...@@ -23,7 +23,7 @@ class Recipe(object): ...@@ -23,7 +23,7 @@ class Recipe(object):
self.name = name self.name = name
# Merge options if there is a matched platform section # Merge options if there is a matched platform section
platform_options = self.get_platform_options() platform_options = self.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:
...@@ -44,6 +44,7 @@ class Recipe(object): ...@@ -44,6 +44,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
...@@ -181,12 +182,12 @@ class Recipe(object): ...@@ -181,12 +182,12 @@ class Recipe(object):
raise zc.buildout.UserError('System error') raise zc.buildout.UserError('System error')
return files.split() return files.split()
def check_promises(self): def check_promises(self, log=None):
result = True result = True
log = logging.getLogger(self.name)
for path in self.options['promises'].splitlines(): for path in self.options['promises'].splitlines():
if not os.path.exists(path): if not os.path.exists(path):
result = False result = False
if log is not None:
log.warning('could not find promise "%s"' % path) log.warning('could not find promise "%s"' % path)
return result return result
...@@ -232,6 +233,11 @@ class Recipe(object): ...@@ -232,6 +233,11 @@ class Recipe(object):
log = logging.getLogger(self.name) log = logging.getLogger(self.name)
parts = [] parts = []
# In share mode, do nothing if package has been installed.
if (not self.options['share'] == '') and self.check_promises():
log.info('This shared package has been installed by other package')
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())
...@@ -341,7 +347,9 @@ class Recipe(object): ...@@ -341,7 +347,9 @@ 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 != '' and os.path.exists(self.buildout_prefix): if (self.buildout_prefix != ''
and self.options['share'] == ''
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))
except: except:
...@@ -353,7 +361,7 @@ class Recipe(object): ...@@ -353,7 +361,7 @@ class Recipe(object):
shutil.rmtree(tmp_path) shutil.rmtree(tmp_path)
# Check promises # Check promises
self.check_promises() 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',
...@@ -366,5 +374,6 @@ class Recipe(object): ...@@ -366,5 +374,6 @@ class Recipe(object):
shutil.rmtree(compile_dir) shutil.rmtree(compile_dir)
del self.options['compile-directory'] del self.options['compile-directory']
if self.options['share'] == '':
parts.append(self.options['location']) parts.append(self.options['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