-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add package for of-swak4foam (SWiss Army Knife for Foam)
- The 'of-' prefix to group as addon/library for openfoam
- Loading branch information
mark
committed
Apr 6, 2017
1 parent
70372dd
commit 9948fda
Showing
3 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
var/spack/repos/builtin/packages/of-swak4foam/assets/local-userdir.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#----------------------------------*-sh-*-------------------------------------- | ||
# | ||
# File | ||
# local-userdir.sh USER-PREFIX | ||
# | ||
# Description | ||
# ----------- | ||
# OpenFOAM normally locates user directories under | ||
# ~/OpenFOAM/<userName>-<foamVersion> | ||
# 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 | ||
|
||
#------------------------------------------------------------------------------ |
21 changes: 21 additions & 0 deletions
21
var/spack/repos/builtin/packages/of-swak4foam/assets/spack-Allwmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
# ----------------------------------------------------------------------------- |
173 changes: 173 additions & 0 deletions
173
var/spack/repos/builtin/packages/of-swak4foam/package.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
############################################################################## | ||
# Copyright (c) 2017 Mark Olesen, OpenCFD Ltd. | ||
# | ||
# This file was authored by Mark Olesen <mark.olesen@esi-group.com> | ||
# 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)) | ||
|
||
# ----------------------------------------------------------------------------- |