updated the executible to return stderr when specified. Added load_module to build_environment.py, loads target

This commit is contained in:
Gregory Becker 2015-10-30 09:44:28 -07:00
parent d00314c621
commit 09597fe8dc
2 changed files with 45 additions and 12 deletions

View file

@ -86,6 +86,28 @@ def __call__(self, *args, **kwargs):
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.

View file

@ -56,7 +56,11 @@ def command(self):
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 @@ def streamify(arg, mode):
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 @@ def streamify(arg, mode):
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 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(