332 lines
15 KiB
Python
332 lines
15 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 pathlib import Path
|
|
from spack import *
|
|
|
|
|
|
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 one variant for each Dune module that we have. Only core modules
|
|
# are activated by default.
|
|
variant('alugrid', default=False, description='Build with dune-alugrid module')
|
|
variant('functions', default=False, description='Build with dune-functions module')
|
|
variant('geometry', default=True, description='Build with dune-geometry module')
|
|
variant('grid', default=True, description='Build with dune-grid module')
|
|
variant('istl', default=True, description='Build with dune-istl module')
|
|
variant('localfunctions', default=True, description='Build with dune-localfunctions module')
|
|
variant('spgrid', default=False, description='Build with dune-spgrid module')
|
|
variant('testtools', default=False, description='Build with dune-testtools module')
|
|
variant('typetree', default=False, description='Build with dune-typetree module')
|
|
variant('uggrid', default=False, description='Build with dune-uggrid 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+geometry' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-grid',
|
|
git='https://gitlab.dune-project.org/core/dune-grid.git',
|
|
branch=branch,
|
|
when='@%s+grid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-istl',
|
|
git='https://gitlab.dune-project.org/core/dune-istl.git',
|
|
branch=branch,
|
|
when='@%s+istl' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-localfunctions',
|
|
git='https://gitlab.dune-project.org/core/dune-localfunctions.git',
|
|
branch=branch,
|
|
when='@%s+localfunctions' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-functions',
|
|
git='https://gitlab.dune-project.org/staging/dune-functions.git',
|
|
branch=branch,
|
|
when='@%s+functions' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-typetree',
|
|
git='https://gitlab.dune-project.org/staging/dune-typetree.git',
|
|
branch=branch,
|
|
when='@%s+typetree' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-alugrid',
|
|
git='https://gitlab.dune-project.org/extensions/dune-alugrid.git',
|
|
branch=branch,
|
|
when='@%s+alugrid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-uggrid',
|
|
git='https://gitlab.dune-project.org/staging/dune-uggrid.git',
|
|
branch='releases/2.7',
|
|
when='@%s+uggrid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-spgrid',
|
|
git='https://gitlab.dune-project.org/extensions/dune-spgrid.git',
|
|
branch=branch,
|
|
when='@%s+spgrid' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-testtools',
|
|
git='https://gitlab.dune-project.org/quality/dune-testtools.git',
|
|
branch=branch,
|
|
when='@%s+testtools' % vers,
|
|
)
|
|
|
|
resource(
|
|
name='dune-python',
|
|
git='https://gitlab.dune-project.org/staging/dune-python.git',
|
|
branch=branch,
|
|
when='@2.7+python',
|
|
)
|
|
|
|
# Dependencies between modules
|
|
module_dependencies = {}
|
|
module_dependencies["dune-alugrid"] = ["dune-grid", "dune-geometry", "dune-common"]
|
|
module_dependencies["dune-common"] = []
|
|
module_dependencies["dune-functions"] = ["dune-grid", "dune-typetree", "dune-localfunctions", "dune-istl"]
|
|
module_dependencies["dune-geometry"] = ["dune-common"]
|
|
module_dependencies["dune-grid"] = ["dune-common", "dune-geometry"]
|
|
module_dependencies["dune-istl"] = ["dune-common"]
|
|
module_dependencies["dune-localfunctions"] = ["dune-common", "dune-geometry"]
|
|
module_dependencies["dune-python"] = []
|
|
module_dependencies["dune-testtools"] = ["dune-common"]
|
|
module_dependencies["dune-typetree"] = ["dune-common"]
|
|
module_dependencies["dune-uggrid"] = ["dune-common"]
|
|
|
|
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'))
|
|
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-pip', type=('build', 'run'), when='+testtools')
|
|
depends_on('py-sphinx', type=('build', 'run'), when='+doc')
|
|
depends_on('py-wheel', type='build', when='+python')
|
|
depends_on('py-wheel', type='build', when='+testtools')
|
|
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')
|
|
|
|
# Apply patches
|
|
patch('virtualenv_from_envvariable.patch', when='+testtools')
|
|
|
|
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', join_path(Path.home(), '.cache', 'dune-py', self.spec.dag_hash()))
|
|
|
|
# For those modules that typically work with the Dune Virtualenv,
|
|
# we export the location of the virtualenv as an environment variable.
|
|
if '+testtools' in self.spec:
|
|
env.set('DUNE_PYTHON_VIRTUALENV_PATH', join_path(Path.home(), '.cache', 'dune-python-env', self.spec.dag_hash()))
|
|
|
|
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:BOOL=%s' % nvariant_bool('+blas'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen:BOOL=%s' % nvariant_bool('+doc'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_GMP:BOOL=%s' % nvariant_bool('+gmp'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_LAPACK:BOOL=%s' % nvariant_bool('+lapack'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_LATEX:BOOL=%s' % nvariant_bool('+doc'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_METIS:BOOL=%s' % nvariant_bool('+metis'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_ParMETIS:BOOL=%s' % nvariant_bool('+parmetis'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_PTScotch:BOOL=%s' % nvariant_bool('+ptscotch'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_SIONLib:BOOL=%s' % nvariant_bool('+sionlib'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_SuiteSparse:BOOL=%s' % nvariant_bool('+suitesparse'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_SuperLU:BOOL=%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:BOOL=%s' % nvariant_bool('+vc'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_ZLIB:BOOL=%s' % nvariant_bool('+zlib'),
|
|
'-DCMAKE_DISABLE_FIND_PACKAGE_ZOLTAN:BOOL=%s' % nvariant_bool('+zoltan'),
|
|
]
|
|
|
|
if '+testtools' in spec or '+codegen' in spec:
|
|
cmake_args.append('-DDUNE_PYTHON_VIRTUALENV_SETUP:BOOL=ON')
|
|
cmake_args.append('-DDUNE_PYTHON_ALLOW_GET_PIP:BOOL=ON')
|
|
cmake_args.append('-DDUNE_PYTHON_VIRTUALENV_PATH:STRING="%s"' % join_path(self.prefix, 'dune-python-env'))
|
|
cmake_args.append('-DDUNE_PYTHON_INSTALL_LOCATION:STRING="system"')
|
|
|
|
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 module_dependency_closure(self, when, reslist):
|
|
# Get a list of all modules that share the version requirement
|
|
all_resources = []
|
|
for w, rl in self.resources.items():
|
|
if w.version == when.version:
|
|
all_resources.extend(rl)
|
|
|
|
# And build the closure of modules from the given reslist
|
|
closure = set(reslist)
|
|
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.name, []):
|
|
for r in all_resources:
|
|
if r.name == mod:
|
|
closure.add(r)
|
|
|
|
return list(closure)
|
|
|
|
def _get_needed_resources(self):
|
|
# Modify the list of resources by building a transitive closure of Dune module dependencies.
|
|
self.resources = {when: self.module_dependency_closure(when, reslist) for when, reslist in self.resources.items()}
|
|
|
|
# and call the original implementation
|
|
return CMakePackage._get_needed_resources(self)
|
|
|
|
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')
|
|
|