summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGregory Becker <becker33@llnl.gov>2015-10-30 09:44:28 -0700
committerGregory Becker <becker33@llnl.gov>2015-10-30 09:44:28 -0700
commit09597fe8dccbd7d49acf1b3198f24ab928874cdb (patch)
tree7a66483460c51b1aa1ea23b08c3d7020f9c9f2d1 /lib
parentd00314c621bd427b142fecafc11c25006f3b5279 (diff)
downloadspack-09597fe8dccbd7d49acf1b3198f24ab928874cdb.tar.gz
spack-09597fe8dccbd7d49acf1b3198f24ab928874cdb.tar.bz2
spack-09597fe8dccbd7d49acf1b3198f24ab928874cdb.tar.xz
spack-09597fe8dccbd7d49acf1b3198f24ab928874cdb.zip
updated the executible to return stderr when specified. Added load_module to build_environment.py, loads target
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/build_environment.py36
-rw-r--r--lib/spack/spack/util/executable.py21
2 files changed, 45 insertions, 12 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 68388958f5..191e858735 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -86,6 +86,28 @@ 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, return_oe=True).split()
+ for i, word in enumerate(text):
+ if word == 'conflict':
+ exec(compile(modulecmd('unload', text[i+1], return_oe=True), '<string>', 'exec'))
+ # Load the module now that there are no conflicts
+ load = modulecmd('load', mod, return_oe=True)
+ exec(compile(load, '<string>', 'exec'))
+
+
def set_compiler_environment_variables(pkg):
assert(pkg.spec.concrete)
compiler = pkg.compiler
@@ -108,11 +130,9 @@ def set_compiler_environment_variables(pkg):
os.environ['SPACK_COMPILER_SPEC'] = str(pkg.spec.compiler)
- if compiler.PrgEnv:
- os.environ['SPACK_CRAYPE'] = compiler.PrgEnv
- os.environ['SPACK_COMP_MODULE'] = compiler.module
-
-
+ if compiler.modules:
+ for mod in compiler.modules:
+ load_module(mod)
def set_build_environment_variables(pkg):
@@ -163,8 +183,10 @@ def set_build_environment_variables(pkg):
pcdir = join_path(p, libdir, 'pkgconfig')
if os.path.isdir(pcdir):
pkg_config_dirs.append(pcdir)
- path_set("PKG_CONFIG_PATH", pkg_config_dirs)
+ path_put_first("PKG_CONFIG_PATH", pkg_config_dirs)
+ if pkg.spec.architecture.compiler_strategy.lower() == 'module':
+ load_module(pkg.spec.architecture.module_name)
def set_module_variables_for_package(pkg):
"""Populate the module scope of install() with some useful functions.
@@ -239,8 +261,8 @@ def get_rpaths(pkg):
def setup_package(pkg):
"""Execute all environment setup routines."""
- set_compiler_environment_variables(pkg)
set_build_environment_variables(pkg)
+ set_compiler_environment_variables(pkg)
set_module_variables_for_package(pkg)
# Allow dependencies to set up environment as well.
diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py
index d1dfb62ffb..15354089ac 100644
--- a/lib/spack/spack/util/executable.py
+++ b/lib/spack/spack/util/executable.py
@@ -56,7 +56,11 @@ class Executable(object):
def __call__(self, *args, **kwargs):
"""Run the executable with subprocess.check_output, return output."""
- return_output = kwargs.get("return_output", False)
+ # Return oe returns a combined stream, setting both output and error
+ # without setting return oe returns them concatenated by a double line break
+ return_oe = kwargs.get("return_oe", False)
+ return_output = True if return_oe else kwargs.get("return_output", False)
+ return_error = True if return_oe else kwargs.get("return_error", False)
fail_on_error = kwargs.get("fail_on_error", True)
ignore_errors = kwargs.get("ignore_errors", ())
@@ -95,8 +99,8 @@ class Executable(object):
proc = subprocess.Popen(
cmd,
stdin=input,
- stderr=error,
- stdout=subprocess.PIPE if return_output else output)
+ stdout=subprocess.PIPE if return_output else output,
+ stderr=subprocess.STDOUT if return_oe else (subprocess.PIPE if return_error else error))
out, err = proc.communicate()
self.returncode = proc.returncode
@@ -104,8 +108,15 @@ class Executable(object):
if fail_on_error and rc != 0 and (rc not in ignore_errors):
raise ProcessError("Command exited with status %d:"
% proc.returncode, cmd_line)
- if return_output:
- return out
+ # Return out or error if specified. Return combined stream if requested,
+ # otherwise return them concatenated by double line break if both requested.
+ if return_output or return_error:
+ if return_oe or not return_error:
+ return out
+ elif return_output:
+ return out+'\n\n'+err
+ else:
+ return err
except OSError, e:
raise ProcessError(