package.py : extra arguments, fixed inheritance issue

- added attribute to hold extra arguments in PackageBase instances
- fixed registration from within packages
- examples : hdf5, lzo
This commit is contained in:
alalazo 2016-07-12 21:28:09 +02:00
parent 813cb032c4
commit 97c2224cd6
3 changed files with 40 additions and 21 deletions

View file

@ -40,6 +40,8 @@
import time
import functools
import inspect
import copy
from StringIO import StringIO
from urlparse import urlparse
@ -135,7 +137,17 @@ def _append_checks(check_name):
checks = getattr(meta, attr_name)
if checks:
for phase_name, funcs in checks.items():
phase = attr_dict.get(PackageMeta.phase_fmt.format(phase_name))
try:
# Search for the phase in the attribute dictionary
phase = attr_dict[PackageMeta.phase_fmt.format(phase_name)]
except KeyError:
# If it is not there it's in the bases
# and we added a check. We need to copy
# and extend
for base in bases:
phase = getattr(base, PackageMeta.phase_fmt.format(phase_name), None)
attr_dict[PackageMeta.phase_fmt.format(phase_name)] = copy.deepcopy(phase)
phase = attr_dict[PackageMeta.phase_fmt.format(phase_name)]
getattr(phase, check_name).extend(funcs)
# Clear the attribute for the next class
setattr(meta, attr_name, {})
@ -511,6 +523,8 @@ def __init__(self, spec):
if self.is_extension:
spack.repo.get(self.extendee_spec)._check_extendable()
self.extra_args = {}
@property
def package_dir(self):
"""Return the directory where the package.py file lives."""

View file

@ -27,7 +27,7 @@
import shutil
class Hdf5(Package):
class Hdf5(AutotoolsPackage):
"""HDF5 is a data model, library, and file format for storing and managing
data. It supports an unlimited variety of datatypes, and is designed for
flexible and efficient I/O and for high volume and complex data.
@ -58,13 +58,15 @@ class Hdf5(Package):
depends_on("szip", when='+szip')
depends_on("zlib")
def validate(self, spec):
@AutotoolsPackage.precondition('configure')
def validate(self):
"""
Checks if incompatible variants have been activated at the same time
:param spec: spec of the package
:raises RuntimeError: in case of inconsistencies
"""
spec = self.spec
if '+fortran' in spec and not self.compiler.fc:
msg = 'cannot build a fortran variant without a fortran compiler'
raise RuntimeError(msg)
@ -73,8 +75,8 @@ def validate(self, spec):
msg = 'cannot use variant +threadsafe with either +cxx or +fortran'
raise RuntimeError(msg)
def install(self, spec, prefix):
self.validate(spec)
def configure_args(self):
spec = self.spec
# Handle compilation after spec validation
extra_args = []
@ -137,16 +139,19 @@ def install(self, spec, prefix):
'--disable-hl',
])
configure(
"--prefix=%s" % prefix,
"--with-zlib=%s" % spec['zlib'].prefix,
*extra_args)
make()
make("install")
self.check_install(spec)
return ["--with-zlib=%s" % spec['zlib'].prefix] + extra_args
#configure(
# "--prefix=%s" % prefix,
# "--with-zlib=%s" % spec['zlib'].prefix,
# *extra_args)
#make()
#make("install")
#self.check_install(spec)
def check_install(self, spec):
@AutotoolsPackage.sanity_check('install')
def check_install(self):
"Build and run a small program to test the installed HDF5 library"
spec = self.spec
print "Checking HDF5 installation..."
checkdir = "spack-check"
with working_dir(checkdir, create=True):

View file

@ -25,7 +25,7 @@
from spack import *
class Lzo(Package):
class Lzo(AutotoolsPackage):
"""Real-time data compression library"""
homepage = 'https://www.oberhumer.com/opensource/lzo/'
@ -37,13 +37,13 @@ class Lzo(Package):
version('2.06', '95380bd4081f85ef08c5209f4107e9f8')
version('2.05', 'c67cda5fa191bab761c7cb06fe091e36')
def install(self, spec, prefix):
configure_args = [
'--prefix={0}'.format(prefix),
def configure_args(self):
return [
'--disable-dependency-tracking',
'--enable-shared'
]
configure(*configure_args)
make()
@AutotoolsPackage.sanity_check('build')
def check(self):
if self.extra_args.get('build-tests', False):
make('check')
make('install')