324 lines
14 KiB
Python
324 lines
14 KiB
Python
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
|
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
|
#
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# If you submit this package back to Spack as a pull request,
|
|
# please first remove this boilerplate and all FIXME comments.
|
|
#
|
|
# This is a template package file for Spack. We've put "FIXME"
|
|
# next to all the things you'll want to change. Once you've handled
|
|
# them, you can save this file and test your package like this:
|
|
#
|
|
# spack install dune
|
|
#
|
|
# You can edit this file again by typing:
|
|
#
|
|
# spack edit dune
|
|
#
|
|
# See the Spack documentation for more information on packaging.
|
|
# ----------------------------------------------------------------------------
|
|
|
|
import os
|
|
from spack import *
|
|
try:
|
|
from collections.abc import Sequence
|
|
except ImportError:
|
|
from collections import Sequence
|
|
import spack.error as error
|
|
|
|
class Dune(CMakePackage):
|
|
"""
|
|
DUNE, the Distributed and Unified Numerics Environment is a modular toolbox for solving partial differential equations (PDEs) with grid-based methods.
|
|
"""
|
|
homepage = "https://www.dune-project.org"
|
|
git = "https://gitlab.dune-project.org/core/dune-common.git"
|
|
|
|
# This defines a mapping of available versions of the dune Spack package
|
|
# and the branch name in the Dune repositories this refers to.
|
|
dune_versions_to_branch = {
|
|
"master" : "master",
|
|
"2.7" : "releases/2.7",
|
|
}
|
|
|
|
# Variants for the general build process
|
|
variant('shared', default=True, description='Enables the build of shared libraries.')
|
|
|
|
# Some variants for customization of Dune
|
|
variant('doc', default=False, description='Build and install documentation')
|
|
variant('python', default=False, description='Build with Python bindings')
|
|
|
|
# Variants for upstream dependencies
|
|
variant('arpack', default=True, description='Build ARnoldi PACKage library support')
|
|
variant('blas', default=True, description='Build with BLAS support')
|
|
variant('gmp', default=True, description='Build with GNU multi-precision library support')
|
|
variant('lapack', default=True, description='Build with LAPACK support')
|
|
variant('metis', default=True, description='Build with METIS library support')
|
|
variant('parmetis', default=False, description='Build with ParMETIS support')
|
|
variant('ptscotch', default=True, description='Build with PT-Scotch support')
|
|
variant('sionlib', default=False, description='Build with SIONlib support')
|
|
variant('suitesparse', default=True, description='Build SuiteSparse library support')
|
|
variant('superlu', default=False, description='Build Supernodal LU library support')
|
|
variant('tbb', default=False, description='Build with Intel TBB support')
|
|
variant('vc', default=False, description='Build C++ Vectorization library support')
|
|
variant('zlib', default=False, description='Build zlib library support')
|
|
variant('zoltan', default=False, description='Build with Zoltan support')
|
|
|
|
# Some variants that were here that are on my todo list
|
|
# variant('jupyter', default=False, description='Build with Jupyter support')
|
|
|
|
# Define a multi-valued variant for defining the modules
|
|
|
|
class dune_module_set(Sequence):
|
|
"""Define the possible values for the DUNE modules variants"""
|
|
def __init__(self):
|
|
self.module_dependencies={}
|
|
self.module_dependencies["common"]=[]
|
|
self.module_dependencies["geometry"]=["common"]
|
|
self.module_dependencies["grid"]=["common","geometry"]
|
|
self.module_dependencies["uggrid"]=["common"]
|
|
self.module_dependencies["istl"]=["common"]
|
|
self.module_dependencies["localfunctions"]=["common","geometry"]
|
|
self.module_dependencies["functions"]=["grid","typetree","localfunctions","istl"]
|
|
self.module_dependencies["typetree"]=["common"]
|
|
self.module_dependencies["python"]=[]
|
|
self.module_dependencies["spgrid"]=[]
|
|
self.module_dependencies["alugrid"]=["grid","geometry","common"]
|
|
self.sets=[]
|
|
for key in self.module_dependencies:
|
|
self.sets.append(key)
|
|
self.feature_values = tuple(self.sets)
|
|
self.default = ("common","grid")
|
|
self.multi = True
|
|
|
|
def __getitem__(self, idx):
|
|
return self.feature_values[idx]
|
|
|
|
def __len__(self):
|
|
return len(self.feature_values)
|
|
|
|
@property
|
|
def validator(self):
|
|
def module_dependency_closure(modlist):
|
|
closure = set(modlist)
|
|
old_closure = set()
|
|
while (len(closure) > len(old_closure)):
|
|
old_closure = closure.copy()
|
|
for res in old_closure:
|
|
for mod in self.module_dependencies.get(res):
|
|
closure.add(mod)
|
|
return closure
|
|
def _dune_modules_set_validator(pkg_name, variant_name, values):
|
|
ok=True
|
|
msg='Missing module dependencies: '
|
|
for s in values:
|
|
req_mod=module_dependency_closure({s})
|
|
for req in req_mod:
|
|
if(not req in values):
|
|
msg+=req+','
|
|
ok=False
|
|
if(ok):
|
|
return
|
|
msg = msg[:-1]
|
|
format_args = {
|
|
'variant': variant_name, 'package': pkg_name, 'values': values
|
|
}
|
|
msg = msg + \
|
|
" @*r{{[{package}, variant '{variant}']}}"
|
|
msg = llnl.util.tty.color.colorize(msg.format(**format_args))
|
|
raise error.SpecError(msg)
|
|
return _dune_modules_set_validator
|
|
|
|
variant( 'modules',
|
|
values=dune_module_set(),
|
|
description='Installed dune module')
|
|
|
|
|
|
# Iterate over all available Dune versions and define resources for all Dune modules
|
|
# If a Dune module behaves differently for different versions (e.g. dune-python got
|
|
# merged into dune-common post-2.7), define the resource outside of this loop.
|
|
for vers, branch in dune_versions_to_branch.items():
|
|
version(vers, branch=dune_versions_to_branch[vers])
|
|
|
|
resource(
|
|
name='dune-geometry',
|
|
git='https://gitlab.dune-project.org/core/dune-geometry.git',
|
|
branch=branch,
|
|
when='@%s modules=geometry' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-grid',
|
|
git='https://gitlab.dune-project.org/core/dune-grid.git',
|
|
branch=branch,
|
|
when='@%s modules=grid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-istl',
|
|
git='https://gitlab.dune-project.org/core/dune-istl.git',
|
|
branch=branch,
|
|
when='@%s modules=istl' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-localfunctions',
|
|
git='https://gitlab.dune-project.org/core/dune-localfunctions.git',
|
|
branch=branch,
|
|
when='@%s modules=localfunctions' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-functions',
|
|
git='https://gitlab.dune-project.org/staging/dune-functions.git',
|
|
branch=branch,
|
|
when='@%s modules=functions' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-typetree',
|
|
git='https://gitlab.dune-project.org/staging/dune-typetree.git',
|
|
branch=branch,
|
|
when='@%s modules=typetree' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-alugrid',
|
|
git='https://gitlab.dune-project.org/extensions/dune-alugrid.git',
|
|
branch=branch,
|
|
when='@%s modules=alugrid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-uggrid',
|
|
git='https://gitlab.dune-project.org/staging/dune-uggrid.git',
|
|
branch='releases/2.7',
|
|
when='@%s modules=uggrid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-spgrid',
|
|
git='https://gitlab.dune-project.org/extensions/dune-spgrid.git',
|
|
branch=branch,
|
|
when='@%s modules=spgrid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-python',
|
|
git='https://gitlab.dune-project.org/staging/dune-python.git',
|
|
branch=branch,
|
|
when='@2.7 modules=python',
|
|
)
|
|
|
|
extends('python')
|
|
python_components = [ 'dune' ]
|
|
|
|
# Specify upstream dependencies (often depending on variants)
|
|
depends_on('arpack-ng', when='+arpack')
|
|
depends_on('blas', when='+blas')
|
|
depends_on('cmake@3.1:', type='build')
|
|
depends_on('doxygen', type='build', when='+doc')
|
|
depends_on('gawk')
|
|
depends_on('gmp', when='+gmp')
|
|
depends_on('intel-tbb', when='+tbb')
|
|
depends_on('lapack', when='+lapack')
|
|
depends_on('metis', when='+metis')
|
|
depends_on('mpi')
|
|
depends_on('parmetis', when='+parmetis')
|
|
depends_on('pkg-config', type='build')
|
|
depends_on('python@3.0:', type=('build', 'run'), when='+python')
|
|
depends_on('py-setuptools', type='build', when='+python')
|
|
depends_on('py-numpy', type=('build', 'run'), when='+python')
|
|
depends_on('py-pip', type=('build', 'run'), when='+python')
|
|
depends_on('py-sphinx', type=('build', 'run'), when='+doc')
|
|
depends_on('py-wheel', type='build', when='+python')
|
|
depends_on('scotch+mpi', when='+ptscotch')
|
|
depends_on('sionlib', when='+sionlib')
|
|
depends_on('suite-sparse', when='+suitesparse')
|
|
depends_on('superlu', when='+superlu')
|
|
depends_on('vc', when='+vc')
|
|
depends_on('zlib', when='+zlib')
|
|
depends_on('zoltan', when='+zoltan')
|
|
|
|
def setup_build_environment(self, env):
|
|
# We reset the DUNE_CONTROL_PATH here because any entries in this
|
|
# path that contain Dune modules will break the Spack build process.
|
|
env.set('DUNE_CONTROL_PATH', '')
|
|
|
|
def setup_run_environment(self, env):
|
|
# Some scripts search the DUNE_CONTROL_PATH for Dune modules (e.g. duneproject).
|
|
# We need to set it correctly in order to allow multiple simultaneous
|
|
# installations of the dune package.
|
|
env.set('DUNE_CONTROL_PATH', self.prefix)
|
|
|
|
# Additionally, we need to set the workspace for the Python bindings to something
|
|
# that is unique to this build of the dune module (it defaults to ~/.cache)
|
|
if '+python' in self.spec:
|
|
env.set('DUNE_PY_DIR', self.prefix)
|
|
|
|
def cmake_args(self):
|
|
"""Populate cmake arguments."""
|
|
spec = self.spec
|
|
def variant_bool(feature, on='ON', off='OFF'):
|
|
"""Ternary for spec variant to ON/OFF string"""
|
|
if feature in spec:
|
|
return on
|
|
return off
|
|
|
|
def nvariant_bool(feature):
|
|
"""Negated ternary for spec variant to OFF/ON string"""
|
|
return variant_bool(feature, on='OFF', off='ON')
|
|
|
|
cmake_args = [
|
|
'-DBUILD_SHARED_LIBS:BOOL=%s' % variant_bool('+shared'),
|
|
'-DDUNE_GRID_GRIDTYPE_SELECTOR:BOOL=ON',
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_BLAS=%s' % nvariant_bool('+blas'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=%s' % nvariant_bool('+doc'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_GMP=%s' % nvariant_bool('+gmp'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_LAPACK=%s' % nvariant_bool('+lapack'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_LATEX=%s' % nvariant_bool('+doc'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_METIS=%s' % nvariant_bool('+metis'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_ParMETIS=%s' % nvariant_bool('+parmetis'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_PTScotch=%s' % nvariant_bool('+ptscotch'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_SIONLib=%s' % nvariant_bool('+sionlib'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_SuiteSparse=%s' % nvariant_bool('+suitesparse'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_SuperLU=%s' % nvariant_bool('+superlu'),
|
|
# '-DCMAKE_DISABLE_FIND_PACKAGE_TBB=%s' % nvariant_bool('+tbb'), Disabled until upstream fix of dune-common#205.
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_VC=%s' % nvariant_bool('+vc'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_ZLIB=%s' % nvariant_bool('+zlib'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_ZOLTAN=%s' % nvariant_bool('+zoltan'),
|
|
]
|
|
|
|
if '+python' in spec:
|
|
if '@2.7' not in spec:
|
|
cmake_args.append('-DDUNE_ENABLE_PYTHONBINDINGS:BOOL=TRUE')
|
|
cmake_args.append('-DDUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS:BOOL=TRUE')
|
|
cmake_args.append('-DDUNE_PYTHON_INSTALL_LOCATION:STRING="system"')
|
|
|
|
return cmake_args
|
|
|
|
def cmake(self, spec, prefix):
|
|
# Write an opts file for later use
|
|
with open(join_path(self.stage.source_path, "..", "dune.opts"), "w") as optFile:
|
|
optFile.write('CMAKE_FLAGS="')
|
|
for flag in self.cmake_args():
|
|
optFile.write(flag.replace("\"", "'")+" ")
|
|
optFile.write('-DCMAKE_INSTALL_PREFIX=%s' % prefix)
|
|
optFile.write('"')
|
|
|
|
installer = Executable('bin/dunecontrol')
|
|
options_file = join_path(self.stage.source_path, "..", "dune.opts")
|
|
installer('--builddir=%s'%self.build_directory , '--opts=%s' % options_file, 'cmake')
|
|
|
|
def install(self, spec, prefix):
|
|
installer = Executable('bin/dunecontrol')
|
|
options_file = join_path(self.stage.source_path, "..", "dune.opts")
|
|
installer('--builddir=%s'%self.build_directory , '--opts=%s' % options_file, 'make', 'install')
|
|
|
|
def build(self, spec, prefix):
|
|
installer = Executable('bin/dunecontrol')
|
|
options_file = join_path(self.stage.source_path, "..", "dune.opts")
|
|
installer('--builddir=%s'%self.build_directory , '--opts=%s' % options_file, 'make')
|
|
|