summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMario Melara <maamelara@gmail.com>2016-04-06 14:07:22 -0700
committerMario Melara <maamelara@gmail.com>2016-04-06 14:07:22 -0700
commit99117cbc9067df814c99f8427f658ad9a811f69b (patch)
treeaf1cce9a653c8bcc8ffb34da52eab931a436a1de /lib
parent918ad28a936abf6112ba91ca7eb2e121f84e60cf (diff)
downloadspack-99117cbc9067df814c99f8427f658ad9a811f69b.tar.gz
spack-99117cbc9067df814c99f8427f658ad9a811f69b.tar.bz2
spack-99117cbc9067df814c99f8427f658ad9a811f69b.tar.xz
spack-99117cbc9067df814c99f8427f658ad9a811f69b.zip
pulled from current repo the build_environment.py. Added module loading methods from our cray port
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/build_environment.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 87fc310b5a..12a529d070 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -83,6 +83,66 @@ class MakeExecutable(Executable):
return super(MakeExecutable, self).__call__(*args, **kwargs)
+def load_module(mod):
+ """Takes a module name and removes modules until it is possible to
+ load that module. It then loads the provided module. Depends on the
+ modulecmd implementation of modules used in cray and lmod.
+ """
+ #Create an executable of the module command that will output python code
+ modulecmd = which('modulecmd')
+ modulecmd.add_default_arg('python')
+
+ # Read the module and remove any conflicting modules
+ # We do this without checking that they are already installed
+ # for ease of programming because unloading a module that is not
+ # loaded does nothing.
+ text = modulecmd('show', mod, output=str, error=str).split()
+ for i, word in enumerate(text):
+ if word == 'conflict':
+ exec(compile(modulecmd('unload', text[i+1], output=str, error=str), '<string>', 'exec'))
+ # Load the module now that there are no conflicts
+ load = modulecmd('load', mod, output=str, error=str)
+ exec(compile(load, '<string>', 'exec'))
+
+def get_path_from_module(mod):
+ """Inspects a TCL module for entries that indicate the absolute path
+ at which the library supported by said module can be found.
+ """
+ # Create a modulecmd executable
+ modulecmd = which('modulecmd')
+ modulecmd.add_default_arg('python')
+
+ # Read the module
+ text = modulecmd('show', mod, output=str, error=str).split('\n')
+
+ # If it lists its package directory, return that
+ for line in text:
+ if line.find(mod.upper()+'_DIR') >= 0:
+ words = line.split()
+ return words[2]
+
+ # If it lists a -rpath instruction, use that
+ for line in text:
+ rpath = line.find('-rpath/')
+ if rpath >= 0:
+ return line[rpath+6:line.find('/lib')]
+
+ # If it lists a -L instruction, use that
+ for line in text:
+ L = line.find('-L/')
+ if L >= 0:
+ return line[L+2:line.find('/lib')]
+
+ # If it sets the LD_LIBRARY_PATH or CRAY_LD_LIBRARY_PATH, use that
+ for line in text:
+ if line.find('LD_LIBRARY_PATH') >= 0:
+ words = line.split()
+ path = words[2]
+ return path[:path.find('/lib')]
+
+ # Unable to find module path
+ return None
+
def set_compiler_environment_variables(pkg):
assert(pkg.spec.concrete)
compiler = pkg.compiler
@@ -109,6 +169,9 @@ def set_compiler_environment_variables(pkg):
os.environ['SPACK_COMPILER_SPEC'] = str(pkg.spec.compiler)
+ if compiler.strategy == 'MODULES':
+ for mod in compiler.modules:
+ load_module(mod)
def set_build_environment_variables(pkg):
"""This ensures a clean install environment when we build packages.
@@ -172,6 +235,9 @@ def set_build_environment_variables(pkg):
pkg_config_dirs.append(pcdir)
path_set("PKG_CONFIG_PATH", pkg_config_dirs)
+ if pkg.spec.architecture.target.module_name:
+ load_module(pkg.spec.architecture.target.module_name)
+
def set_module_variables_for_package(pkg, m):
"""Populate the module scope of install() with some useful functions.
@@ -241,6 +307,11 @@ def set_module_variables_for_package(pkg, m):
def get_rpaths(pkg):
"""Get a list of all the rpaths for a package."""
+ for spec in pkg.spec.traverse(root=False):
+ if spec.external_module:
+ load_module(spec.external_module)
+ spec.external = get_path_from_module(spec.external_module)
+
rpaths = [pkg.prefix.lib, pkg.prefix.lib64]
rpaths.extend(d.prefix.lib for d in pkg.spec.dependencies.values()
if os.path.isdir(d.prefix.lib))