summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
authorMark Olesen <Mark.Olesen@esi-group.com>2017-12-20 08:39:12 +0100
committerscheibelp <scheibel1@llnl.gov>2017-12-20 11:32:33 -0800
commit235c3c10250112155715b475dc1b8864c6452b3d (patch)
tree26063eb7d15cfeb90ee571a3608490f39f24d56d /var
parent6ea4614dbd3e7cbc447c98a2d9717523b213095f (diff)
downloadspack-235c3c10250112155715b475dc1b8864c6452b3d.tar.gz
spack-235c3c10250112155715b475dc1b8864c6452b3d.tar.bz2
spack-235c3c10250112155715b475dc1b8864c6452b3d.tar.xz
spack-235c3c10250112155715b475dc1b8864c6452b3d.zip
ENH: improved openfoam module creation (issue #4942)
- post-install module settings for openfoam-com and foam-extend.
Diffstat (limited to 'var')
-rw-r--r--var/spack/repos/builtin/packages/foam-extend/package.py77
-rw-r--r--var/spack/repos/builtin/packages/openfoam-com/package.py81
-rw-r--r--var/spack/repos/builtin/packages/openfoam-org/package.py7
3 files changed, 146 insertions, 19 deletions
diff --git a/var/spack/repos/builtin/packages/foam-extend/package.py b/var/spack/repos/builtin/packages/foam-extend/package.py
index c6861da8d3..6a45f92399 100644
--- a/var/spack/repos/builtin/packages/foam-extend/package.py
+++ b/var/spack/repos/builtin/packages/foam-extend/package.py
@@ -58,10 +58,12 @@ import shutil
import os
from spack import *
+from spack.environment import EnvironmentModifications
from spack.pkg.builtin.openfoam_com import OpenfoamArch
from spack.pkg.builtin.openfoam_com import add_extra_files
from spack.pkg.builtin.openfoam_com import write_environ
from spack.pkg.builtin.openfoam_com import rewrite_environ_files
+import llnl.util.tty as tty
class FoamExtend(Package):
@@ -140,14 +142,77 @@ class FoamExtend(Package):
#
def setup_environment(self, spack_env, run_env):
- run_env.set('FOAM_INST_DIR', os.path.dirname(self.projectdir)),
- run_env.set('FOAM_PROJECT_DIR', self.projectdir)
- run_env.set('WM_PROJECT_DIR', self.projectdir)
- for d in ['wmake', self.archbin]: # bin already added automatically
- run_env.prepend_path('PATH', join_path(self.projectdir, d))
+ """Add environment variables to the generated module file.
+ These environment variables come from running:
+
+ .. code-block:: console
+
+ $ . $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')
+ minimal = True
+ if os.path.isfile(bashrc):
+ # post-install: source the installed bashrc
+ try:
+ mods = EnvironmentModifications.from_sourcing_file(
+ bashrc,
+ clean=True, # Remove duplicate entries
+ blacklist=[ # Blacklist these
+ # Inadvertent changes
+ # -------------------
+ 'PS1', # Leave unaffected
+ 'MANPATH', # Leave unaffected
+
+ # Unneeded bits
+ # -------------
+ 'FOAM_INST_DIR', # Possibly incorrect
+ 'FOAM_(APP|ETC|SRC|SOLVERS|UTILITIES)',
+ 'FOAM_TEST_.*_DIR',
+ 'WM_NCOMPPROCS',
+ # 'FOAM_TUTORIALS', # can be useful
+
+ # Lots of third-party cruft
+ # -------------------------
+ '[A-Z].*_(BIN|LIB|INCLUDE)_DIR',
+ '[A-Z].*_SYSTEM',
+ 'WM_THIRD_PARTY_.*',
+ '(BISON|FLEX|CMAKE|ZLIB)_DIR',
+ '(METIS|PARMETIS|PARMGRIDGEN|SCOTCH)_DIR',
+
+ # User-specific
+ # -------------
+ 'FOAM_RUN',
+ '(FOAM|WM)_.*USER_.*',
+ ],
+ whitelist=[ # Whitelist these
+ 'MPI_ARCH_PATH', # Can be needed for compilation
+ 'PYTHON_BIN_DIR',
+ ])
+
+ run_env.extend(mods)
+ minimal = False
+ tty.info('foam-extend env: {0}'.format(bashrc))
+ except Exception:
+ minimal = True
+
+ if minimal:
+ # pre-build or minimal environment
+ tty.info('foam-extend minimal env {0}'.format(self.prefix))
+ run_env.set('FOAM_INST_DIR', os.path.dirname(self.projectdir)),
+ run_env.set('FOAM_PROJECT_DIR', self.projectdir)
+ run_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))
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
- """Provide location of the OpenFOAM project.
+ """Location of the OpenFOAM project.
This is identical to the WM_PROJECT_DIR value, but we avoid that
variable since it would mask the normal OpenFOAM cleanup of
previous versions.
diff --git a/var/spack/repos/builtin/packages/openfoam-com/package.py b/var/spack/repos/builtin/packages/openfoam-com/package.py
index d184365720..2554e6c47f 100644
--- a/var/spack/repos/builtin/packages/openfoam-com/package.py
+++ b/var/spack/repos/builtin/packages/openfoam-com/package.py
@@ -64,6 +64,7 @@ import shutil
import os
from spack import *
+from spack.environment import EnvironmentModifications
import llnl.util.tty as tty
@@ -150,8 +151,9 @@ def _write_environ_file(output, environ, formatter):
Also descends into sub-dict and sub-list, but drops the key.
"""
with open(output, 'w') as outfile:
- outfile.write('# SPACK settings\n\n')
+ outfile.write('# spack generated\n')
_write_environ_entries(outfile, environ, formatter)
+ outfile.write('# spack\n')
def write_environ(environ, **kwargs):
@@ -260,6 +262,7 @@ class OpenfoamCom(Package):
in 2004.
"""
+ maintainers = ['olesenm']
homepage = "http://www.openfoam.com/"
baseurl = "https://sourceforge.net/projects/openfoamplus/files/"
gitrepo = "https://develop.openfoam.com/Development/OpenFOAM-plus.git"
@@ -367,13 +370,72 @@ class OpenfoamCom(Package):
#
def setup_environment(self, spack_env, run_env):
- run_env.set('FOAM_PROJECT_DIR', self.projectdir)
- run_env.set('WM_PROJECT_DIR', self.projectdir)
- for d in ['wmake', self.archbin]: # bin already added automatically
- run_env.prepend_path('PATH', join_path(self.projectdir, d))
+ """Add environment variables to the generated module file.
+ These environment variables come from running:
+
+ .. code-block:: console
+
+ $ . $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')
+ minimal = True
+ if os.path.isfile(bashrc):
+ # post-install: source the installed bashrc
+ try:
+ mods = EnvironmentModifications.from_sourcing_file(
+ bashrc,
+ clean=True, # Remove duplicate entries
+ blacklist=[ # Blacklist these
+ # Inadvertent changes
+ # -------------------
+ 'PS1', # Leave unaffected
+ 'MANPATH', # Leave unaffected
+
+ # Unneeded bits
+ # -------------
+ 'FOAM_SETTINGS', # Do not use with modules
+ 'FOAM_INST_DIR', # Old
+ 'FOAM_(APP|ETC|SRC|SOLVERS|UTILITIES)',
+ # 'FOAM_TUTORIALS', # can be useful
+ 'WM_OSTYPE', # Purely optional value
+
+ # Third-party cruft - only used for orig compilation
+ # -----------------
+ '[A-Z].*_ARCH_PATH',
+ '(KAHIP|METIS|SCOTCH)_VERSION',
+
+ # User-specific
+ # -------------
+ 'FOAM_RUN',
+ '(FOAM|WM)_.*USER_.*',
+ ],
+ whitelist=[ # Whitelist these
+ 'MPI_ARCH_PATH', # Can be needed for compilation
+ ])
+
+ run_env.extend(mods)
+ minimal = False
+ tty.info('OpenFOAM bashrc env: {0}'.format(bashrc))
+ except Exception:
+ minimal = True
+
+ if minimal:
+ # pre-build or minimal environment
+ tty.info('OpenFOAM minimal env {0}'.format(self.prefix))
+ run_env.set('FOAM_PROJECT_DIR', self.projectdir)
+ run_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))
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
- """Provide location of the OpenFOAM project.
+ """Location of the OpenFOAM project directory.
This is identical to the WM_PROJECT_DIR value, but we avoid that
variable since it would mask the normal OpenFOAM cleanup of
previous versions.
@@ -468,6 +530,7 @@ class OpenfoamCom(Package):
],
'scotch': {},
'metis': {},
+ 'ensight': {}, # Disable settings
'paraview': [],
'gperftools': [], # Currently unused
}
@@ -613,12 +676,6 @@ class OpenfoamCom(Package):
]:
os.symlink(f, os.path.basename(f))
- def openfoam_run_environment(self, projdir):
- # This seems to bomb out with an ImportError 'site'!
- # mods = EnvironmentModifications.from_sourcing_files(
- # join_path(projdir, 'etc/bashrc'))
- pass
-
# -----------------------------------------------------------------------------
diff --git a/var/spack/repos/builtin/packages/openfoam-org/package.py b/var/spack/repos/builtin/packages/openfoam-org/package.py
index e37c22b6ed..ddae24939b 100644
--- a/var/spack/repos/builtin/packages/openfoam-org/package.py
+++ b/var/spack/repos/builtin/packages/openfoam-org/package.py
@@ -137,13 +137,18 @@ class OpenfoamOrg(Package):
#
def setup_environment(self, spack_env, run_env):
+ # This should be similar to the openfoam-com package,
+ # but sourcing the etc/bashrc here seems to exit with an error.
+ # ... this needs to be examined in more detail.
+ #
+ # Minimal environment only.
run_env.set('FOAM_PROJECT_DIR', self.projectdir)
run_env.set('WM_PROJECT_DIR', self.projectdir)
for d in ['wmake', self.archbin]: # bin already added automatically
run_env.prepend_path('PATH', join_path(self.projectdir, d))
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
- """Provide location of the OpenFOAM project.
+ """Location of the OpenFOAM project directory.
This is identical to the WM_PROJECT_DIR value, but we avoid that
variable since it would mask the normal OpenFOAM cleanup of
previous versions.