package.py : added CMakePackage, changed qhull, ibmisc, openjpeg to work as examples

This commit is contained in:
alalazo 2016-07-13 17:36:06 +02:00
parent ad16830f71
commit 7cedd620f1
4 changed files with 161 additions and 125 deletions

View file

@ -33,15 +33,14 @@
rundown on spack and how it differs from homebrew, look at the rundown on spack and how it differs from homebrew, look at the
README. README.
""" """
import os import copy
import re
import string
import textwrap
import time
import functools import functools
import inspect import inspect
import copy import os
import platform
import re
import textwrap
import time
from StringIO import StringIO from StringIO import StringIO
from urlparse import urlparse from urlparse import urlparse
@ -65,7 +64,7 @@
from spack.stage import Stage, ResourceStage, StageComposite from spack.stage import Stage, ResourceStage, StageComposite
from spack.util.compression import allowed_archive from spack.util.compression import allowed_archive
from spack.util.environment import dump_environment from spack.util.environment import dump_environment
from spack.util.executable import ProcessError, which from spack.util.executable import ProcessError
from spack.version import * from spack.version import *
"""Allowed URL schemes for spack packages.""" """Allowed URL schemes for spack packages."""
@ -1644,6 +1643,49 @@ def install(self, spec, prefix):
PackageBase.sanity_check('install')(PackageBase.sanity_check_prefix) PackageBase.sanity_check('install')(PackageBase.sanity_check_prefix)
class CMakePackage(PackageBase):
phases = ['cmake', 'build', 'install']
def build_type(self):
return 'RelWithDebInfo'
@property
def std_cmake_args(self):
# standard CMake arguments
args = ['-DCMAKE_INSTALL_PREFIX:PATH={0}'.format(self.prefix),
'-DCMAKE_BUILD_TYPE:STRING={0}'.format(self.build_type())]
if platform.mac_ver()[0]:
args.append('-DCMAKE_FIND_FRAMEWORK:STRING=LAST')
# Set up CMake rpath
args.append('-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=FALSE')
rpaths = ':'.join(spack.build_environment.get_rpaths(self))
args.append('-DCMAKE_INSTALL_RPATH:STRING={0}'.format(rpaths))
return args
def wdir(self):
return join_path(self.stage.source_path, 'spack-build')
def cmake_args(self):
return list()
def cmake(self, spec, prefix):
options = [self.source_directory] + self.std_cmake_args + self.cmake_args()
create = not os.path.exists(self.wdir())
with working_dir(self.wdir(), create=create):
inspect.getmodule(self).cmake(*options)
def build(self, spec, prefix):
with working_dir(self.wdir()):
inspect.getmodule(self).make()
def install(self, spec, prefix):
with working_dir(self.wdir()):
inspect.getmodule(self).make('install')
PackageBase.sanity_check('install')(PackageBase.sanity_check_prefix)
def install_dependency_symlinks(pkg, spec, prefix): def install_dependency_symlinks(pkg, spec, prefix):
"""Execute a dummy install and flatten dependencies""" """Execute a dummy install and flatten dependencies"""
flatten_dependencies(spec, prefix) flatten_dependencies(spec, prefix)
@ -1753,107 +1795,107 @@ def _hms(seconds):
# os.chmod(path, mode) # os.chmod(path, mode)
class CMakePackage(PackageBase): # class CMakePackage(PackageBase):
phases = ['configure', 'build', 'install', 'provenance'] # phases = ['configure', 'build', 'install', 'provenance']
def make_make(self):
import multiprocessing
# number of jobs spack will to build with.
jobs = multiprocessing.cpu_count()
if not self.parallel:
jobs = 1
elif self.make_jobs:
jobs = self.make_jobs
make = spack.build_environment.MakeExecutable('make', jobs)
return make
def configure_args(self):
"""Returns package-specific arguments to be provided to the configure command."""
return list()
def configure_env(self):
"""Returns package-specific environment under which the configure command should be run."""
# FIXME : Why not EnvironmentModules and the hooks that PackageBase already provides ?
return dict()
def spack_transitive_include_path(self):
return ';'.join(
os.path.join(dep, 'include')
for dep in os.environ['SPACK_DEPENDENCIES'].split(os.pathsep)
)
def setup(self, spec, prefix):
cmd = [str(which('cmake'))] + \
spack.build_environment.get_std_cmake_args(self) + \
['-DCMAKE_INSTALL_PREFIX=%s' % os.environ['SPACK_PREFIX'],
'-DCMAKE_C_COMPILER=%s' % os.environ['SPACK_CC'],
'-DCMAKE_CXX_COMPILER=%s' % os.environ['SPACK_CXX'],
'-DCMAKE_Fortran_COMPILER=%s' % os.environ['SPACK_FC']] + \
self.configure_args()
env = dict()
env['PATH'] = os.environ['PATH']
env['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.spack_transitive_include_path()
env['CMAKE_PREFIX_PATH'] = os.environ['CMAKE_PREFIX_PATH']
setup_fname = 'spconfig.py'
with open(setup_fname, 'w') as fout:
fout.write(\
r"""#!%s
# #
# def make_make(self):
import sys # import multiprocessing
import os # # number of jobs spack will to build with.
import subprocess # jobs = multiprocessing.cpu_count()
# if not self.parallel:
def cmdlist(str): # jobs = 1
return list(x.strip().replace("'",'') for x in str.split('\n') if x) # elif self.make_jobs:
env = dict(os.environ) # jobs = self.make_jobs
""" % sys.executable) #
# make = spack.build_environment.MakeExecutable('make', jobs)
env_vars = sorted(list(env.keys())) # return make
for name in env_vars: #
val = env[name] # def configure_args(self):
if string.find(name, 'PATH') < 0: # """Returns package-specific arguments to be provided to the configure command."""
fout.write('env[%s] = %s\n' % (repr(name),repr(val))) # return list()
else: #
if name == 'SPACK_TRANSITIVE_INCLUDE_PATH': # def configure_env(self):
sep = ';' # """Returns package-specific environment under which the configure command should be run."""
else: # # FIXME : Why not EnvironmentModules and the hooks that PackageBase already provides ?
sep = ':' # return dict()
#
fout.write('env[%s] = "%s".join(cmdlist("""\n' % (repr(name),sep)) # def spack_transitive_include_path(self):
for part in string.split(val, sep): # return ';'.join(
fout.write(' %s\n' % part) # os.path.join(dep, 'include')
fout.write('"""))\n') # for dep in os.environ['SPACK_DEPENDENCIES'].split(os.pathsep)
# )
fout.write("env['CMAKE_TRANSITIVE_INCLUDE_PATH'] = env['SPACK_TRANSITIVE_INCLUDE_PATH'] # Deprecated\n") #
fout.write('\ncmd = cmdlist("""\n') # def setup(self, spec, prefix):
fout.write('%s\n' % cmd[0]) # cmd = [str(which('cmake'))] + \
for arg in cmd[1:]: # spack.build_environment.get_std_cmake_args(self) + \
fout.write(' %s\n' % arg) # ['-DCMAKE_INSTALL_PREFIX=%s' % os.environ['SPACK_PREFIX'],
fout.write('""") + sys.argv[1:]\n') # '-DCMAKE_C_COMPILER=%s' % os.environ['SPACK_CC'],
fout.write('\nproc = subprocess.Popen(cmd, env=env)\nproc.wait()\n') # '-DCMAKE_CXX_COMPILER=%s' % os.environ['SPACK_CXX'],
set_executable(setup_fname) # '-DCMAKE_Fortran_COMPILER=%s' % os.environ['SPACK_FC']] + \
# self.configure_args()
def configure(self, spec, prefix): #
cmake = which('cmake') # env = dict()
with working_dir(self.build_directory, create=True): # env['PATH'] = os.environ['PATH']
os.environ.update(self.configure_env()) # env['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.spack_transitive_include_path()
os.environ['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.spack_transitive_include_path() # env['CMAKE_PREFIX_PATH'] = os.environ['CMAKE_PREFIX_PATH']
options = self.configure_args() + spack.build_environment.get_std_cmake_args(self) #
cmake(self.source_directory, *options) # setup_fname = 'spconfig.py'
# with open(setup_fname, 'w') as fout:
def build(self, spec, prefix): # fout.write(\
make = self.make_make() # r"""#!%s
with working_dir(self.build_directory, create=False): # #
make() #
# import sys
def install(self, spec, prefix): # import os
make = self.make_make() # import subprocess
with working_dir(self.build_directory, create=False): #
make('install') # def cmdlist(str):
# return list(x.strip().replace("'",'') for x in str.split('\n') if x)
# env = dict(os.environ)
# """ % sys.executable)
#
# env_vars = sorted(list(env.keys()))
# for name in env_vars:
# val = env[name]
# if string.find(name, 'PATH') < 0:
# fout.write('env[%s] = %s\n' % (repr(name),repr(val)))
# else:
# if name == 'SPACK_TRANSITIVE_INCLUDE_PATH':
# sep = ';'
# else:
# sep = ':'
#
# fout.write('env[%s] = "%s".join(cmdlist("""\n' % (repr(name),sep))
# for part in string.split(val, sep):
# fout.write(' %s\n' % part)
# fout.write('"""))\n')
#
# fout.write("env['CMAKE_TRANSITIVE_INCLUDE_PATH'] = env['SPACK_TRANSITIVE_INCLUDE_PATH'] # Deprecated\n")
# fout.write('\ncmd = cmdlist("""\n')
# fout.write('%s\n' % cmd[0])
# for arg in cmd[1:]:
# fout.write(' %s\n' % arg)
# fout.write('""") + sys.argv[1:]\n')
# fout.write('\nproc = subprocess.Popen(cmd, env=env)\nproc.wait()\n')
# set_executable(setup_fname)
#
# def configure(self, spec, prefix):
# cmake = which('cmake')
# with working_dir(self.build_directory, create=True):
# os.environ.update(self.configure_env())
# os.environ['SPACK_TRANSITIVE_INCLUDE_PATH'] = self.spack_transitive_include_path()
# options = self.configure_args() + spack.build_environment.get_std_cmake_args(self)
# cmake(self.source_directory, *options)
#
# def build(self, spec, prefix):
# make = self.make_make()
# with working_dir(self.build_directory, create=False):
# make()
#
# def install(self, spec, prefix):
# make = self.make_make()
# with working_dir(self.build_directory, create=False):
# make('install')
class FetchError(spack.error.SpackError): class FetchError(spack.error.SpackError):

View file

@ -34,7 +34,7 @@ class Ibmisc(CMakePackage):
depends_on('cmake') depends_on('cmake')
depends_on('doxygen') depends_on('doxygen')
def configure_args(self): def cmake_args(self):
spec = self.spec spec = self.spec
return [ return [
'-DUSE_EVERYTRACE=%s' % ('YES' if '+everytrace' in spec else 'NO'), '-DUSE_EVERYTRACE=%s' % ('YES' if '+everytrace' in spec else 'NO'),

View file

@ -25,9 +25,9 @@
from spack import * from spack import *
class Openjpeg(Package): class Openjpeg(CMakePackage):
""" """OpenJPEG is an open-source JPEG 2000 codec written in C language.
OpenJPEG is an open-source JPEG 2000 codec written in C language.
It has been developed in order to promote the use of JPEG 2000, a It has been developed in order to promote the use of JPEG 2000, a
still-image compression standard from the Joint Photographic still-image compression standard from the Joint Photographic
Experts Group (JPEG). Experts Group (JPEG).
@ -35,7 +35,7 @@ class Openjpeg(Package):
ITU-T as a JPEG 2000 Reference Software. ITU-T as a JPEG 2000 Reference Software.
""" """
homepage = "https://github.com/uclouvain/openjpeg" homepage = "https://github.com/uclouvain/openjpeg"
url = "https://github.com/uclouvain/openjpeg/archive/version.2.1.tar.gz" url = "https://github.com/uclouvain/openjpeg/archive/version.2.1.tar.gz"
version('2.1', '3e1c451c087f8462955426da38aa3b3d') version('2.1', '3e1c451c087f8462955426da38aa3b3d')
version('2.0.1', '105876ed43ff7dbb2f90b41b5a43cfa5') version('2.0.1', '105876ed43ff7dbb2f90b41b5a43cfa5')
@ -44,9 +44,3 @@ class Openjpeg(Package):
version('1.5.1', 'd774e4b5a0db5f0f171c4fc0aabfa14e') version('1.5.1', 'd774e4b5a0db5f0f171c4fc0aabfa14e')
depends_on('cmake') depends_on('cmake')
def install(self, spec, prefix):
cmake('.', *std_cmake_args)
make()
make("install")

View file

@ -24,7 +24,8 @@
############################################################################## ##############################################################################
from spack import * from spack import *
class Qhull(Package):
class Qhull(CMakePackage):
"""Qhull computes the convex hull, Delaunay triangulation, Voronoi """Qhull computes the convex hull, Delaunay triangulation, Voronoi
diagram, halfspace intersection about a point, furt hest-site diagram, halfspace intersection about a point, furt hest-site
Delaunay triangulation, and furthest-site Voronoi diagram. The Delaunay triangulation, and furthest-site Voronoi diagram. The
@ -47,8 +48,7 @@ class Qhull(Package):
depends_on('cmake') depends_on('cmake')
def install(self, spec, prefix): @CMakePackage.sanity_check('build')
with working_dir('spack-build', create=True): @CMakePackage.on_package_attributes(run_tests=True)
cmake('..', *std_cmake_args) def check(self):
make() make('test')
make("install")