summaryrefslogtreecommitdiff
path: root/lib/spack/spack/cmd/compiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/spack/cmd/compiler.py')
-rw-r--r--lib/spack/spack/cmd/compiler.py111
1 files changed, 76 insertions, 35 deletions
diff --git a/lib/spack/spack/cmd/compiler.py b/lib/spack/spack/cmd/compiler.py
index dc7731a290..609210f77e 100644
--- a/lib/spack/spack/cmd/compiler.py
+++ b/lib/spack/spack/cmd/compiler.py
@@ -32,11 +32,12 @@ import spack.spec
from llnl.util.lang import index_by
from llnl.util.tty.colify import colify
from llnl.util.tty.color import colorize
-from spack.spec import CompilerSpec
+from spack.spec import CompilerSpec, ArchSpec
from spack.util.environment import get_path
description = "Manage compilers"
+
def setup_parser(subparser):
sp = subparser.add_subparsers(
metavar='SUBCOMMAND', dest='compiler_command')
@@ -44,48 +45,72 @@ def setup_parser(subparser):
scopes = spack.config.config_scopes
# Find
- find_parser = sp.add_parser('find', aliases=['add'], help='Search the system for compilers to add to the Spack configuration.')
+ find_parser = sp.add_parser(
+ 'find', aliases=['add'],
+ help='Search the system for compilers to add to Spack configuration.')
find_parser.add_argument('add_paths', nargs=argparse.REMAINDER)
- find_parser.add_argument('--scope', choices=scopes, default=spack.cmd.default_modify_scope,
- help="Configuration scope to modify.")
+ find_parser.add_argument(
+ '--scope', choices=scopes, default=spack.cmd.default_modify_scope,
+ help="Configuration scope to modify.")
# Remove
- remove_parser = sp.add_parser('remove', aliases=['rm'], help='Remove compiler by spec.')
+ remove_parser = sp.add_parser(
+ 'remove', aliases=['rm'], help='Remove compiler by spec.')
remove_parser.add_argument(
- '-a', '--all', action='store_true', help='Remove ALL compilers that match spec.')
+ '-a', '--all', action='store_true',
+ help='Remove ALL compilers that match spec.')
remove_parser.add_argument('compiler_spec')
- remove_parser.add_argument('--scope', choices=scopes, default=spack.cmd.default_modify_scope,
- help="Configuration scope to modify.")
+ remove_parser.add_argument(
+ '--scope', choices=scopes, default=spack.cmd.default_modify_scope,
+ help="Configuration scope to modify.")
# List
list_parser = sp.add_parser('list', help='list available compilers')
- list_parser.add_argument('--scope', choices=scopes, default=spack.cmd.default_list_scope,
- help="Configuration scope to read from.")
+ list_parser.add_argument(
+ '--scope', choices=scopes, default=spack.cmd.default_list_scope,
+ help="Configuration scope to read from.")
# Info
info_parser = sp.add_parser('info', help='Show compiler paths.')
info_parser.add_argument('compiler_spec')
- info_parser.add_argument('--scope', choices=scopes, default=spack.cmd.default_list_scope,
- help="Configuration scope to read from.")
+ info_parser.add_argument(
+ '--scope', choices=scopes, default=spack.cmd.default_list_scope,
+ help="Configuration scope to read from.")
def compiler_find(args):
- """Search either $PATH or a list of paths for compilers and add them
- to Spack's configuration."""
+ """Search either $PATH or a list of paths OR MODULES for compilers and
+ add them to Spack's configuration.
+
+ """
paths = args.add_paths
if not paths:
paths = get_path('PATH')
- compilers = [c for c in spack.compilers.find_compilers(*args.add_paths)
- if c.spec not in spack.compilers.all_compilers(scope=args.scope)]
-
- if compilers:
- spack.compilers.add_compilers_to_config(compilers, scope=args.scope)
- n = len(compilers)
+ # Don't initialize compilers config via compilers.get_compiler_config.
+ # Just let compiler_find do the
+ # entire process and return an empty config from all_compilers
+ # Default for any other process is init_config=True
+ compilers = [c for c in spack.compilers.find_compilers(*paths)]
+ new_compilers = []
+ for c in compilers:
+ arch_spec = ArchSpec(None, c.operating_system, c.target)
+ same_specs = spack.compilers.compilers_for_spec(c.spec,
+ arch_spec,
+ args.scope)
+
+ if not same_specs:
+ new_compilers.append(c)
+
+ if new_compilers:
+ spack.compilers.add_compilers_to_config(new_compilers,
+ scope=args.scope,
+ init_config=False)
+ n = len(new_compilers)
s = 's' if n > 1 else ''
filename = spack.config.get_config_filename(args.scope, 'compilers')
tty.msg("Added %d new compiler%s to %s" % (n, s, filename))
- colify(reversed(sorted(c.spec for c in compilers)), indent=4)
+ colify(reversed(sorted(c.spec for c in new_compilers)), indent=4)
else:
tty.msg("Found no new compilers")
@@ -93,17 +118,17 @@ def compiler_find(args):
def compiler_remove(args):
cspec = CompilerSpec(args.compiler_spec)
compilers = spack.compilers.compilers_for_spec(cspec, scope=args.scope)
-
if not compilers:
tty.die("No compilers match spec %s" % cspec)
elif not args.all and len(compilers) > 1:
tty.error("Multiple compilers match spec %s. Choose one:" % cspec)
colify(reversed(sorted([c.spec for c in compilers])), indent=4)
- tty.msg("Or, you can use `spack compiler remove -a` to remove all of them.")
+ tty.msg("Or, use `spack compiler remove -a` to remove all of them.")
sys.exit(1)
for compiler in compilers:
- spack.compilers.remove_compiler_from_config(compiler.spec, scope=args.scope)
+ spack.compilers.remove_compiler_from_config(
+ compiler.spec, scope=args.scope)
tty.msg("Removed compiler %s" % compiler.spec)
@@ -117,17 +142,33 @@ def compiler_info(args):
else:
for c in compilers:
print str(c.spec) + ":"
- print "\tcc = %s" % c.cc
- print "\tcxx = %s" % c.cxx
- print "\tf77 = %s" % c.f77
- print "\tfc = %s" % c.fc
+ print "\tpaths:"
+ for cpath in ['cc', 'cxx', 'f77', 'fc']:
+ print "\t\t%s = %s" % (cpath, getattr(c, cpath, None))
+ if c.flags:
+ print "\tflags:"
+ for flag, flag_value in c.flags.iteritems():
+ print "\t\t%s = %s" % (flag, flag_value)
+ if len(c.environment) != 0:
+ if len(c.environment['set']) != 0:
+ print "\tenvironment:"
+ print "\t set:"
+ for key, value in c.environment['set'].iteritems():
+ print "\t %s = %s" % (key, value)
+ if c.extra_rpaths:
+ print "\tExtra rpaths:"
+ for extra_rpath in c.extra_rpaths:
+ print "\t\t%s" % extra_rpath
+ print "\tmodules = %s" % c.modules
+ print "\toperating system = %s" % c.operating_system
def compiler_list(args):
tty.msg("Available compilers")
index = index_by(spack.compilers.all_compilers(scope=args.scope), 'name')
for i, (name, compilers) in enumerate(index.items()):
- if i >= 1: print
+ if i >= 1:
+ print
cname = "%s{%s}" % (spack.spec.compiler_color, name)
tty.hline(colorize(cname), char='-')
@@ -135,10 +176,10 @@ def compiler_list(args):
def compiler(parser, args):
- action = { 'add' : compiler_find,
- 'find' : compiler_find,
- 'remove' : compiler_remove,
- 'rm' : compiler_remove,
- 'info' : compiler_info,
- 'list' : compiler_list }
+ action = {'add': compiler_find,
+ 'find': compiler_find,
+ 'remove': compiler_remove,
+ 'rm': compiler_remove,
+ 'info': compiler_info,
+ 'list': compiler_list}
action[args.compiler_command](args)