Add modules to compilers. Changed compiler to take paths as a list. Changed compiler_for_spec to be aware of different compiler stratigies
This commit is contained in:
parent
7e6fc79eb2
commit
95a34628a3
3 changed files with 27 additions and 49 deletions
|
@ -106,17 +106,20 @@ class Compiler(object):
|
||||||
PrgEnv_compiler = None
|
PrgEnv_compiler = None
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, cspec, cc, cxx, f77, fc, modules=None):
|
def __init__(self, cspec, paths, modules=None):
|
||||||
def check(exe):
|
def check(exe):
|
||||||
if exe is None:
|
if exe is None:
|
||||||
return None
|
return None
|
||||||
_verify_executables(exe)
|
_verify_executables(exe)
|
||||||
return exe
|
return exe
|
||||||
|
|
||||||
self.cc = check(cc)
|
self.cc = check(paths[0])
|
||||||
self.cxx = check(cxx)
|
self.cxx = check(paths[1])
|
||||||
self.f77 = check(f77)
|
self.f77 = check(paths[2])
|
||||||
self.fc = check(fc)
|
if len(paths) == 3:
|
||||||
|
self.fc = self.f77
|
||||||
|
else:
|
||||||
|
self.fc = check(paths[3])
|
||||||
|
|
||||||
self.spec = cspec
|
self.spec = cspec
|
||||||
self.modules = modules
|
self.modules = modules
|
||||||
|
@ -264,7 +267,7 @@ def find_in_path(cls, *path):
|
||||||
if newcount <= prevcount:
|
if newcount <= prevcount:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
compilers[ver] = cls(spec, *paths)
|
compilers[ver] = cls(spec, paths)
|
||||||
|
|
||||||
return list(compilers.values())
|
return list(compilers.values())
|
||||||
|
|
||||||
|
@ -277,60 +280,26 @@ def find_in_modules(cls):
|
||||||
if not cls.PrgEnv_compiler:
|
if not cls.PrgEnv_compiler:
|
||||||
tty.die('Must supply PrgEnv_compiler with PrgEnv')
|
tty.die('Must supply PrgEnv_compiler with PrgEnv')
|
||||||
|
|
||||||
# output = _shell('module avail %s' % cls.PrgEnv_compiler)
|
|
||||||
modulecmd = which('modulecmd')
|
modulecmd = which('modulecmd')
|
||||||
modulecmd
|
modulecmd.add_default_arg('python')
|
||||||
|
output = modulecmd('avail', return_oe=True)
|
||||||
matches = re.findall(r'(%s)/([^\s(]*)' % cls.PrgEnv_compiler, output)
|
matches = re.findall(r'(%s)/([^\s(]*)' % cls.PrgEnv_compiler, output)
|
||||||
|
|
||||||
loaded_modules = os.environ["LOADEDMODULES"].split(":")
|
# loaded_modules = os.environ["LOADEDMODULES"].split(":")
|
||||||
#output = _shell('module avail %s' % cls.PrgEnv_compiler)
|
#output = _shell('module avail %s' % cls.PrgEnv_compiler)
|
||||||
for module in loaded_modules:
|
# for module in loaded_modules:
|
||||||
match = re.findall(r'(%s)/([^\s(]*)' % cls.PrgEnv_compiler, module)
|
# match = re.findall(r'(%s)/([^\s(]*)' % cls.PrgEnv_compiler, module)
|
||||||
|
|
||||||
for name, version in matches:
|
for name, version in matches:
|
||||||
v = version + '-craype'
|
v = version + '-craype'
|
||||||
comp = cls(spack.spec.CompilerSpec(name + '@' + v),
|
comp = cls(spack.spec.CompilerSpec(name + '@' + v),
|
||||||
'cc', 'CC', 'ftn', 'ftn', name +'/' + v)
|
['cc', 'CC', 'ftn'], [cls.PrgEnv, name +'/' + v])
|
||||||
|
|
||||||
compilers.append(comp)
|
compilers.append(comp)
|
||||||
|
|
||||||
return compilers
|
return compilers
|
||||||
|
|
||||||
|
|
||||||
def _cur_prgenv():
|
|
||||||
out, err = subprocess.Popen(
|
|
||||||
['module list'], shell=True,
|
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
|
||||||
matches = re.findall(r'(PrgEnv-[^/]*)/', err)
|
|
||||||
return matches[0]
|
|
||||||
|
|
||||||
|
|
||||||
def _module_shell(module, *args):
|
|
||||||
cmd = 'module swap %s %s;' % (_cur_prgenv(), module)
|
|
||||||
cmd += 'module load %s;' % compiler
|
|
||||||
cmd += 'module unload cray-libsci;'
|
|
||||||
|
|
||||||
# +
|
|
||||||
# 'module load craype-network-gemini;' +
|
|
||||||
# 'module load %s;' % module +
|
|
||||||
# 'module swap gcc/4.6.1;' +
|
|
||||||
# 'module load eswrap; ' +
|
|
||||||
# 'module load craype-mc12; ' +
|
|
||||||
# 'module load cray-shmem; ' +
|
|
||||||
# 'module load cray-mpich; ')
|
|
||||||
cmd += ' '.join(args)
|
|
||||||
out, err = subprocess.Popen([cmd + ' '.join(args)], shell=True,
|
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def _shell(*args):
|
|
||||||
return subprocess.Popen([' '.join(args)], shell=True,
|
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Return a string represntation of the compiler toolchain."""
|
"""Return a string represntation of the compiler toolchain."""
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
|
@ -197,18 +197,27 @@ def get_compiler(cspec):
|
||||||
else:
|
else:
|
||||||
compiler_paths.append(None)
|
compiler_paths.append(None)
|
||||||
|
|
||||||
return cls(cspec, *compiler_paths)
|
for m in _optional_instance_vars:
|
||||||
|
if m not in items:
|
||||||
|
items[m] = None
|
||||||
|
mods = items[m]
|
||||||
|
|
||||||
|
return cls(cspec, compiler_paths, mods)
|
||||||
|
|
||||||
matches = find(compiler_spec)
|
matches = find(compiler_spec)
|
||||||
return [get_compiler(cspec) for cspec in matches]
|
return [get_compiler(cspec) for cspec in matches]
|
||||||
|
|
||||||
|
|
||||||
@_auto_compiler_spec
|
@_auto_compiler_spec
|
||||||
def compiler_for_spec(compiler_spec):
|
def compiler_for_spec(compiler_spec, target):
|
||||||
"""Get the compiler that satisfies compiler_spec. compiler_spec must
|
"""Get the compiler that satisfies compiler_spec. compiler_spec must
|
||||||
be concrete."""
|
be concrete."""
|
||||||
assert(compiler_spec.concrete)
|
assert(compiler_spec.concrete)
|
||||||
compilers = compilers_for_spec(compiler_spec)
|
compilers = compilers_for_spec(compiler_spec)
|
||||||
|
if target.compiler_strategy == "PATH":
|
||||||
|
filter(lambda c: c.modules is None, compilers)
|
||||||
|
elif target.compiler_strategy == "MODULES":
|
||||||
|
filter(lambda c: c.modules is not None, compilers)
|
||||||
assert(len(compilers) == 1)
|
assert(len(compilers) == 1)
|
||||||
return compilers[0]
|
return compilers[0]
|
||||||
|
|
||||||
|
|
|
@ -592,7 +592,7 @@ def compiler(self):
|
||||||
"""Get the spack.compiler.Compiler object used to build this package."""
|
"""Get the spack.compiler.Compiler object used to build this package."""
|
||||||
if not self.spec.concrete:
|
if not self.spec.concrete:
|
||||||
raise ValueError("Can only get a compiler for a concrete package.")
|
raise ValueError("Can only get a compiler for a concrete package.")
|
||||||
return spack.compilers.compiler_for_spec(self.spec.compiler)
|
return spack.compilers.compiler_for_spec(self.spec.compiler, self.spec.architecture)
|
||||||
|
|
||||||
|
|
||||||
def url_version(self, version):
|
def url_version(self, version):
|
||||||
|
|
Loading…
Reference in a new issue