diff options
-rw-r--r-- | lib/spack/spack/cmd/compilers.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/compiler.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/compilers/__init__.py | 31 | ||||
-rw-r--r-- | lib/spack/spack/compilers/clang.py | 41 | ||||
-rw-r--r-- | lib/spack/spack/compilers/gcc.py | 26 | ||||
-rw-r--r-- | lib/spack/spack/compilers/intel.py | 26 | ||||
-rw-r--r-- | lib/spack/spack/globals.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 32 |
8 files changed, 118 insertions, 53 deletions
diff --git a/lib/spack/spack/cmd/compilers.py b/lib/spack/spack/cmd/compilers.py index f2bf2ed0b1..5658263c26 100644 --- a/lib/spack/spack/cmd/compilers.py +++ b/lib/spack/spack/cmd/compilers.py @@ -31,13 +31,10 @@ import spack.spec description = "List available compilers" - def compilers(parser, args): 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) + tty.hline(name, char='-', color=spack.spec.compiler_color) colify(compilers, indent=4) diff --git a/lib/spack/spack/compiler.py b/lib/spack/spack/compiler.py index 38b7780264..27effa20c4 100644 --- a/lib/spack/spack/compiler.py +++ b/lib/spack/spack/compiler.py @@ -1,10 +1,11 @@ import os +from llnl.util.lang import memoized import spack.error from spack.version import Version -from spack.util import Executable +from spack.util.executable import Executable + -from subprocess import check_output def _verify_executables(*paths): diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py index c6398f736d..4bfb855d94 100644 --- a/lib/spack/spack/compilers/__init__.py +++ b/lib/spack/spack/compilers/__init__.py @@ -27,21 +27,36 @@ # from llnl.util.lang import memoized, list_modules -import spack -import spack.compilers.gcc import spack.spec +from spack.util.executable import which + + @memoized def supported_compilers(): - return [spack.spec.Compiler(c) for c in list_modules(spack.compilers_path)] + """Return a list of compiler types supported by Spack.""" + return sorted(c for c in list_modules(spack.compilers_path)) + +def supported(compiler_spec): + """Test if a particular compiler is supported.""" + if isinstance(compiler_spec, spack.spec.Compiler): + return compiler_spec.name in supported_compilers() -def supported(compiler): - return True -# return compiler in supported_compilers() + elif isinstance(compiler_spec, basestring): + return compiler_spec in supported_compilers() + + else: + raise TypeError("compiler_spec must be string or spack.spec.Compiler") @memoized def default_compiler(): - from spack.spec import Compiler - return Compiler('gcc', gcc.get_version()) + """Get the spec for the default compiler supported by Spack. + Currently just returns the system's default gcc. + + TODO: provide a better way to specify/find this on startup. + """ + gcc = which('gcc', required=True) + version = gcc('-dumpversion', return_output=True) + return spack.spec.Compiler('gcc', version) diff --git a/lib/spack/spack/compilers/clang.py b/lib/spack/spack/compilers/clang.py new file mode 100644 index 0000000000..9ed7b57846 --- /dev/null +++ b/lib/spack/spack/compilers/clang.py @@ -0,0 +1,41 @@ +############################################################################## +# Copyright (c) 2013, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://scalability-llnl.github.io/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License (as published by +# the Free Software Foundation) version 2.1 dated February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +from spack.compiler import Compiler + +class Clang(Compiler): + # Subclasses use possible names of C compiler + cc_names = ['clang'] + + # Subclasses use possible names of C++ compiler + cxx_names = ['clang++'] + + # Subclasses use possible names of Fortran 77 compiler + f77_names = [] + + # Subclasses use possible names of Fortran 90 compiler + f90_names = [] + + def __init__(self, cc, cxx, f77, f90): + super(Gcc, self).__init__(cc, cxx, f77, f90) diff --git a/lib/spack/spack/compilers/gcc.py b/lib/spack/spack/compilers/gcc.py index 073219dc20..638051008f 100644 --- a/lib/spack/spack/compilers/gcc.py +++ b/lib/spack/spack/compilers/gcc.py @@ -22,18 +22,20 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -# -# This is a stub module. It should be expanded when we implement full -# compiler support. -# +from spack.compiler import Compiler + +class Gcc(Compiler): + # Subclasses use possible names of C compiler + cc_names = ['gcc'] + + # Subclasses use possible names of C++ compiler + cxx_names = ['g++'] -import subprocess -from spack.version import Version + # Subclasses use possible names of Fortran 77 compiler + f77_names = ['gfortran'] -cc = 'gcc' -cxx = 'g++' -fortran = 'gfortran' + # Subclasses use possible names of Fortran 90 compiler + f90_names = ['gfortran'] -def get_version(): - v = subprocess.check_output([cc, '-dumpversion']) - return Version(v) + def __init__(self, cc, cxx, f77, f90): + super(Gcc, self).__init__(cc, cxx, f77, f90) diff --git a/lib/spack/spack/compilers/intel.py b/lib/spack/spack/compilers/intel.py index c27fee1719..ebbab57ed1 100644 --- a/lib/spack/spack/compilers/intel.py +++ b/lib/spack/spack/compilers/intel.py @@ -22,18 +22,20 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -# -# This is a stub module. It should be expanded when we implement full -# compiler support. -# +from spack.compiler import Compiler + +class Intel(Compiler): + # Subclasses use possible names of C compiler + cc_names = ['icc'] + + # Subclasses use possible names of C++ compiler + cxx_names = ['icpc'] -import subprocess -from spack.version import Version + # Subclasses use possible names of Fortran 77 compiler + f77_names = ['ifort'] -cc = 'icc' -cxx = 'icc' -fortran = 'ifort' + # Subclasses use possible names of Fortran 90 compiler + f90_names = ['ifort'] -def get_version(): - v = subprocess.check_output([cc, '-dumpversion']) - return Version(v) + def __init__(self, cc, cxx, f77, f90): + super(Gcc, self).__init__(cc, cxx, f77, f90) diff --git a/lib/spack/spack/globals.py b/lib/spack/spack/globals.py index 6c3c5c9645..c67cb02060 100644 --- a/lib/spack/spack/globals.py +++ b/lib/spack/spack/globals.py @@ -43,6 +43,7 @@ spack_file = join_path(prefix, "bin", "spack") 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") @@ -50,9 +51,9 @@ stage_path = join_path(var_path, "stage") install_path = join_path(prefix, "opt") # -# Place to look for usable compiler installations +# Place to look for usable compiler versions. # -compilers_path = join_path(var_path, "compilers") +compiler_version_path = join_path(var_path, "compilers") # # Set up the packages database. diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 900e36a8fb..bb8965ccc8 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -173,16 +173,23 @@ 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, compiler_spec_like): - c = SpecParser().parse_compiler(compiler_spec_like) - self.name = c.name - self.versions = c.versions + def __init__(self, *args): + nargs = len(args) + if nargs == 1: + # If there is one argument, it's a spec to parse + c = SpecParser().parse_compiler(args[0]) + self.name = c.name + self.versions = c.versions + + elif nargs == 2: + name, version = args + self.name = name + self.versions = VersionList() + self.versions.add(ver(version)) - - def __init__(self, name, version): - self.name = name - self.versions = VersionList() - self.versions.add(version) + else: + raise TypeError( + "__init__ takes 1 or 2 arguments. (%d given)" % nargs) def _add_version(self, version): @@ -776,11 +783,10 @@ class Spec(object): if not spec.virtual: spack.db.get(spec.name) - # validate compiler name in addition to the package name. + # validate compiler in addition to the package name. if spec.compiler: - compiler_name = spec.compiler.name - if not spack.compilers.supported(compiler_name): - raise UnknownCompilerError(compiler_name) + if not spack.compilers.supported(spec.compiler): + raise UnknownCompilerError(spec.compiler) def constrain(self, other, **kwargs): |