From 9948fda4e9fa29f8e6ba2acce295a05d34d82388 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 6 Apr 2017 09:01:41 +0200 Subject: [PATCH] add package for of-swak4foam (SWiss Army Knife for Foam) - The 'of-' prefix to group as addon/library for openfoam --- .../of-swak4foam/assets/local-userdir.sh | 42 +++++ .../of-swak4foam/assets/spack-Allwmake | 21 +++ .../builtin/packages/of-swak4foam/package.py | 173 ++++++++++++++++++ 3 files changed, 236 insertions(+) create mode 100644 var/spack/repos/builtin/packages/of-swak4foam/assets/local-userdir.sh create mode 100755 var/spack/repos/builtin/packages/of-swak4foam/assets/spack-Allwmake create mode 100644 var/spack/repos/builtin/packages/of-swak4foam/package.py diff --git a/var/spack/repos/builtin/packages/of-swak4foam/assets/local-userdir.sh b/var/spack/repos/builtin/packages/of-swak4foam/assets/local-userdir.sh new file mode 100644 index 00000000000000..4fba1cb038b82a --- /dev/null +++ b/var/spack/repos/builtin/packages/of-swak4foam/assets/local-userdir.sh @@ -0,0 +1,42 @@ +#----------------------------------*-sh-*-------------------------------------- +# +# File +# local-userdir.sh USER-PREFIX +# +# Description +# ----------- +# OpenFOAM normally locates user directories under +# ~/OpenFOAM/- +# and sets FOAM_USER_APPBIN, FOAM_USER_LIBBIN accordingly. +# +# When building additional programs (eg, swak4Foam), it is better to relocate +# these and avoid conflicts with the normal user bin/lib files. +# +# The 'user' prefix could also include "platforms/$WM_OPTIONS" (as required) +#------------------------------------------------------------------------------ + +if [ "$#" -ge 1 ] +then + foamClean=$WM_PROJECT_DIR/bin/foamCleanPath + if [ -x "$foamCleanPath" ] + then + cleaned=$($foamClean "$PATH" "$FOAM_USER_APPBIN") && PATH="$cleaned" + cleaned=$($foamClean "$LD_LIBRARY_PATH" "$FOAM_USER_LIBBIN") \ + && LD_LIBRARY_PATH="$cleaned" + fi + + user="$1" + export FOAM_USER_APPBIN=$user/bin + export FOAM_USER_LIBBIN=$user/lib + + PATH=$FOAM_USER_APPBIN:$PATH + LD_LIBRARY_PATH=$FOAM_USER_LIBBIN:$LD_LIBRARY_PATH +fi + +echo WM_PROJECT_DIR = $WM_PROJECT_DIR +echo FOAM_USER_APPBIN = $FOAM_USER_APPBIN +echo FOAM_USER_LIBBIN = $FOAM_USER_LIBBIN + +unset foamClean cleaned user + +#------------------------------------------------------------------------------ diff --git a/var/spack/repos/builtin/packages/of-swak4foam/assets/spack-Allwmake b/var/spack/repos/builtin/packages/of-swak4foam/assets/spack-Allwmake new file mode 100755 index 00000000000000..f78178e2f5fb8f --- /dev/null +++ b/var/spack/repos/builtin/packages/of-swak4foam/assets/spack-Allwmake @@ -0,0 +1,21 @@ +#!/bin/bash +echo "Using PROJECT=$FOAM_PROJECT_DIR from spack" +[ -d "$FOAM_PROJECT_DIR" ] || { + echo "Error: no PROJECT=$FOAM_PROJECT_DIR" 1>&2 + exit 1 +} +export FOAM_INST_DIR=$(cd $FOAM_PROJECT_DIR/.. && pwd -L) # Needed by foam-extend +. $FOAM_PROJECT_DIR/etc/bashrc '' # No arguments + +[ -f spack-config.sh ] && . ./spack-config.sh + +echo "========================================" +date "+%Y-%m-%d %H:%M:%S %z" 2>/dev/null || echo "date is unknown" +echo "Build swak4foam with SPACK for $WM_PROJECT-$WM_PROJECT_VERSION" +echo " WM_PROJECT_DIR = $WM_PROJECT_DIR" +echo " $WM_COMPILER $WM_COMPILER_TYPE compiler" +echo " ${WM_OPTIONS}, with ${WM_MPLIB} ${FOAM_MPI}" +echo + +./Allwmake # No arguments +# ----------------------------------------------------------------------------- diff --git a/var/spack/repos/builtin/packages/of-swak4foam/package.py b/var/spack/repos/builtin/packages/of-swak4foam/package.py new file mode 100644 index 00000000000000..054268bb76290d --- /dev/null +++ b/var/spack/repos/builtin/packages/of-swak4foam/package.py @@ -0,0 +1,173 @@ +############################################################################## +# Copyright (c) 2017 Mark Olesen, OpenCFD Ltd. +# +# This file was authored by Mark Olesen +# and is released as part of spack under the LGPL license. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for the LLNL notice and the LGPL. +# +# License +# ------- +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Legal Notice +# ------------ +# OPENFOAM is a trademark owned by OpenCFD Ltd +# (producer and distributor of the OpenFOAM software via www.openfoam.com). +# The trademark information must remain visible and unadulterated in this +# file and via the "spack info" and comply with the term set by +# http://openfoam.com/legal/trademark-policy.php +# +# This file is not part of OpenFOAM, nor does it constitute a component of an +# OpenFOAM distribution. +# +############################################################################## +# +# Notes +# - The build sometimes has problems with the parser: +# >>>> +# Parser library did not compile OK. +# No sense continuing as everything else depends on it +# >>>> +# +# Just try building a second time and this complaint often disappears. +# +############################################################################## +from spack import * +from spack.environment import * +import llnl.util.tty as tty + +import os +from os.path import isfile + + +class OfSwak4foam(Package): + """swak4foam (SWiss Army Knife for Foam) supplies additional libraries + and utilities for OpenFOAM. + This offering is not approved or endorsed by OpenCFD Ltd, + producer and distributor of the OpenFOAM software via www.openfoam.com, + and owner of the OPENFOAM trademark. + """ + + homepage = "https://openfoamwiki.net/index.php/Contrib/swak4Foam" + + version( + 'dev', + branch='branches/develop', + git='https://github.com/Unofficial-Extend-Project-Mirror/openfoam-extend-swak4Foam-dev.git') + # The git mirror can be more convenient than hg (eg, shallow clone etc). + # http://hg.code.sf.net/p/openfoam-extend/swak4Foam + + variant('python', default=True, description='Build python modules') + + depends_on('openfoam+source') + depends_on('python', when='+python') + depends_on('flex@:2.6.1', type='build') # <- restriction due to scotch + depends_on('bison@:2.7', type='build') # swak4Foam only tested with 2.x + + # General patches + assets = ['spack-Allwmake', 'local-userdir.sh'] + + build_script = 'spack-Allwmake' # <- Generated by patch() method. + build_userdir = 'spack-userdir' # Build user APPBIN, LIBBIN into here + config_file = 'swakConfiguration' + + phases = ['configure', 'build', 'install'] + + # + # - End of definitions / setup - + # + + def patch(self): + """Copy additional files or other patching.""" + spec = self.spec + + # Copy files + assetdir = join_path(self.package_dir, 'assets') + for f in self.assets: + install( + join_path(assetdir, f), + join_path(self.stage.source_path, f)) + # Emit the dependent openfoam version _immediately_ + # We may have resolved the wrong version, and don't wish to build + # it as a dependency! + tty.info('Build for {0}'.format(spec['openfoam'].format('$_$@$%@+$+'))) + + def configure(self, spec, prefix): + """Generate swakConfiguration and spack-config.sh file.""" + # Standard swakConfiguration file + config = join_path(self.stage.source_path, self.config_file) + with open(config, 'w') as out: + if '+python' in spec: + out.write( + """# With python +python_bin={python_bin} +python_config="$python_bin/python-config" +export SWAK_PYTHON_INCLUDE="$($python_config --cflags)" +export SWAK_PYTHON_LINK="$($python_config --ldflags)" + +# Force python to be found first +PATH=$python_bin:$PATH +# +""".format(python_bin=spec['python'].prefix.bin)) + else: + out.write('# No python requested\n') + + # Local tweaks + config = join_path(self.stage.source_path, 'spack-config.sh') + with open(config, 'w') as out: + out.write( + """# local tweaks for building +# Force bison to be found first +bison_bin={bison_bin} +PATH=$bison_bin:$PATH + +# Local build (for user appbin, libbin) +. ./local-userdir.sh {user_dir} +# +""" + .format( + bison_bin=spec['bison'].prefix.bin, + user_dir='$PWD/' + self.build_userdir)) + + def build(self, spec, prefix): + """Build using the OpenFOAM Allwmake script, with a wrapper to source + its environment first. + """ + args = [] + if self.parallel: # Build in parallel? - pass via the environment + os.environ['WM_NCOMPPROCS'] = str(make_jobs) + builder = Executable(self.build_script) + builder(*args) + + def install(self, spec, prefix): + """Install under the prefix directory""" + + # Retain swak config file + for f in [self.config_file, 'COPYING']: + if isfile(f): + install(f, join_path(self.prefix, f)) + + for d in ['Documentation', 'Examples']: + install_tree(d, join_path(self.prefix, d)) + + # Place these directly under 'bin' and 'lib' + for d in ['bin', 'lib']: + install_tree( + join_path(self.build_userdir, d), + join_path(self.prefix, d)) + +# -----------------------------------------------------------------------------