diff options
author | Mark Olesen <Mark.Olesen@esi-group.com> | 2017-12-20 08:39:12 +0100 |
---|---|---|
committer | scheibelp <scheibel1@llnl.gov> | 2017-12-20 11:32:33 -0800 |
commit | 235c3c10250112155715b475dc1b8864c6452b3d (patch) | |
tree | 26063eb7d15cfeb90ee571a3608490f39f24d56d /var/spack/repos/builtin/packages/foam-extend | |
parent | 6ea4614dbd3e7cbc447c98a2d9717523b213095f (diff) | |
download | spack-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/spack/repos/builtin/packages/foam-extend')
-rw-r--r-- | var/spack/repos/builtin/packages/foam-extend/package.py | 77 |
1 files changed, 71 insertions, 6 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. |