Make Compiler constructor behave like Spec constructor.
This commit is contained in:
		@@ -24,11 +24,20 @@
 | 
			
		||||
##############################################################################
 | 
			
		||||
import llnl.util.tty as tty
 | 
			
		||||
from llnl.util.tty.colify import colify
 | 
			
		||||
from llnl.util.lang import index_by
 | 
			
		||||
 | 
			
		||||
import spack.compilers
 | 
			
		||||
import spack.spec
 | 
			
		||||
 | 
			
		||||
description = "List available compilers"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def compilers(parser, args):
 | 
			
		||||
    tty.msg("Supported compilers")
 | 
			
		||||
    colify(spack.compilers.supported_compilers(), indent=4)
 | 
			
		||||
    tty.msg("Available compilers")
 | 
			
		||||
 | 
			
		||||
    # Index compilers
 | 
			
		||||
    index = index_by(spack.compilers.supported_compilers(), 'name')
 | 
			
		||||
 | 
			
		||||
    for name, compilers in index.items():
 | 
			
		||||
        tty.hline(name, char='=', color=spack.spec.compiler_color)
 | 
			
		||||
        colify(compilers, indent=4)
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@
 | 
			
		||||
import llnl.util.tty as tty
 | 
			
		||||
from llnl.util.tty.colify import colify
 | 
			
		||||
from llnl.util.tty.color import *
 | 
			
		||||
from llnl.util.lang import partition_list
 | 
			
		||||
from llnl.util.lang import partition_list, index_by
 | 
			
		||||
 | 
			
		||||
import spack
 | 
			
		||||
import spack.spec
 | 
			
		||||
@@ -49,9 +49,6 @@ def setup_parser(subparser):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def find(parser, args):
 | 
			
		||||
    def hasher():
 | 
			
		||||
        return collections.defaultdict(hasher)
 | 
			
		||||
 | 
			
		||||
    # Filter out specs that don't exist.
 | 
			
		||||
    query_specs = spack.cmd.parse_specs(args.query_specs)
 | 
			
		||||
    query_specs, nonexisting = partition_list(
 | 
			
		||||
@@ -64,15 +61,9 @@ def hasher():
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
    # Make a dict with specs keyed by architecture and compiler.
 | 
			
		||||
    index = hasher()
 | 
			
		||||
    for spec in spack.db.installed_package_specs():
 | 
			
		||||
        # Check whether this installed package matches any query.
 | 
			
		||||
        if query_specs and not any(spec.satisfies(q) for q in query_specs):
 | 
			
		||||
            continue
 | 
			
		||||
 | 
			
		||||
        if spec.compiler not in index[spec.architecture]:
 | 
			
		||||
            index[spec.architecture][spec.compiler] = []
 | 
			
		||||
        index[spec.architecture][spec.compiler].append(spec)
 | 
			
		||||
    specs = [s for s in spack.db.installed_package_specs()
 | 
			
		||||
             if not query_specs or any(spec.satisfies(q) for q in query_specs)]
 | 
			
		||||
    index = index_by(specs, 'architecture', 'compiler')
 | 
			
		||||
 | 
			
		||||
    # Traverse the index and print out each package
 | 
			
		||||
    for architecture in index:
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
from subprocess import check_output
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _verify_compiler(*paths):
 | 
			
		||||
def _verify_executables(*paths):
 | 
			
		||||
    for path in paths:
 | 
			
		||||
        if not os.path.isfile(path) and os.access(path, os.X_OK):
 | 
			
		||||
            raise InvalidCompilerPathError(path)
 | 
			
		||||
@@ -37,13 +37,13 @@ class Compiler(object):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def __init__(self, cc, cxx, f77, f90):
 | 
			
		||||
        _verify_compiler(cc, cxx, f77, f90)
 | 
			
		||||
        _verify_executables(cc, cxx, f77, f90)
 | 
			
		||||
 | 
			
		||||
        self.cc  = Executable(cc)
 | 
			
		||||
        self.cxx = Executable(cxx)
 | 
			
		||||
        self.f77 = Executable(f77)
 | 
			
		||||
        self.f90 = Executable(f90)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    @memoized
 | 
			
		||||
    def version(self):
 | 
			
		||||
 
 | 
			
		||||
@@ -26,16 +26,19 @@
 | 
			
		||||
# This needs to be expanded for full compiler support.
 | 
			
		||||
#
 | 
			
		||||
from llnl.util.lang import memoized, list_modules
 | 
			
		||||
 | 
			
		||||
import spack
 | 
			
		||||
import spack.compilers.gcc
 | 
			
		||||
import spack.spec
 | 
			
		||||
 | 
			
		||||
@memoized
 | 
			
		||||
def supported_compilers():
 | 
			
		||||
    return [c for c in list_modules(spack.compilers_path)]
 | 
			
		||||
    return [spack.spec.Compiler(c) for c in list_modules(spack.compilers_path)]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def supported(compiler):
 | 
			
		||||
    return compiler in supported_compilers()
 | 
			
		||||
    return True
 | 
			
		||||
#    return compiler in supported_compilers()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@memoized
 | 
			
		||||
 
 | 
			
		||||
@@ -43,14 +43,17 @@
 | 
			
		||||
lib_path       = join_path(prefix, "lib", "spack")
 | 
			
		||||
build_env_path = join_path(lib_path, "env")
 | 
			
		||||
module_path    = join_path(lib_path, "spack")
 | 
			
		||||
compilers_path = join_path(module_path, "compilers")
 | 
			
		||||
test_path      = join_path(module_path, "test")
 | 
			
		||||
 | 
			
		||||
var_path       = join_path(prefix, "var", "spack")
 | 
			
		||||
stage_path     = join_path(var_path, "stage")
 | 
			
		||||
 | 
			
		||||
install_path   = join_path(prefix, "opt")
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Place to look for usable compiler installations
 | 
			
		||||
#
 | 
			
		||||
compilers_path = join_path(var_path, "compilers")
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Set up the packages database.
 | 
			
		||||
#
 | 
			
		||||
 
 | 
			
		||||
@@ -173,10 +173,15 @@ class Compiler(object):
 | 
			
		||||
    """The Compiler field represents the compiler or range of compiler
 | 
			
		||||
       versions that a package should be built with.  Compilers have a
 | 
			
		||||
       name and a version list. """
 | 
			
		||||
    def __init__(self, name, version=None):
 | 
			
		||||
    def __init__(self, compiler_spec_like):
 | 
			
		||||
        c = SpecParser().parse_compiler(compiler_spec_like)
 | 
			
		||||
        self.name = c.name
 | 
			
		||||
        self.versions = c.versions
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def __init__(self, name, version):
 | 
			
		||||
        self.name = name
 | 
			
		||||
        self.versions = VersionList()
 | 
			
		||||
        if version:
 | 
			
		||||
        self.versions.add(version)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -210,7 +215,8 @@ def version(self):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def copy(self):
 | 
			
		||||
        clone = Compiler(self.name)
 | 
			
		||||
        clone = Compiler.__new__(Compiler)
 | 
			
		||||
        clone.name = self.name
 | 
			
		||||
        clone.versions = self.versions.copy()
 | 
			
		||||
        return clone
 | 
			
		||||
 | 
			
		||||
@@ -1188,6 +1194,11 @@ def do_parse(self):
 | 
			
		||||
        return specs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def parse_compiler(self, text):
 | 
			
		||||
        self.setup(text)
 | 
			
		||||
        return self.compiler()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def spec(self):
 | 
			
		||||
        """Parse a spec out of the input.  If a spec is supplied, then initialize
 | 
			
		||||
           and return it instead of creating a new one."""
 | 
			
		||||
@@ -1279,7 +1290,10 @@ def version_list(self):
 | 
			
		||||
    def compiler(self):
 | 
			
		||||
        self.expect(ID)
 | 
			
		||||
        self.check_identifier()
 | 
			
		||||
        compiler = Compiler(self.token.value)
 | 
			
		||||
 | 
			
		||||
        compiler = Compiler.__new__(Compiler)
 | 
			
		||||
        compiler.name = self.token.value
 | 
			
		||||
        compiler.versions = VersionList()
 | 
			
		||||
        if self.accept(AT):
 | 
			
		||||
            vlist = self.version_list()
 | 
			
		||||
            for version in vlist:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user