Update openfoam to use new environment api (ref: #11115, 9ddc98e46a) (#13645)

- build:
  no special treatment - already addressed in the spack-Allwmake script

- run:
  use environment from the OpenFOAM etc/bashrc
This commit is contained in:
Mark Olesen 2019-11-08 17:32:14 +01:00 committed by Adam J. Stewart
parent ae6229dee2
commit f4a1666b1a
2 changed files with 39 additions and 30 deletions

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# Build wrapper script - FOAM_INST_DIR is only required by foam-extend # Build wrapper script - FOAM_INST_DIR is only required by foam-extend
export FOAM_INST_DIR=$(cd .. && pwd -L) export FOAM_INST_DIR=$(cd .. && pwd -L)
. $PWD/etc/bashrc '' # No arguments . "$PWD/etc/bashrc" '' # No arguments
mkdir -p $FOAM_APPBIN $FOAM_LIBBIN 2>/dev/null # Allow interrupt mkdir -p "$FOAM_APPBIN" "$FOAM_LIBBIN" 2>/dev/null # Allow build interrupt
echo "Build openfoam with SPACK ($@)" echo "Build openfoam with SPACK ($@)"
echo "WM_PROJECT_DIR = $WM_PROJECT_DIR" echo "WM_PROJECT_DIR = $WM_PROJECT_DIR"
@ -12,6 +12,7 @@ then
./Allwmake-spack $@ # Pass arguments ./Allwmake-spack $@ # Pass arguments
else else
./Allwmake $@ # Pass arguments ./Allwmake $@ # Pass arguments
##echo "Disabled build of openfoam" # When testing environment only
# Generate manpages # Generate manpages
if [ -x bin/tools/foamCreateManpage ] if [ -x bin/tools/foamCreateManpage ]
@ -23,13 +24,13 @@ fi
# Link non-dummy MPI_FOAM type to parent-dir, where rpath can find it # Link non-dummy MPI_FOAM type to parent-dir, where rpath can find it
if [ "${FOAM_MPI:=dummy}" != dummy -a -d "$FOAM_LIBBIN/$FOAM_MPI" ] if [ "${FOAM_MPI:=dummy}" != dummy ] && [ -d "$FOAM_LIBBIN/$FOAM_MPI" ]
then then
( (
cd "$FOAM_LIBBIN" || exit 1 cd "$FOAM_LIBBIN" || exit 1
for i in $FOAM_MPI/lib*.so for i in "$FOAM_MPI"/lib*.so
do do
[ -f $i ] && ln -sf $i "${i##*/}" [ -f "$i" ] && ln -sf "$i" "${i##*/}"
done done
) )
fi fi

View File

@ -376,21 +376,29 @@ def url_for_version(self, version):
fmt += 'v{0}/OpenFOAM-v{0}.tgz' fmt += 'v{0}/OpenFOAM-v{0}.tgz'
return fmt.format(version, version) return fmt.format(version, version)
def setup_environment(self, spack_env, run_env): def setup_minimal_environment(self, env):
"""Add environment variables to the generated module file. """Sets a minimal openfoam environment.
These environment variables come from running: """
tty.info('OpenFOAM minimal env {0}'.format(self.prefix))
env.set('FOAM_PROJECT_DIR', self.projectdir)
env.set('WM_PROJECT_DIR', self.projectdir)
for d in ['wmake', self.archbin]: # bin added automatically
env.prepend_path('PATH', join_path(self.projectdir, d))
def setup_build_environment(self, env):
"""Sets the build environment (prior to unpacking the sources).
"""
pass
def setup_run_environment(self, env):
"""Sets the run environment (post-installation).
The environment comes from running:
.. code-block:: console .. code-block:: console
$ . $WM_PROJECT_DIR/etc/bashrc $ . $WM_PROJECT_DIR/etc/bashrc
""" """
# NOTE: Spack runs setup_environment twice.
# 1) pre-build to set up the build environment
# 2) post-install to determine runtime environment variables
# The etc/bashrc is only available (with corrrect content)
# post-installation.
bashrc = join_path(self.projectdir, 'etc', 'bashrc') bashrc = join_path(self.projectdir, 'etc', 'bashrc')
minimal = True minimal = True
if os.path.isfile(bashrc): if os.path.isfile(bashrc):
@ -427,8 +435,7 @@ def setup_environment(self, spack_env, run_env):
'MPI_ARCH_PATH', # Can be needed for compilation 'MPI_ARCH_PATH', # Can be needed for compilation
]) ])
run_env.extend(mods) env.extend(mods)
spack_env.extend(mods)
minimal = False minimal = False
tty.info('OpenFOAM bashrc env: {0}'.format(bashrc)) tty.info('OpenFOAM bashrc env: {0}'.format(bashrc))
except Exception: except Exception:
@ -436,22 +443,23 @@ def setup_environment(self, spack_env, run_env):
if minimal: if minimal:
# pre-build or minimal environment # pre-build or minimal environment
tty.info('OpenFOAM minimal env {0}'.format(self.prefix)) self.setup_minimal_environment(env)
run_env.set('FOAM_PROJECT_DIR', self.projectdir)
run_env.set('WM_PROJECT_DIR', self.projectdir)
spack_env.set('FOAM_PROJECT_DIR', self.projectdir)
spack_env.set('WM_PROJECT_DIR', self.projectdir)
for d in ['wmake', self.archbin]: # bin added automatically
run_env.prepend_path('PATH', join_path(self.projectdir, d))
spack_env.prepend_path('PATH', join_path(self.projectdir, d))
def setup_dependent_environment(self, spack_env, run_env, dependent_spec): def setup_dependent_build_environment(self, env, dependent_spec):
"""Location of the OpenFOAM project directory. """Use full OpenFOAM environment when building.
This is identical to the WM_PROJECT_DIR value, but we avoid that Mirror WM_PROJECT_DIR value as FOAM_PROJECT_DIR to avoid
variable since it would mask the normal OpenFOAM cleanup of masking the normal OpenFOAM cleanup of previous versions.
previous versions.
""" """
self.setup_environment(spack_env, run_env) self.setup_run_environment(env)
env.set('FOAM_PROJECT_DIR', self.projectdir)
def setup_dependent_run_environment(self, env, dependent_spec):
"""Use full OpenFOAM environment when running.
Mirror WM_PROJECT_DIR value as FOAM_PROJECT_DIR to avoid
masking the normal OpenFOAM cleanup of previous versions.
"""
self.setup_run_environment(env)
env.set('FOAM_PROJECT_DIR', self.projectdir)
@property @property
def projectdir(self): def projectdir(self):