# 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. This is a # list instead of a dictionary to ensure iteration order (first entry is # the default version) in Python3. dune_versions_to_branch = [ ("2.7", "releases/2.7"), ("master" , "master"), ] # 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('petsc', default=False, description='Build with PetSc 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('codegen', default=False, description='Build with dune-codegen module') variant('fem', default=False, description='Build with dune-fem(py) module') variant('foamgrid', default=False, description='Build with dune-foamgrid 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('gridglue', default=False, description='Build with dune-grid-glue module') variant('istl', default=True, description='Build with dune-istl module') variant('localfunctions', default=True, description='Build with dune-localfunctions module') variant('multidomaingrid', default=False, description='Build with dune-multidomaingrid module') variant('pdelab', default=False, description='Build with dune-pdelab module') variant('polygongrid', default=False, description='Build with dune-polygongrid 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: version(vers, branch=branch) 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-polygongrid', git='https://gitlab.dune-project.org/extensions/dune-polygongrid.git', branch=branch, when='@%s+polygongrid' % vers, ) resource( name='dune-foamgrid', git='https://gitlab.dune-project.org/extensions/dune-foamgrid.git', branch=branch, when='@%s+foamgrid' % vers, ) resource( name='dune-multidomaingrid', git='https://gitlab.dune-project.org/extensions/dune-multidomaingrid.git', branch=branch, when='@%s+multidomaingrid' % vers, ) resource( name='dune-fem', git='https://gitlab.dune-project.org/dune-fem/dune-fem.git', branch=branch, when='@%s+fem' % vers, ) resource( name='dune-fempy', git='https://gitlab.dune-project.org/dune-fem/dune-fempy.git', branch=branch, when='@%s+fem+python' % vers, ) # The dune-grid-glue package does not yet have a 2.7-compatible release resource( name='dune-grid-glue', git='https://gitlab.dune-project.org/extensions/dune-grid-glue.git', branch='master', when='@master+gridglue', ) # The dune-python package migrated to dune-common after the 2.7 release resource( name='dune-python', git='https://gitlab.dune-project.org/staging/dune-python.git', branch='releases/2.7', when='@2.7+python', ) # The dune-pdelab package does not yet have a 2.7-compatible release resource( name='dune-pdelab', git='https://gitlab.dune-project.org/pdelab/dune-pdelab.git', branch='bugfix/library-build', when='@master+pdelab', ) # The dune-codegen package does not yet have a 2.7-compatible release resource( name='dune-codegen', git='https://gitlab.dune-project.org/extensions/dune-codegen.git', branch='bugfix/installed-library', when='@master+codegen', submodules=True, ) # Dependencies between modules - not necessarily the full set # as the closure of module dependencies is built later on. module_dependencies = {} module_dependencies["dune-alugrid"] = ["dune-grid", "dune-geometry", "dune-common"] module_dependencies["dune-codegen"] = ["dune-pdelab", "dune-testtools", "dune-alugrid"] module_dependencies["dune-common"] = [] module_dependencies["dune-fem"] = ["dune-grid"] module_dependencies["fune-fempy"] = ["dune-fem"] module_dependencies["dune-foamgrid"] = ["dune-grid"] 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-grid-glue"] = ["dune-grid"] module_dependencies["dune-istl"] = ["dune-common"] module_dependencies["dune-localfunctions"] = ["dune-common", "dune-geometry"] module_dependencies["dune-multidomaingrid"] = ["dune-grid", "dune-typetree"] module_dependencies["dune-pdelab"] = ["dune-common", "dune-grid", "dune-istl", "dune-functions"] module_dependencies["dune-polygongrid"] = ["dune-grid"] module_dependencies["dune-python"] = ["dune-common"] 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('benchmark', when='+codegen') depends_on('blas', when='+blas') depends_on('cmake@3.1:', type='build') depends_on('eigen', when='+fem') depends_on('eigen', when='+pdelab') depends_on('papi', when='+fem') 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('likwid', when='+codegen') likwid cannot be built in spack v0.14.2 due to the lua dependency being broken depends_on('metis', when='+metis') depends_on('mpi') depends_on('parmetis', when='+parmetis') depends_on('petsc', when='+petsc') 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='+codegen') 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='+codegen') 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') patch('virtualenv_from_envvariable.patch', when='+codegen') # Some conflicts conflicts('dune~superlu', when='+codegen') 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 or '+codegen' 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(Path.home(), '.cache', 'dune-python-env', self.spec.dag_hash())) 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): # dune-codegen delivers its own set of patches for its submodules # that we can apply with a script delivered by dune-codegen. if '+codegen' in self.spec: with working_dir(join_path(self.root_cmakelists_dir, 'dune-codegen')): Executable('patches/apply_patches.sh')() # 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')