From c9fbba22a21e75eb83208256ba6365583473e3fa Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 19 Sep 2014 09:50:09 -0700 Subject: First version of AutomaDeD package. --- var/spack/packages/automaded/package.py | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 var/spack/packages/automaded/package.py diff --git a/var/spack/packages/automaded/package.py b/var/spack/packages/automaded/package.py new file mode 100644 index 0000000000..9fbd93e3b3 --- /dev/null +++ b/var/spack/packages/automaded/package.py @@ -0,0 +1,51 @@ +############################################################################## +# 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 import * + +class Automaded(Package): + """AutomaDeD (Automata-based Debugging for Dissimilar parallel + tasks) is a tool for automatic diagnosis of performance and + correctness problems in MPI applications. It creates + control-flow models of each MPI process and, when a failure + occurs, these models are leveraged to find the origin of + problems automatically. MPI calls are intercepted (using + wrappers) to create the models. When an MPI application hangs, + AutomaDeD creates a progress-dependence graph that helps + finding the process (or group of processes) that caused the hang. + """ + + homepage = "https://github.com/scalability-llnl/AutomaDeD" + url = "https://github.com/scalability-llnl/AutomaDeD/archive/v1.0.tar.gz" + + version('1.0', '16a3d4def2c4c77d0bc4b21de8b3ab03') + + depends_on('mpi') + depends_on('boost') + depends_on('callpath') + + def install(self, spec, prefix): + cmake("-DSTATE_TRACKER_WITH_CALLPATH=ON", *std_cmake_args) + make() + make("install") -- cgit v1.2.3-70-g09d2 From 2de2d4bea7689f4421beee526c6ded9199740b6d Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 23 Sep 2014 14:59:30 -0700 Subject: Modify MPI installs to work without fortran. --- lib/spack/spack/__init__.py | 4 ++-- var/spack/packages/mpich/package.py | 16 +++++++++++++--- var/spack/packages/openmpi/package.py | 30 ++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index bf91a885ca..da7088640f 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -137,9 +137,9 @@ sys_type = None # TODO: it's not clear where all the stuff that needs to be included in packages # should live. This file is overloaded for spack core vs. for packages. # -__all__ = ['Package', 'Version', 'when'] +__all__ = ['Package', 'Version', 'when', 'ver'] from spack.package import Package -from spack.version import Version +from spack.version import Version, ver from spack.multimethod import when import llnl.util.filesystem diff --git a/var/spack/packages/mpich/package.py b/var/spack/packages/mpich/package.py index 19a1efe9c3..9062a6bae8 100644 --- a/var/spack/packages/mpich/package.py +++ b/var/spack/packages/mpich/package.py @@ -38,8 +38,18 @@ class Mpich(Package): provides('mpi@:1', when='@1:') def install(self, spec, prefix): - configure( - "--prefix=" + prefix, - "--enable-shared") + config_args = ["--prefix=" + prefix, + "--enable-shared"] + + # TODO: Spack should make it so that you can't actually find + # these compilers if they're "disabled" for the current + # compiler configuration. + if not self.compiler.f77: + config_args.append("--disable-f77") + + if not self.compiler.fc: + config_args.append("--disable-fc") + + configure(*config_args) make() make("install") diff --git a/var/spack/packages/openmpi/package.py b/var/spack/packages/openmpi/package.py index 0ce09bdd8d..1ef8a8f000 100644 --- a/var/spack/packages/openmpi/package.py +++ b/var/spack/packages/openmpi/package.py @@ -10,22 +10,32 @@ class Openmpi(Package): """ homepage = "http://www.open-mpi.org" - url = "http://www.open-mpi.org/software/ompi/v1.6/downloads/openmpi-1.6.5.tar.bz2" - version('1.6.5', '03aed2a4aa4d0b27196962a2a65fc475') + version('1.8.2', 'ab538ed8e328079d566fc797792e016e', + url='http://www.open-mpi.org/software/ompi/v1.8/downloads/openmpi-1.8.2.tar.gz') - provides('mpi@:2') + version('1.6.5', '03aed2a4aa4d0b27196962a2a65fc475', + url = "http://www.open-mpi.org/software/ompi/v1.6/downloads/openmpi-1.6.5.tar.bz2") + patch('ad_lustre_rwcontig_open_source.patch', when="@1.6.5") + patch('llnl-platforms.patch', when="@1.6.5") - patch('ad_lustre_rwcontig_open_source.patch') - patch('llnl-platforms.patch') + provides('mpi@:2') def install(self, spec, prefix): - configure("--prefix=%s" % prefix, - "--with-platform=contrib/platform/lanl/tlcc2/optimized-nopanasas") + config_args = ["--prefix=%s" % prefix] + + # TODO: use variants for this, e.g. +lanl, +llnl, etc. + # use this for LANL builds, but for LLNL builds, we need: + # "--with-platform=contrib/platform/llnl/optimized" + if self.version == ver("1.6.5"): + confg_args.append("--with-platform=contrib/platform/lanl/tlcc2/optimized-nopanasas") - # TODO: implement variants next, so we can have LLNL and LANL options. - # use above for LANL builds, but for LLNL builds, we need this - # "--with-platform=contrib/platform/llnl/optimized") + # TODO: Spack should make it so that you can't actually find + # these compilers if they're "disabled" for the current + # compiler configuration. + if not self.compiler.f77 and not self.compiler.fc: + config_args.append("--enable-mpi-fortran=no") + configure(*config_args) make() make("install") -- cgit v1.2.3-70-g09d2 From bff2192498aa715280a257f62d238a40727483c2 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 23 Sep 2014 21:48:44 -0700 Subject: Added SWIG package. --- var/spack/packages/swig/package.py | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 var/spack/packages/swig/package.py diff --git a/var/spack/packages/swig/package.py b/var/spack/packages/swig/package.py new file mode 100644 index 0000000000..d7a3d815b9 --- /dev/null +++ b/var/spack/packages/swig/package.py @@ -0,0 +1,44 @@ +############################################################################## +# Copyright (c) 2014, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Written by Matthew LeGendre, legendre1@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 import * + +class Swig(Package): + """SWIG is an interface compiler that connects programs written in + C and C++ with scripting languages such as Perl, Python, Ruby, + and Tcl. It works by taking the declarations found in C/C++ + header files and using them to generate the wrapper code that + scripting languages need to access the underlying C/C++ + code. In addition, SWIG provides a variety of customization + features that let you tailor the wrapping process to suit your + application.""" + homepage = "http://www.swig.org" + url = "http://prdownloads.sourceforge.net/swig/swig-3.0.2.tar.gz" + + version('3.0.2', '62f9b0d010cef36a13a010dc530d0d41') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + make() + make("install") -- cgit v1.2.3-70-g09d2 From 608191bd8ccbdca6f9fd2bd638d7a278a652dd36 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 15:32:44 -0700 Subject: Find custom list_urls depending on the archive URL (e.g. github releases) --- lib/spack/spack/package.py | 2 +- lib/spack/spack/url.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 9644aa43d3..0d6c400bd8 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -859,7 +859,7 @@ def find_versions_of_archive(archive_url, **kwargs): list_depth = kwargs.get('list_depth', 1) if not list_url: - list_url = os.path.dirname(archive_url) + list_url = url.find_list_url(archive_url) # This creates a regex from the URL with a capture group for the # version part of the URL. The capture group is converted to a diff --git a/lib/spack/spack/url.py b/lib/spack/spack/url.py index 902ce9817d..e2fbb19f5d 100644 --- a/lib/spack/spack/url.py +++ b/lib/spack/spack/url.py @@ -78,6 +78,26 @@ class UndetectableNameError(UrlParseError): "Couldn't parse package name in: " + path, path) +def find_list_url(url): + """Finds a good list URL for the supplied URL. This depends on + the site. By default, just assumes that a good list URL is the + dirname of an archive path. For github URLs, this returns the + URL of the project's releases page. + """ + + url_types = [ + # e.g. https://github.com/scalability-llnl/callpath/archive/v1.0.1.tar.gz + (r'^(https://github.com/[^/]+/[^/]+)/archive/', lambda m: m.group(1) + '/releases') + ] + + for pattern, fun in url_types: + match = re.search(pattern, url) + if match: + return fun(match) + else: + return os.path.dirname(url) + + def parse_version_string_with_indices(path): """Try to extract a version string from a filename or URL. This is taken largely from Homebrew's Version class.""" -- cgit v1.2.3-70-g09d2 From d7984c7540b23ea8db2e95eb823f198b69a1a913 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 15:33:27 -0700 Subject: Update checksum to print new version syntax. --- lib/spack/spack/cmd/checksum.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py index 5a8109b70f..8a52178833 100644 --- a/lib/spack/spack/cmd/checksum.py +++ b/lib/spack/spack/cmd/checksum.py @@ -117,7 +117,5 @@ def checksum(parser, args): if not version_hashes: tty.die("Could not fetch any available versions for %s." % pkg.name) - dict_string = [" '%s' : '%s'," % (v, h) for v, h in version_hashes] - dict_string = ['{'] + dict_string + ["}"] - - tty.msg("Checksummed new versions of %s:" % pkg.name, *dict_string) + version_lines = [" version('%s', '%s')" % (v, h) for v, h in version_hashes] + tty.msg("Checksummed new versions of %s:" % pkg.name, *version_lines) -- cgit v1.2.3-70-g09d2 From 63292c5826279d67ead30be03d4d954d40c2b342 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 15:39:00 -0700 Subject: Update callpath to 1.0.2 --- var/spack/packages/callpath/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/var/spack/packages/callpath/package.py b/var/spack/packages/callpath/package.py index 84170d9c9e..f78ddcbc0c 100644 --- a/var/spack/packages/callpath/package.py +++ b/var/spack/packages/callpath/package.py @@ -31,6 +31,7 @@ class Callpath(Package): homepage = "https://github.com/scalability-llnl/callpath" url = "https://github.com/scalability-llnl/callpath/archive/v1.0.1.tar.gz" + version('1.0.2', 'b1994d5ee7c7db9d27586fc2dcf8f373') version('1.0.1', '0047983d2a52c5c335f8ba7f5bab2325') depends_on("dyninst") -- cgit v1.2.3-70-g09d2 From 5cc508393a49c9212092356b9d8bf59eb0b488e4 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 16:19:56 -0700 Subject: gfortran version detection brokenon debian. --- lib/spack/spack/compilers/gcc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/compilers/gcc.py b/lib/spack/spack/compilers/gcc.py index 097b24bb87..f0d27d590e 100644 --- a/lib/spack/spack/compilers/gcc.py +++ b/lib/spack/spack/compilers/gcc.py @@ -56,7 +56,7 @@ class Gcc(Compiler): return get_compiler_version( fc, '-dumpversion', # older gfortran versions don't have simple dumpversion output. - r'(?:GNU Fortran \(GCC\))?(\d+\.\d+\.\d+)') + r'(?:GNU Fortran \(GCC\))?(\d+\.\d+(?:\.\d+)?)') @classmethod -- cgit v1.2.3-70-g09d2 From 3bd52678bec6bf7f923d8ebc3073a68d86da7282 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 20:47:38 -0700 Subject: MPICH sets MPI compilers to use real compilers and not spack wrappers. --- lib/spack/llnl/util/filesystem.py | 27 +++++++++++++++++++++++---- var/spack/packages/mpich/package.py | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 3782aefcce..a70111b915 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -38,7 +38,7 @@ import llnl.util.tty as tty from spack.util.compression import ALLOWED_ARCHIVE_TYPES -def filter_file(regex, repl, *filenames): +def filter_file(regex, repl, *filenames, **kwargs): """Like sed, but uses python regular expressions. Filters every line of file through regex and replaces the file @@ -49,16 +49,31 @@ def filter_file(regex, repl, *filenames): return a suitable replacement string. If it is a string, it can contain ``\1``, ``\2``, etc. to represent back-substitution as sed would allow. + + Keyword Options: + string[=False] If True, treat regex as a plain string. + backup[=True] Make a backup files suffixed with ~ + ignore_absent[=False] Ignore any files that don't exist. """ - # Keep callables intact - if not hasattr(repl, '__call__'): - # Allow strings to use \1, \2, etc. for replacement, like sed + string = kwargs.get('string', False) + backup = kwargs.get('backup', True) + ignore_absent = kwargs.get('ignore_absent', False) + + # Allow strings to use \1, \2, etc. for replacement, like sed + if not callable(repl): unescaped = repl.replace(r'\\', '\\') repl = lambda m: re.sub( r'\\([0-9])', lambda x: m.group(int(x.group(1))), unescaped) + if string: + regex = re.escape(regex) + for filename in filenames: backup = filename + "~" + + if ignore_absent and not os.path.exists(filename): + continue + shutil.copy(filename, backup) try: with closing(open(backup)) as infile: @@ -71,6 +86,10 @@ def filter_file(regex, repl, *filenames): shutil.move(backup, filename) raise + finally: + if not backup: + shutil.rmtree(backup, ignore_errors=True) + def change_sed_delimiter(old_delim, new_delim, *filenames): """Find all sed search/replace commands and change the delimiter. diff --git a/var/spack/packages/mpich/package.py b/var/spack/packages/mpich/package.py index 9062a6bae8..57378626ab 100644 --- a/var/spack/packages/mpich/package.py +++ b/var/spack/packages/mpich/package.py @@ -23,6 +23,7 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## from spack import * +import os class Mpich(Package): """MPICH is a high performance and widely portable implementation of @@ -53,3 +54,26 @@ class Mpich(Package): configure(*config_args) make() make("install") + + self.filter_compilers() + + + def filter_compilers(self): + """Run after install to make the MPI compilers use the + compilers that Spack built the package with. + + If this isn't done, they'll have CC, CXX, F77, and FC set + to Spack's generic cc, c++, f77, and f90. We want them to + be bound to whatever compiler they were built with. + """ + bin = self.prefix.bin + mpicc = os.path.join(bin, 'mpicc') + mpicxx = os.path.join(bin, 'mpicxx') + mpif77 = os.path.join(bin, 'mpif77') + mpif90 = os.path.join(bin, 'mpif90') + + kwargs = { 'ignore_absent' : True, 'backup' : False, 'string' : True } + filter_file('CC="cc"', 'CC="%s"' % self.compiler.cc, mpicc, **kwargs) + filter_file('CXX="c++"', 'CXX="%s"' % self.compiler.cxx, mpicxx, **kwargs) + filter_file('F77="f77"', 'F77="%s"' % self.compiler.f77, mpif77, **kwargs) + filter_file('FC="f90"', 'FC="%s"' % self.compiler.fc, mpif90, **kwargs) -- cgit v1.2.3-70-g09d2 From a8ed1ec414c678683628a603a1bb3c76d1319ea6 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 29 Sep 2014 20:00:00 -0700 Subject: Minor argparse improvement. --- lib/spack/external/argparse.py | 6 ++++-- lib/spack/llnl/util/tty/colify.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/spack/external/argparse.py b/lib/spack/external/argparse.py index c8dfdd3bed..42b64ee7be 100644 --- a/lib/spack/external/argparse.py +++ b/lib/spack/external/argparse.py @@ -108,6 +108,8 @@ import re as _re import sys as _sys import textwrap as _textwrap +from llnl.util.tty.colify import colified + from gettext import gettext as _ try: @@ -2285,8 +2287,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def _check_value(self, action, value): # converted value must be one of the choices (if specified) if action.choices is not None and value not in action.choices: - tup = value, ', '.join(map(repr, action.choices)) - msg = _('invalid choice: %r (choose from %s)') % tup + cols = colified(sorted(action.choices), indent=4, tty=True) + msg = _('invalid choice: %r choose from:\n%s') % (value, cols) raise ArgumentError(action, msg) # ======================= diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py index 1b04f1012f..5586b2681a 100644 --- a/lib/spack/llnl/util/tty/colify.py +++ b/lib/spack/llnl/util/tty/colify.py @@ -37,9 +37,11 @@ import sys import fcntl import termios import struct +from StringIO import StringIO from llnl.util.tty import terminal_size + class ColumnConfig: def __init__(self, cols): self.cols = cols @@ -102,16 +104,18 @@ def colify(elts, **options): output = options.get("output", sys.stdout) indent = options.get("indent", 0) padding = options.get("padding", 2) + tty = options.get('tty', None) # elts needs to be an array of strings so we can count the elements elts = [str(elt) for elt in elts] if not elts: return - if not isatty(output): - for elt in elts: - output.write("%s\n" % elt) - return + if not tty: + if tty is False or not isatty(output): + for elt in elts: + output.write("%s\n" % elt) + return console_cols = options.get("cols", None) if not console_cols: @@ -147,6 +151,15 @@ def colify(elts, **options): cols -= 1 +def colified(elts, **options): + """Invokes the colify() function but returns the result as a string + instead of writing it to an output string.""" + sio = StringIO() + options['output'] = sio + colify(elts, **options) + return sio.getvalue() + + if __name__ == "__main__": import optparse -- cgit v1.2.3-70-g09d2 From 70475d08c0c05176f9ba8bb36d71dd8b80a40f84 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 29 Sep 2014 22:39:36 -0700 Subject: Bugfix for spack cd -h --- share/spack/csh/spack.csh | 11 ++++++++++- share/spack/setup-env.sh | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/share/spack/csh/spack.csh b/share/spack/csh/spack.csh index 30c4ec1361..b21da23836 100644 --- a/share/spack/csh/spack.csh +++ b/share/spack/csh/spack.csh @@ -46,8 +46,17 @@ set _sp_spec="" set _sp_modtype = "" switch ($_sp_subcommand) case cd: + shift _sp_args # get rid of 'cd' + + set _sp_arg="" + [ $#_sp_args -gt 0 ] && set _sp_arg = ($_sp_args[1]) shift _sp_args - cd `spack location $_sp_args` + + if ( "$_sp_arg" == "-h" ) then + \spack cd -h + else + cd `\spack location $_sp_arg $_sp_args` + endif breaksw case use: case unuse: diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index 6f56d4739b..91b1dc4630 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -76,7 +76,12 @@ function spack { # command. case $_sp_subcommand in "cd") - cd $(spack location "$@") + _sp_arg="$1"; shift + if [ "$_sp_arg" = "-h" ]; then + command spack cd -h + else + cd $(spack location $_sp_arg "$@") + fi return ;; "use"|"unuse"|"load"|"unload") -- cgit v1.2.3-70-g09d2 From e4613a60cfa47f30c67173e9298e9b2672d91603 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 29 Sep 2014 22:43:40 -0700 Subject: Fix for spack cd -i. --- lib/spack/spack/cmd/location.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/location.py b/lib/spack/spack/cmd/location.py index 074d984ee6..116cf6ee6c 100644 --- a/lib/spack/spack/cmd/location.py +++ b/lib/spack/spack/cmd/location.py @@ -48,6 +48,9 @@ def setup_parser(subparser): directories.add_argument( '-p', '--package-dir', action='store_true', help="Directory enclosing a spec's package.py file.") + directories.add_argument( + '-P', '--packages', action='store_true', + help="Top-level packages directory for Spack.") directories.add_argument( '-s', '--stage-dir', action='store_true', help="Stage directory for a spec.") directories.add_argument( @@ -65,21 +68,39 @@ def location(parser, args): elif args.spack_root: print spack.prefix + elif args.packages: + print spack.db.root + else: - specs = spack.cmd.parse_specs(args.spec, concretize=True) + specs = spack.cmd.parse_specs(args.spec) if not specs: tty.die("You must supply a spec.") if len(specs) != 1: - tty.die("Too many specs. Need only one.") + tty.die("Too many specs. Supply only one.") spec = specs[0] if args.install_dir: - print spec.prefix + # install_dir command matches against installed specs. + matching_specs = spack.db.get_installed(spec) + if not matching_specs: + tty.die("Spec '%s' matches no installed packages." % spec) + + elif len(matching_specs) > 1: + args = ["%s matches multiple packages." % spec, + "Matching packages:"] + args += [" " + str(s) for s in matching_specs] + args += ["Use a more specific spec."] + tty.die(*args) + + print matching_specs[0].prefix elif args.package_dir: + # This one just needs the spec name. print join_path(spack.db.root, spec.name) else: + # These versions need concretized specs. + spec.concretize() pkg = spack.db.get(spec) if args.stage_dir: -- cgit v1.2.3-70-g09d2 From 26495ddce940dbf47c8b1bc84d4fdb8ff61217df Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 29 Sep 2014 23:27:40 -0700 Subject: Reverse sort output versions in spack checksum --- lib/spack/spack/cmd/checksum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py index 8a52178833..f9218b9df1 100644 --- a/lib/spack/spack/cmd/checksum.py +++ b/lib/spack/spack/cmd/checksum.py @@ -96,7 +96,7 @@ def checksum(parser, args): if not versions: tty.die("Could not fetch any available versions for %s." % pkg.name) - versions = list(reversed(versions)) + versions = list(reversed(sorted(versions))) urls = [pkg.url_for_version(v) for v in versions] -- cgit v1.2.3-70-g09d2 From 921a5b5bcc43de88ced7ec9e2fdd5d3dc8eebd21 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 29 Sep 2014 23:28:16 -0700 Subject: Make fetch fail on 404. --- lib/spack/spack/stage.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 3dac798396..e2e156e916 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -224,6 +224,7 @@ class Stage(object): # Run curl but grab the mime type from the http headers headers = spack.curl('-#', # status bar '-O', # save file to disk + '-f', # fail on >400 errors '-D', '-', # print out HTML headers '-L', url, return_output=True, fail_on_error=False) @@ -233,6 +234,10 @@ class Stage(object): if self.archive_file: os.remove(self.archive_file) + if spack.curl.returncode == 22: + # This is a 404. Curl will print the error. + raise FailedDownloadError(url) + if spack.curl.returncode == 60: # This is a certificate error. Suggest spack -k raise FailedDownloadError( -- cgit v1.2.3-70-g09d2 From 13eca0357fc1d61b74a339867ae628e978b39dc8 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 29 Sep 2014 23:30:48 -0700 Subject: Bugfix for version substitution. --- lib/spack/spack/package.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 0d6c400bd8..91419e3a3f 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -551,7 +551,8 @@ class Package(object): base_url, self.url_version(version)) return vdesc.url else: - return nearest_url(version) + base_url = nearest_url(version) + return url.substitute_version(base_url, self.url_version(version)) @property -- cgit v1.2.3-70-g09d2 From 720ced4c2e00f01d894e64650539464ce841807b Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 30 Sep 2014 00:09:11 -0700 Subject: Add test for URL version substitution. --- lib/spack/spack/test/__init__.py | 1 + lib/spack/spack/test/url_substitution.py | 73 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 lib/spack/spack/test/url_substitution.py diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index 8ddc7f227d..e245d30f39 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -36,6 +36,7 @@ import spack.test.install """Names of tests to be included in Spack's test suite""" test_names = ['versions', 'url_parse', + 'url_substitution', 'packages', 'stage', 'spec_syntax', diff --git a/lib/spack/spack/test/url_substitution.py b/lib/spack/spack/test/url_substitution.py new file mode 100644 index 0000000000..db7ddd251d --- /dev/null +++ b/lib/spack/spack/test/url_substitution.py @@ -0,0 +1,73 @@ +############################################################################## +# 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 +############################################################################## +"""\ +This test does sanity checks on substituting new versions into URLs +""" +import unittest + +import spack +import spack.url as url +from spack.packages import PackageDB + + +class PackageSanityTest(unittest.TestCase): + def test_hypre_url_substitution(self): + base = "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-2.9.0b.tar.gz" + + self.assertEqual(url.substitute_version(base, '2.9.0b'), base) + self.assertEqual( + url.substitute_version(base, '2.8.0b'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-2.8.0b.tar.gz") + self.assertEqual( + url.substitute_version(base, '2.7.0b'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-2.7.0b.tar.gz") + self.assertEqual( + url.substitute_version(base, '2.6.0b'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-2.6.0b.tar.gz") + self.assertEqual( + url.substitute_version(base, '1.14.0b'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-1.14.0b.tar.gz") + self.assertEqual( + url.substitute_version(base, '1.13.0b'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-1.13.0b.tar.gz") + self.assertEqual( + url.substitute_version(base, '2.0.0'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-2.0.0.tar.gz") + self.assertEqual( + url.substitute_version(base, '1.6.0'), + "https://computation-rnd.llnl.gov/linear_solvers/download/hypre-1.6.0.tar.gz") + + + def test_otf2_url_substitution(self): + base = "http://www.vi-hps.org/upload/packages/otf2/otf2-1.4.tar.gz" + + self.assertEqual(url.substitute_version(base, '1.4'), base) + + self.assertEqual( + url.substitute_version(base, '1.3.1'), + "http://www.vi-hps.org/upload/packages/otf2/otf2-1.3.1.tar.gz") + self.assertEqual( + url.substitute_version(base, '1.2.1'), + "http://www.vi-hps.org/upload/packages/otf2/otf2-1.2.1.tar.gz") -- cgit v1.2.3-70-g09d2 From 52d140c3370bfe42dafe4568d02fef9f34cc8622 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 25 Aug 2014 01:11:12 -0700 Subject: Factor out URL fetching into URLFetchStrategy - Added FetchStrategy class to Spack - Isolated pieces that need to be separate from Stage for git/svn/http - Added URLFetchStrategy for curl-based fetching. --- lib/spack/spack/fetch_strategy.py | 222 ++++++++++++++++++++++++++++++++++++++ lib/spack/spack/package.py | 20 ++-- lib/spack/spack/relations.py | 2 +- lib/spack/spack/stage.py | 175 +++++++++++++----------------- lib/spack/spack/test/stage.py | 8 +- 5 files changed, 310 insertions(+), 117 deletions(-) create mode 100644 lib/spack/spack/fetch_strategy.py diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py new file mode 100644 index 0000000000..2811c0e92b --- /dev/null +++ b/lib/spack/spack/fetch_strategy.py @@ -0,0 +1,222 @@ +############################################################################## +# 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 +############################################################################## +""" +Fetch strategies are used to download source code into a staging area +in order to build it. They need to define the following methods: + + * fetch() + This should attempt to download/check out source from somewhere. + * check() + Apply a checksum to the downloaded source code, e.g. for an archive. + May not do anything if the fetch method was safe to begin with. + * expand() + Expand (e.g., an archive) downloaded file to source. + * reset() + Restore original state of downloaded code. Used by clean commands. + This may just remove the expanded source and re-expand an archive, + or it may run something like git reset --hard. +""" +import os +import re +import shutil + +import llnl.util.tty as tty + +import spack +import spack.error +import spack.util.crypto as crypto +from spack.util.compression import decompressor_for + + +class FetchStrategy(object): + def __init__(self): + # The stage is initialized late, so that fetch strategies can be constructed + # at package construction time. This is where things will be fetched. + self.stage = None + + + def set_stage(self, stage): + """This is called by Stage before any of the fetching + methods are called on the stage.""" + self.stage = stage + + + # Subclasses need to implement tehse methods + def fetch(self): pass # Return True on success, False on fail + def check(self): pass + def expand(self): pass + def reset(self): pass + def __str__(self): pass + + + +class URLFetchStrategy(FetchStrategy): + + def __init__(self, url, digest=None): + super(URLFetchStrategy, self).__init__() + self.url = url + self.digest = digest + + + def fetch(self): + assert(self.stage) + + self.stage.chdir() + + if self.archive_file: + tty.msg("Already downloaded %s." % self.archive_file) + return + + tty.msg("Trying to fetch from %s" % self.url) + + # Run curl but grab the mime type from the http headers + headers = spack.curl('-#', # status bar + '-O', # save file to disk + '-D', '-', # print out HTML headers + '-L', self.url, + return_output=True, fail_on_error=False) + + if spack.curl.returncode != 0: + # clean up archive on failure. + if self.archive_file: + os.remove(self.archive_file) + + if spack.curl.returncode == 60: + # This is a certificate error. Suggest spack -k + raise FailedDownloadError( + self.url, + "Curl was unable to fetch due to invalid certificate. " + "This is either an attack, or your cluster's SSL configuration " + "is bad. If you believe your SSL configuration is bad, you " + "can try running spack -k, which will not check SSL certificates." + "Use this at your own risk.") + + # Check if we somehow got an HTML file rather than the archive we + # asked for. We only look at the last content type, to handle + # redirects properly. + content_types = re.findall(r'Content-Type:[^\r\n]+', headers) + if content_types and 'text/html' in content_types[-1]: + tty.warn("The contents of " + self.archive_file + " look like HTML.", + "The checksum will likely be bad. If it is, you can use", + "'spack clean --dist' to remove the bad archive, then fix", + "your internet gateway issue and install again.") + + if not self.archive_file: + raise FailedDownloadError(self.url) + + + @property + def archive_file(self): + """Path to the source archive within this stage directory.""" + assert(self.stage) + path = os.path.join(self.stage.path, os.path.basename(self.url)) + return path if os.path.exists(path) else None + + + def expand(self): + assert(self.stage) + tty.msg("Staging archive: %s" % self.archive_file) + + self.stage.chdir() + if not self.archive_file: + raise NoArchiveFileError("URLFetchStrategy couldn't find archive file", + "Failed on expand() for URL %s" % self.url) + + print self.archive_file + + decompress = decompressor_for(self.archive_file) + decompress(self.archive_file) + + + def check(self): + """Check the downloaded archive against a checksum digest. + No-op if this stage checks code out of a repository.""" + assert(self.stage) + if not self.digest: + raise NoDigestError("Attempt to check URLFetchStrategy with no digest.") + checker = crypto.Checker(digest) + if not checker.check(self.archive_file): + raise ChecksumError( + "%s checksum failed for %s." % (checker.hash_name, self.archive_file), + "Expected %s but got %s." % (digest, checker.sum)) + + + def reset(self): + """Removes the source path if it exists, then re-expands the archive.""" + assert(self.stage) + if not self.archive_file: + raise NoArchiveFileError("Tried to reset URLFetchStrategy before fetching", + "Failed on reset() for URL %s" % self.url) + if self.stage.source_path: + shutil.rmtree(self.stage.source_path, ignore_errors=True) + self.expand() + + + def __str__(self): + return self.url + + + +class GitFetchStrategy(FetchStrategy): + pass + + +class SvnFetchStrategy(FetchStrategy): + pass + + +def strategy_for_url(url): + """Given a URL, find an appropriate fetch strategy for it. + Currently just gives you a URLFetchStrategy that uses curl. + + TODO: make this return appropriate fetch strategies for other + types of URLs. + """ + return URLFetchStrategy(url) + + +class FetchStrategyError(spack.error.SpackError): + def __init__(self, msg, long_msg): + super(FetchStrategyError, self).__init__(msg, long_msg) + + +class FailedDownloadError(FetchStrategyError): + """Raised wen a download fails.""" + def __init__(self, url, msg=""): + super(FailedDownloadError, self).__init__( + "Failed to fetch file from URL: %s" % url, msg) + self.url = url + + +class NoArchiveFileError(FetchStrategyError): + def __init__(self, msg, long_msg): + super(NoArchiveFileError, self).__init__(msg, long_msg) + + +class NoDigestError(FetchStrategyError): + def __init__(self, msg, long_msg): + super(NoDigestError, self).__init__(msg, long_msg) + + diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 9644aa43d3..f5f1c9dec6 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -337,7 +337,7 @@ class Package(object): # Sanity check some required variables that could be # overridden by package authors. - def sanity_check_dict(attr_name): + def ensure_has_dict(attr_name): if not hasattr(self, attr_name): raise PackageError("Package %s must define %s" % attr_name) @@ -345,10 +345,10 @@ class Package(object): if not isinstance(attr, dict): raise PackageError("Package %s has non-dict %s attribute!" % (self.name, attr_name)) - sanity_check_dict('versions') - sanity_check_dict('dependencies') - sanity_check_dict('conflicted') - sanity_check_dict('patches') + ensure_has_dict('versions') + ensure_has_dict('dependencies') + ensure_has_dict('conflicted') + ensure_has_dict('patches') # Check versions in the versions dict. for v in self.versions: @@ -362,9 +362,8 @@ class Package(object): # Version-ize the keys in versions dict try: self.versions = dict((Version(v), h) for v,h in self.versions.items()) - except ValueError: - raise ValueError("Keys of versions dict in package %s must be versions!" - % self.name) + except ValueError, e: + raise ValueError("In package %s: %s" % (self.name, e.message)) # stage used to build this package. self._stage = None @@ -600,9 +599,8 @@ class Package(object): self.do_fetch() - archive_dir = self.stage.expanded_archive_path + archive_dir = self.stage.source_path if not archive_dir: - tty.msg("Staging archive: %s" % self.stage.archive_file) self.stage.expand_archive() tty.msg("Created stage directory in %s." % self.stage.path) else: @@ -620,7 +618,7 @@ class Package(object): # Construct paths to special files in the archive dir used to # keep track of whether patches were successfully applied. - archive_dir = self.stage.expanded_archive_path + archive_dir = self.stage.source_path good_file = join_path(archive_dir, '.spack_patched') bad_file = join_path(archive_dir, '.spack_patch_failed') diff --git a/lib/spack/spack/relations.py b/lib/spack/spack/relations.py index 5afb7e7624..f7e1cfd925 100644 --- a/lib/spack/spack/relations.py +++ b/lib/spack/spack/relations.py @@ -95,7 +95,7 @@ class VersionDescriptor(object): def version(ver, checksum, **kwargs): - """Adds a version and associated metadata to the package.""" + """Adds a version and metadata describing how to fetch it.""" pkg = caller_locals() versions = pkg.setdefault('versions', {}) diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 3dac798396..0fa315051f 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -32,18 +32,20 @@ from llnl.util.filesystem import * import spack import spack.config +from spack.fetch_strategy import strategy_for_url, URLFetchStrategy import spack.error -import spack.util.crypto as crypto -from spack.util.compression import decompressor_for + STAGE_PREFIX = 'spack-stage-' class Stage(object): - """A Stage object manaages a directory where an archive is downloaded, - expanded, and built before being installed. It also handles downloading - the archive. A stage's lifecycle looks like this: + """A Stage object manaages a directory where some source code is + downloaded and built before being installed. It handles + fetching the source code, either as an archive to be expanded + or by checking it out of a repository. A stage's lifecycle + looks like this: Stage() Constructor creates the stage directory. @@ -71,18 +73,24 @@ class Stage(object): def __init__(self, url, **kwargs): """Create a stage object. Parameters: - url URL of the archive to be downloaded into this stage. - - name If a name is provided, then this stage is a named stage - and will persist between runs (or if you construct another - stage object later). If name is not provided, then this - stage will be given a unique name automatically. + url_or_fetch_strategy + URL of the archive to be downloaded into this stage, OR + a valid FetchStrategy. + + name + If a name is provided, then this stage is a named stage + and will persist between runs (or if you construct another + stage object later). If name is not provided, then this + stage will be given a unique name automatically. """ + if isinstance(url, basestring): + self.fetcher = strategy_for_url(url) + self.fetcher.set_stage(self) + self.name = kwargs.get('name') self.mirror_path = kwargs.get('mirror_path') self.tmp_root = find_tmp_root() - self.url = url self.path = None self._setup() @@ -198,17 +206,17 @@ class Stage(object): @property - def expanded_archive_path(self): - """Returns the path to the expanded archive directory if it's expanded; - None if the archive hasn't been expanded. - """ - if not self.archive_file: - return None + def source_path(self): + """Returns the path to the expanded/checked out source code + within this fetch strategy's path. - for file in os.listdir(self.path): - archive_path = join_path(self.path, file) - if os.path.isdir(archive_path): - return archive_path + This assumes nothing else is going ot be put in the + FetchStrategy's path. It searches for the first + subdirectory of the path it can find, then returns that. + """ + for p in [os.path.join(self.path, f) for f in os.listdir(self.path)]: + if os.path.isdir(p): + return p return None @@ -220,71 +228,35 @@ class Stage(object): tty.die("Setup failed: no such directory: " + self.path) - def fetch_from_url(self, url): - # Run curl but grab the mime type from the http headers - headers = spack.curl('-#', # status bar - '-O', # save file to disk - '-D', '-', # print out HTML headers - '-L', url, - return_output=True, fail_on_error=False) - - if spack.curl.returncode != 0: - # clean up archive on failure. - if self.archive_file: - os.remove(self.archive_file) - - if spack.curl.returncode == 60: - # This is a certificate error. Suggest spack -k - raise FailedDownloadError( - url, - "Curl was unable to fetch due to invalid certificate. " - "This is either an attack, or your cluster's SSL configuration " - "is bad. If you believe your SSL configuration is bad, you " - "can try running spack -k, which will not check SSL certificates." - "Use this at your own risk.") - - # Check if we somehow got an HTML file rather than the archive we - # asked for. We only look at the last content type, to handle - # redirects properly. - content_types = re.findall(r'Content-Type:[^\r\n]+', headers) - if content_types and 'text/html' in content_types[-1]: - tty.warn("The contents of " + self.archive_file + " look like HTML.", - "The checksum will likely be bad. If it is, you can use", - "'spack clean --dist' to remove the bad archive, then fix", - "your internet gateway issue and install again.") - - def fetch(self): - """Downloads the file at URL to the stage. Returns true if it was downloaded, - false if it already existed.""" + """Downloads an archive or checks out code from a repository.""" self.chdir() - if self.archive_file: - tty.msg("Already downloaded %s." % self.archive_file) - - else: - urls = [self.url] - if self.mirror_path: - urls = ["%s/%s" % (m, self.mirror_path) for m in _get_mirrors()] + urls - for url in urls: - tty.msg("Trying to fetch from %s" % url) - self.fetch_from_url(url) - if self.archive_file: - break + fetchers = [self.fetcher] - if not self.archive_file: - raise FailedDownloadError(url) - - return self.archive_file + # TODO: move mirror logic out of here and clean it up! + if self.mirror_path: + urls = ["%s/%s" % (m, self.mirror_path) for m in _get_mirrors()] + digest = None + if isinstance(self.fetcher, URLFetchStrategy): + digest = self.fetcher.digest + fetchers = [URLFetchStrategy(url, digest) for url in urls] + fetchers + for f in fetchers: + f.set_stage(self) + + for fetcher in fetchers: + try: + fetcher.fetch() + break + except spack.error.SpackError, e: + tty.msg("Download from %s failed." % fetcher) + continue def check(self, digest): - """Check the downloaded archive against a checksum digest""" - checker = crypto.Checker(digest) - if not checker.check(self.archive_file): - raise ChecksumError( - "%s checksum failed for %s." % (checker.hash_name, self.archive_file), - "Expected %s but got %s." % (digest, checker.sum)) + """Check the downloaded archive against a checksum digest. + No-op if this stage checks code out of a repository.""" + self.fetcher.check() def expand_archive(self): @@ -292,19 +264,14 @@ class Stage(object): archive. Fail if the stage is not set up or if the archive is not yet downloaded. """ - self.chdir() - if not self.archive_file: - tty.die("Attempt to expand archive before fetching.") - - decompress = decompressor_for(self.archive_file) - decompress(self.archive_file) + self.fetcher.expand() def chdir_to_archive(self): """Changes directory to the expanded archive directory. Dies with an error if there was no expanded archive. """ - path = self.expanded_archive_path + path = self.source_path if not path: tty.die("Attempt to chdir before expanding archive.") else: @@ -317,12 +284,7 @@ class Stage(object): """Removes the expanded archive path if it exists, then re-expands the archive. """ - if not self.archive_file: - tty.die("Attempt to restage when not staged.") - - if self.expanded_archive_path: - shutil.rmtree(self.expanded_archive_path, True) - self.expand_archive() + self.fetcher.reset() def destroy(self): @@ -393,15 +355,26 @@ def find_tmp_root(): return None -class FailedDownloadError(spack.error.SpackError): - """Raised wen a download fails.""" - def __init__(self, url, msg=""): - super(FailedDownloadError, self).__init__( - "Failed to fetch file from URL: %s" % url, msg) - self.url = url +class StageError(spack.error.SpackError): + def __init__(self, message, long_message=None): + super(self, StageError).__init__(message, long_message) -class ChecksumError(spack.error.SpackError): +class ChecksumError(StageError): """Raised when archive fails to checksum.""" - def __init__(self, message, long_msg): + def __init__(self, message, long_msg=None): super(ChecksumError, self).__init__(message, long_msg) + + +class RestageError(StageError): + def __init__(self, message, long_msg=None): + super(RestageError, self).__init__(message, long_msg) + + +class ChdirError(StageError): + def __init__(self, message, long_msg=None): + super(ChdirError, self).__init__(message, long_msg) + + +# Keep this in namespace for convenience +FailedDownloadError = spack.fetch_strategy.FailedDownloadError diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py index a412549dc7..8cb7ac772e 100644 --- a/lib/spack/spack/test/stage.py +++ b/lib/spack/spack/test/stage.py @@ -146,7 +146,7 @@ class StageTest(unittest.TestCase): stage_path = self.get_stage_path(stage, stage_name) self.assertTrue(archive_name in os.listdir(stage_path)) self.assertEqual(join_path(stage_path, archive_name), - stage.archive_file) + stage.fetcher.archive_file) def check_expand_archive(self, stage, stage_name): @@ -156,7 +156,7 @@ class StageTest(unittest.TestCase): self.assertEqual( join_path(stage_path, archive_dir), - stage.expanded_archive_path) + stage.source_path) readme = join_path(stage_path, archive_dir, readme_name) self.assertTrue(os.path.isfile(readme)) @@ -292,7 +292,7 @@ class StageTest(unittest.TestCase): with closing(open('foobar', 'w')) as file: file.write("this file is to be destroyed.") - self.assertTrue('foobar' in os.listdir(stage.expanded_archive_path)) + self.assertTrue('foobar' in os.listdir(stage.source_path)) # Make sure the file is not there after restage. stage.restage() @@ -301,7 +301,7 @@ class StageTest(unittest.TestCase): stage.chdir_to_archive() self.check_chdir_to_archive(stage, stage_name) - self.assertFalse('foobar' in os.listdir(stage.expanded_archive_path)) + self.assertFalse('foobar' in os.listdir(stage.source_path)) stage.destroy() self.check_destroy(stage, stage_name) -- cgit v1.2.3-70-g09d2 From 0cc79e05642c78932f87d06f272bad6602b3cbfe Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 5 Sep 2014 10:48:18 -0700 Subject: Implement per-version attributes for flexible fetch policies. - Tests pass with URL fetching and new scheme. - Lots of refactoring - Infrastructure is there for arbitrary fetch policies and more attribtues on the version() call. - Mirrors do not currently work properly, and they get in the way of a proper git fetch --- lib/spack/spack/fetch_strategy.py | 163 ++++++++++++++++++++++++++++++--- lib/spack/spack/package.py | 116 +++++++++++++++-------- lib/spack/spack/patch.py | 2 +- lib/spack/spack/relations.py | 28 +++--- lib/spack/spack/stage.py | 23 +++-- lib/spack/spack/test/install.py | 8 +- lib/spack/spack/test/package_sanity.py | 6 +- lib/spack/spack/test/stage.py | 14 +-- 8 files changed, 273 insertions(+), 87 deletions(-) diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 2811c0e92b..b0845700b6 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -47,9 +47,11 @@ import llnl.util.tty as tty import spack import spack.error import spack.util.crypto as crypto +from spack.version import Version, ver from spack.util.compression import decompressor_for + class FetchStrategy(object): def __init__(self): # The stage is initialized late, so that fetch strategies can be constructed @@ -63,21 +65,37 @@ class FetchStrategy(object): self.stage = stage - # Subclasses need to implement tehse methods + # Subclasses need to implement these methods def fetch(self): pass # Return True on success, False on fail def check(self): pass def expand(self): pass def reset(self): pass - def __str__(self): pass + def __str__(self): + return "FetchStrategy.__str___" + # This method is used to match fetch strategies to version() + # arguments in packages. + @classmethod + def match(kwargs): + return any(k in kwargs for k in self.attributes) class URLFetchStrategy(FetchStrategy): + attributes = ('url', 'md5') - def __init__(self, url, digest=None): + def __init__(self, url=None, digest=None, **kwargs): super(URLFetchStrategy, self).__init__() - self.url = url - self.digest = digest + + # If URL or digest are provided in the kwargs, then prefer + # those values. + self.url = kwargs.get('url', None) + if not self.url: self.url = url + + self.digest = kwargs.get('md5', None) + if not self.digest: self.digest = digest + + if not self.url: + raise ValueError("URLFetchStrategy requires a url for fetching.") def fetch(self): @@ -142,9 +160,7 @@ class URLFetchStrategy(FetchStrategy): self.stage.chdir() if not self.archive_file: raise NoArchiveFileError("URLFetchStrategy couldn't find archive file", - "Failed on expand() for URL %s" % self.url) - - print self.archive_file + "Failed on expand() for URL %s" % self.url) decompress = decompressor_for(self.archive_file) decompress(self.archive_file) @@ -175,19 +191,117 @@ class URLFetchStrategy(FetchStrategy): def __str__(self): - return self.url + if self.url: + return self.url + else: + return "URLFetchStrategy " +class VCSFetchStrategy(FetchStrategy): + def __init__(self, name): + super(VCSFetchStrategy, self).__init__() + self.name = name + + + def check(self): + assert(self.stage) + tty.msg("No check needed when fetching with %s." % self.name) + + def expand(self): + assert(self.stage) + tty.debug("Source fetched with %s is already expanded." % self.name) + + + +class GitFetchStrategy(VCSFetchStrategy): + attributes = ('git', 'ref', 'tag', 'branch') + + def __init__(self, **kwargs): + super(GitFetchStrategy, self).__init__("git") + self.url = kwargs.get('git', None) + if not self.url: + raise ValueError("GitFetchStrategy requires git argument.") + + if sum((k in kwargs for k in ('ref', 'tag', 'branch'))) > 1: + raise FetchStrategyError( + "Git requires exactly one ref, branch, or tag.") + + self._git = None + self.ref = kwargs.get('ref', None) + self.branch = kwargs.get('branch', None) + if not self.branch: + self.branch = kwargs.get('tag', None) + + + @property + def git_version(self): + git = which('git', required=True) + vstring = git('--version', return_output=True).lstrip('git version ') + return Version(vstring) + + + @property + def git(self): + if not self._git: + self._git = which('git', required=True) + return self._git + + + def fetch(self): + assert(self.stage) + self.stage.chdir() + + if self.stage.source_path: + tty.msg("Already fetched %s." % self.source_path) + return + + tty.msg("Trying to clone git repository: %s" % self.url) -class GitFetchStrategy(FetchStrategy): - pass + + if self.ref: + # Need to do a regular clone and check out everything if + # they asked for a particular ref. + git('clone', self.url) + self.chdir_to_source() + git('checkout', self.ref) + + else: + # Can be more efficient if not checking out a specific ref. + args = ['clone'] + + # If we want a particular branch ask for it. + if self.branch: + args.extend(['--branch', self.branch]) + + # Try to be efficient if we're using a new enough git. + # This checks out only one branch's history + if self.git_version > ver('1.7.10'): + args.append('--single-branch') + + args.append(self.url) + git(*args) + self.chdir_to_source() + + + def reset(self): + assert(self.stage) + git = which('git', required=True) + + self.stage.chdir_to_source() + git('checkout', '.') + git('clean', '-f') + + + def __str__(self): + return self.url class SvnFetchStrategy(FetchStrategy): + attributes = ('svn', 'rev', 'revision') pass -def strategy_for_url(url): +def from_url(url): """Given a URL, find an appropriate fetch strategy for it. Currently just gives you a URLFetchStrategy that uses curl. @@ -197,6 +311,27 @@ def strategy_for_url(url): return URLFetchStrategy(url) +def args_are_for(args, fetcher): + return any(arg in args for arg in fetcher.attributes) + + +def from_args(args, pkg): + """Determine a fetch strategy based on the arguments supplied to + version() in the package description.""" + fetchers = (URLFetchStrategy, GitFetchStrategy) + for fetcher in fetchers: + if args_are_for(args, fetcher): + attrs = {} + for attr in fetcher.attributes: + default = getattr(pkg, attr, None) + if default: + attrs[attr] = default + + attrs.update(args) + return fetcher(**attrs) + + return None + class FetchStrategyError(spack.error.SpackError): def __init__(self, msg, long_msg): super(FetchStrategyError, self).__init__(msg, long_msg) @@ -220,3 +355,7 @@ class NoDigestError(FetchStrategyError): super(NoDigestError, self).__init__(msg, long_msg) +class InvalidArgsError(FetchStrategyError): + def __init__(self, msg, long_msg): + super(InvalidArgsError, self).__init__(msg, long_msg) + diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index f5f1c9dec6..553e0118e3 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -52,6 +52,7 @@ import spack.compilers import spack.hooks import spack.build_environment as build_env import spack.url as url +import spack.fetch_strategy as fs from spack.version import * from spack.stage import Stage from spack.util.web import get_pages @@ -300,7 +301,7 @@ class Package(object): # These variables are defaults for the various "relations". # """Map of information about Versions of this package. - Map goes: Version -> VersionDescriptor""" + Map goes: Version -> dict of attributes""" versions = {} """Specs of dependency packages, keyed by name.""" @@ -356,8 +357,7 @@ class Package(object): # Check version descriptors for v in sorted(self.versions): - vdesc = self.versions[v] - assert(isinstance(vdesc, spack.relations.VersionDescriptor)) + assert(isinstance(self.versions[v], dict)) # Version-ize the keys in versions dict try: @@ -368,9 +368,14 @@ class Package(object): # stage used to build this package. self._stage = None - # patch up self.url based on the actual version + # If there's no default URL provided, set this package's url to None + if not hasattr(self, 'url'): + self.url = None + + # Set up a fetch strategy for this package. + self.fetcher = None if self.spec.concrete: - self.url = self.url_for_version(self.version) + self.fetcher = fs.from_args(self.versions[self.version], self) # Set a default list URL (place to find available versions) if not hasattr(self, 'list_url'): @@ -387,6 +392,61 @@ class Package(object): return self.spec.versions[0] + @memoized + def version_urls(self): + """Return a list of URLs for different versions of this + package, sorted by version. A version's URL only appears + in this list if it has an explicitly defined URL.""" + version_urls = {} + for v in sorted(self.versions): + args = self.versions[v] + if 'url' in args: + version_urls[v] = args['url'] + return version_urls + + + def nearest_url(self, version): + """Finds the URL for the next lowest version with a URL. + If there is no lower version with a URL, uses the + package url property. If that isn't there, uses a + *higher* URL, and if that isn't there raises an error. + """ + version_urls = self.version_urls() + url = self.url + + for v in version_urls: + if v > version and url: + break + if version_urls[v]: + url = version_urls[v] + return url + + + def has_url(self): + """Returns whether there is a URL available for this package. + If there isn't, it's probably fetched some other way (version + control, etc.)""" + return self.url or self.version_urls() + + + # TODO: move this out of here and into some URL extrapolation module. + def url_for_version(self, version): + """Returns a URL that you can download a new version of this package from.""" + if not isinstance(version, Version): + version = Version(version) + + if not self.has_url(): + raise NoURLError(self.__class__) + + # If we have a specific URL for this version, don't extrapolate. + version_urls = self.version_urls() + if version in version_urls: + return version_urls[version] + else: + return url.substitute_version(self.nearest_url(version), + self.url_version(version)) + + @property def stage(self): if not self.spec.concrete: @@ -397,11 +457,12 @@ class Package(object): raise PackageVersionError(self.version) # TODO: move this logic into a mirror module. + # TODO: get rid of dependence on extension. mirror_path = "%s/%s" % (self.name, "%s-%s.%s" % ( self.name, self.version, extension(self.url))) self._stage = Stage( - self.url, mirror_path=mirror_path, name=self.spec.short_spec) + self.fetcher, mirror_path=mirror_path, name=self.spec.short_spec) return self._stage @@ -523,36 +584,6 @@ class Package(object): return str(version) - def url_for_version(self, version): - """Returns a URL that you can download a new version of this package from.""" - if not isinstance(version, Version): - version = Version(version) - - def nearest_url(version): - """Finds the URL for the next lowest version with a URL. - If there is no lower version with a URL, uses the - package url property. If that isn't there, uses a - *higher* URL, and if that isn't there raises an error. - """ - url = getattr(self, 'url', None) - for v in sorted(self.versions): - if v > version and url: - break - if self.versions[v].url: - url = self.versions[v].url - return url - - if version in self.versions: - vdesc = self.versions[version] - if not vdesc.url: - base_url = nearest_url(version) - vdesc.url = url.substitute_version( - base_url, self.url_version(version)) - return vdesc.url - else: - return nearest_url(version) - - @property def default_url(self): if self.concrete: @@ -605,7 +636,7 @@ class Package(object): tty.msg("Created stage directory in %s." % self.stage.path) else: tty.msg("Already staged %s in %s." % (self.name, self.stage.path)) - self.stage.chdir_to_archive() + self.stage.chdir_to_source() def do_patch(self): @@ -628,7 +659,7 @@ class Package(object): tty.msg("Patching failed last time. Restaging.") self.stage.restage() - self.stage.chdir_to_archive() + self.stage.chdir_to_source() # If this file exists, then we already applied all the patches. if os.path.isfile(good_file): @@ -788,7 +819,7 @@ class Package(object): def do_clean(self): if self.stage.expanded_archive_path: - self.stage.chdir_to_archive() + self.stage.chdir_to_source() self.clean() @@ -944,3 +975,10 @@ class VersionFetchError(PackageError): super(VersionFetchError, self).__init__( "Cannot fetch version for package %s " % cls.__name__ + "because it does not define a default url.") + + +class NoURLError(PackageError): + """Raised when someone tries to build a URL for a package with no URLs.""" + def __init__(self, cls): + super(NoURLError, self).__init__( + "Package %s has no version with a URL." % cls.__name__) diff --git a/lib/spack/spack/patch.py b/lib/spack/spack/patch.py index 42d49b15e5..b1b6e07738 100644 --- a/lib/spack/spack/patch.py +++ b/lib/spack/spack/patch.py @@ -64,7 +64,7 @@ class Patch(object): """Fetch this patch, if necessary, and apply it to the source code in the supplied stage. """ - stage.chdir_to_archive() + stage.chdir_to_source() patch_stage = None try: diff --git a/lib/spack/spack/relations.py b/lib/spack/spack/relations.py index f7e1cfd925..b1f4348945 100644 --- a/lib/spack/spack/relations.py +++ b/lib/spack/spack/relations.py @@ -79,32 +79,28 @@ import spack import spack.spec import spack.error import spack.url - from spack.version import Version from spack.patch import Patch from spack.spec import Spec, parse_anonymous_spec -class VersionDescriptor(object): - """A VersionDescriptor contains information to describe a - particular version of a package. That currently includes a URL - for the version along with a checksum.""" - def __init__(self, checksum, url): - self.checksum = checksum - self.url = url - -def version(ver, checksum, **kwargs): - """Adds a version and metadata describing how to fetch it.""" +def version(ver, checksum=None, **kwargs): + """Adds a version and metadata describing how to fetch it. + Metadata is just stored as a dict in the package's versions + dictionary. Package must turn it into a valid fetch strategy + later. + """ pkg = caller_locals() - versions = pkg.setdefault('versions', {}) - patches = pkg.setdefault('patches', {}) - ver = Version(ver) - url = kwargs.get('url', None) + # special case checksum for backward compatibility + if checksum: + kwargs['md5'] = checksum - versions[ver] = VersionDescriptor(checksum, url) + # Store the kwargs for the package to use later when constructing + # a fetch strategy. + versions[Version(ver)] = kwargs def depends_on(*specs): diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 0fa315051f..5dc6eac488 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -32,11 +32,10 @@ from llnl.util.filesystem import * import spack import spack.config -from spack.fetch_strategy import strategy_for_url, URLFetchStrategy +import spack.fetch_strategy as fetch_strategy import spack.error - STAGE_PREFIX = 'spack-stage-' @@ -70,7 +69,7 @@ class Stage(object): similar, and are intended to persist for only one run of spack. """ - def __init__(self, url, **kwargs): + def __init__(self, url_or_fetch_strategy, **kwargs): """Create a stage object. Parameters: url_or_fetch_strategy @@ -83,10 +82,16 @@ class Stage(object): stage object later). If name is not provided, then this stage will be given a unique name automatically. """ - if isinstance(url, basestring): - self.fetcher = strategy_for_url(url) + if isinstance(url_or_fetch_strategy, basestring): + self.fetcher = fetch_strategy.from_url(url_or_fetch_strategy) self.fetcher.set_stage(self) + elif isinstance(url_or_fetch_strategy, fetch_strategy.FetchStrategy): + self.fetcher = url_or_fetch_strategy + + else: + raise ValueError("Can't construct Stage without url or fetch strategy") + self.name = kwargs.get('name') self.mirror_path = kwargs.get('mirror_path') @@ -237,10 +242,12 @@ class Stage(object): # TODO: move mirror logic out of here and clean it up! if self.mirror_path: urls = ["%s/%s" % (m, self.mirror_path) for m in _get_mirrors()] + digest = None - if isinstance(self.fetcher, URLFetchStrategy): + if isinstance(self.fetcher, fetch_strategy.URLFetchStrategy): digest = self.fetcher.digest - fetchers = [URLFetchStrategy(url, digest) for url in urls] + fetchers + fetchers = [fetch_strategy.URLFetchStrategy(url, digest) + for url in urls] + fetchers for f in fetchers: f.set_stage(self) @@ -267,7 +274,7 @@ class Stage(object): self.fetcher.expand() - def chdir_to_archive(self): + def chdir_to_source(self): """Changes directory to the expanded archive directory. Dies with an error if there was no expanded archive. """ diff --git a/lib/spack/spack/test/install.py b/lib/spack/spack/test/install.py index 8047ab92e3..896f19ac01 100644 --- a/lib/spack/spack/test/install.py +++ b/lib/spack/spack/test/install.py @@ -32,6 +32,7 @@ from llnl.util.filesystem import * import spack from spack.stage import Stage +from spack.fetch_strategy import URLFetchStrategy from spack.directory_layout import SpecHashDirectoryLayout from spack.util.executable import which from spack.test.mock_packages_test import * @@ -100,11 +101,16 @@ class InstallTest(MockPackagesTest): self.assertTrue(spec.concrete) # Get the package + print + print "======== GETTING PACKAGE ========" pkg = spack.db.get(spec) + print "======== GOT PACKAGE ========" + print + # Fake the URL for the package so it downloads from a file. archive_path = join_path(self.stage.path, archive_name) - pkg.url = 'file://' + archive_path + pkg.fetcher = URLFetchStrategy('file://' + archive_path) try: pkg.do_install() diff --git a/lib/spack/spack/test/package_sanity.py b/lib/spack/spack/test/package_sanity.py index e3de695070..6222e7b5f8 100644 --- a/lib/spack/spack/test/package_sanity.py +++ b/lib/spack/spack/test/package_sanity.py @@ -56,8 +56,8 @@ class PackageSanityTest(unittest.TestCase): def test_url_versions(self): """Check URLs for regular packages, if they are explicitly defined.""" for pkg in spack.db.all_packages(): - for v, vdesc in pkg.versions.items(): - if vdesc.url: + for v, vattrs in pkg.versions.items(): + if 'url' in vattrs: # If there is a url for the version check it. v_url = pkg.url_for_version(v) - self.assertEqual(vdesc.url, v_url) + self.assertEqual(vattrs['url'], v_url) diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py index 8cb7ac772e..c5a7013675 100644 --- a/lib/spack/spack/test/stage.py +++ b/lib/spack/spack/test/stage.py @@ -170,7 +170,7 @@ class StageTest(unittest.TestCase): self.assertEqual(os.path.realpath(stage_path), os.getcwd()) - def check_chdir_to_archive(self, stage, stage_name): + def check_chdir_to_source(self, stage, stage_name): stage_path = self.get_stage_path(stage, stage_name) self.assertEqual( join_path(os.path.realpath(stage_path), archive_dir), @@ -271,9 +271,9 @@ class StageTest(unittest.TestCase): self.check_fetch(stage, stage_name) stage.expand_archive() - stage.chdir_to_archive() + stage.chdir_to_source() self.check_expand_archive(stage, stage_name) - self.check_chdir_to_archive(stage, stage_name) + self.check_chdir_to_source(stage, stage_name) stage.destroy() self.check_destroy(stage, stage_name) @@ -284,9 +284,9 @@ class StageTest(unittest.TestCase): stage.fetch() stage.expand_archive() - stage.chdir_to_archive() + stage.chdir_to_source() self.check_expand_archive(stage, stage_name) - self.check_chdir_to_archive(stage, stage_name) + self.check_chdir_to_source(stage, stage_name) # Try to make a file in the old archive dir with closing(open('foobar', 'w')) as file: @@ -299,8 +299,8 @@ class StageTest(unittest.TestCase): self.check_chdir(stage, stage_name) self.check_fetch(stage, stage_name) - stage.chdir_to_archive() - self.check_chdir_to_archive(stage, stage_name) + stage.chdir_to_source() + self.check_chdir_to_source(stage, stage_name) self.assertFalse('foobar' in os.listdir(stage.source_path)) stage.destroy() -- cgit v1.2.3-70-g09d2 From c74cd63389eff149d8c0db4f7d68d173a72b48b3 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 16 Sep 2014 16:56:16 -0700 Subject: Callpath build works when a tag is fetched from git. --- LICENSE | 48 ++++---- lib/spack/spack/fetch_strategy.py | 208 ++++++++++++++++++++++++--------- lib/spack/spack/package.py | 27 +++-- lib/spack/spack/stage.py | 6 +- var/spack/packages/callpath/package.py | 2 + 5 files changed, 198 insertions(+), 93 deletions(-) diff --git a/LICENSE b/LICENSE index 72a3a77890..6ad4af5861 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013, Lawrence Livermore National Security, LLC. +Copyright (c) 2013-2014, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory. This file is part of Spack. @@ -55,22 +55,22 @@ Modification 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called “this License”). Each -licensee is addressed as “you”. +this Lesser General Public License (also called "this License"). Each +licensee is addressed as "you". -A “library” means a collection of software functions and/or data +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. -The “Library”, below, refers to any such software library or work -which has been distributed under these terms. A “work based on the -Library” means either the Library or any derivative work under +The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term “modification”.) +included without limitation in the term "modification".) -“Source code” for a work means the preferred form of the work for +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control @@ -83,7 +83,7 @@ covered only if its contents constitute a work based on the Library it). Whether that is true depends on what the Library does and what the program that uses the Library does. -1. You may copy and distribute verbatim copies of the Library’s +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact @@ -170,17 +170,17 @@ source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or -linked with it, is called a “work that uses the Library”. Such a work, +linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. -However, linking a “work that uses the Library” with the Library +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a “work that uses the -library”. The executable is therefore covered by this License. Section +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. -When a “work that uses the Library” uses material from a header file +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be @@ -200,10 +200,10 @@ distribute the object code for the work under the terms of Section whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link -a “work that uses the Library” with the Library to produce a work +a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of -the work for the customer’s own use and reverse engineering for +the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the @@ -218,7 +218,7 @@ a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable liked with the Library, with the -complete machine-readable “work that uses the Library”, as object code +complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of @@ -227,7 +227,7 @@ recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy -of the library already present on the user’s computer system, rather +of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface- compatible @@ -245,8 +245,8 @@ specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. -For an executable, the required form of the “work that uses the -Library” must include any data and utility programs needed for +For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major @@ -296,7 +296,7 @@ the Library or works based on it. Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further -restrictions on the recipients’ exercise of the rights granted +restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. @@ -347,7 +347,7 @@ differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and -“any later version”, you have the option of following the terms and +"any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by @@ -367,7 +367,7 @@ NO WARRANTY 1 BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER -PARTIES PROVIDE THE LIBRARY “AS IS” WITHOUT WARRANTY OF ANY KIND, +PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index b0845700b6..cba0ace6d3 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -47,12 +47,27 @@ import llnl.util.tty as tty import spack import spack.error import spack.util.crypto as crypto +from spack.util.executable import * +from spack.util.string import * from spack.version import Version, ver from spack.util.compression import decompressor_for +"""List of all fetch strategies, created by FetchStrategy metaclass.""" +all_strategies = [] class FetchStrategy(object): + """Superclass of all fetch strategies.""" + enabled = False # Non-abstract subclasses should be enabled. + required_attributes = None # Attributes required in version() args. + + class __metaclass__(type): + """This metaclass registers all fetch strategies in a list.""" + def __init__(cls, name, bases, dict): + type.__init__(cls, name, bases, dict) + if cls.enabled: all_strategies.append(cls) + + def __init__(self): # The stage is initialized late, so that fetch strategies can be constructed # at package construction time. This is where things will be fetched. @@ -76,12 +91,16 @@ class FetchStrategy(object): # This method is used to match fetch strategies to version() # arguments in packages. @classmethod - def match(kwargs): - return any(k in kwargs for k in self.attributes) + def matches(cls, args): + return any(k in args for k in cls.required_attributes) class URLFetchStrategy(FetchStrategy): - attributes = ('url', 'md5') + """FetchStrategy that pulls source code from a URL for an archive, + checks the archive against a checksum,and decompresses the archive. + """ + enabled = True + required_attributes = ['url'] def __init__(self, url=None, digest=None, **kwargs): super(URLFetchStrategy, self).__init__() @@ -172,11 +191,11 @@ class URLFetchStrategy(FetchStrategy): assert(self.stage) if not self.digest: raise NoDigestError("Attempt to check URLFetchStrategy with no digest.") - checker = crypto.Checker(digest) + checker = crypto.Checker(self.digest) if not checker.check(self.archive_file): raise ChecksumError( "%s checksum failed for %s." % (checker.hash_name, self.archive_file), - "Expected %s but got %s." % (digest, checker.sum)) + "Expected %s but got %s." % (self.digest, checker.sum)) def reset(self): @@ -191,46 +210,73 @@ class URLFetchStrategy(FetchStrategy): def __str__(self): - if self.url: - return self.url - else: - return "URLFetchStrategy " + url = self.url if self.url else "no url" + return "URLFetchStrategy<%s>" % url class VCSFetchStrategy(FetchStrategy): - def __init__(self, name): + def __init__(self, name, *rev_types, **kwargs): super(VCSFetchStrategy, self).__init__() self.name = name + # Set a URL based on the type of fetch strategy. + self.url = kwargs.get(name, None) + if not self.url: raise ValueError( + "%s requires %s argument." % (self.__class__, name)) + + # Ensure that there's only one of the rev_types + if sum((k in kwargs for k in rev_types)) > 1: + raise FetchStrategyError( + "Supply only one of %s to fetch with %s." % ( + comma_or(rev_types), name)) + + # Set attributes for each rev type. + for rt in rev_types: + setattr(self, rt, getattr(kwargs, rt, None)) + def check(self): assert(self.stage) - tty.msg("No check needed when fetching with %s." % self.name) + tty.msg("No checksum needed when fetching with %s." % self.name) + def expand(self): assert(self.stage) tty.debug("Source fetched with %s is already expanded." % self.name) + def __str__(self): + return "%s<%s>" % (self.__class__, self.url) + + class GitFetchStrategy(VCSFetchStrategy): - attributes = ('git', 'ref', 'tag', 'branch') + """Fetch strategy that gets source code from a git repository. + Use like this in a package: - def __init__(self, **kwargs): - super(GitFetchStrategy, self).__init__("git") - self.url = kwargs.get('git', None) - if not self.url: - raise ValueError("GitFetchStrategy requires git argument.") + version('name', git='https://github.com/project/repo.git') - if sum((k in kwargs for k in ('ref', 'tag', 'branch'))) > 1: - raise FetchStrategyError( - "Git requires exactly one ref, branch, or tag.") + Optionally, you can provide a branch, or commit to check out, e.g.: + + version('1.1', git='https://github.com/project/repo.git', tag='v1.1') + + You can use these three optional attributes in addition to ``git``: + + * ``branch``: Particular branch to build from (default is master) + * ``tag``: Particular tag to check out + * ``commit``: Particular commit hash in the repo + """ + enabled = True + required_attributes = ('git',) + def __init__(self, **kwargs): + super(GitFetchStrategy, self).__init__( + 'git', 'tag', 'branch', 'commit', **kwargs) self._git = None - self.ref = kwargs.get('ref', None) - self.branch = kwargs.get('branch', None) + + # For git fetch branches and tags the same way. if not self.branch: - self.branch = kwargs.get('tag', None) + self.branch = self.tag @property @@ -252,21 +298,20 @@ class GitFetchStrategy(VCSFetchStrategy): self.stage.chdir() if self.stage.source_path: - tty.msg("Already fetched %s." % self.source_path) + tty.msg("Already fetched %s." % self.stage.source_path) return tty.msg("Trying to clone git repository: %s" % self.url) - - if self.ref: + if self.commit: # Need to do a regular clone and check out everything if - # they asked for a particular ref. - git('clone', self.url) - self.chdir_to_source() - git('checkout', self.ref) + # they asked for a particular commit. + self.git('clone', self.url) + self.stage.chdir_to_source() + self.git('checkout', self.commit) else: - # Can be more efficient if not checking out a specific ref. + # Can be more efficient if not checking out a specific commit. args = ['clone'] # If we want a particular branch ask for it. @@ -279,26 +324,77 @@ class GitFetchStrategy(VCSFetchStrategy): args.append('--single-branch') args.append(self.url) - git(*args) - self.chdir_to_source() + self.git(*args) + self.stage.chdir_to_source() def reset(self): assert(self.stage) - git = which('git', required=True) + self.stage.chdir_to_source() + self.git('checkout', '.') + self.git('clean', '-f') + +class SvnFetchStrategy(VCSFetchStrategy): + """Fetch strategy that gets source code from a subversion repository. + Use like this in a package: + + version('name', svn='http://www.example.com/svn/trunk') + + Optionally, you can provide a revision for the URL: + + version('name', svn='http://www.example.com/svn/trunk', + revision='1641') + """ + enabled = True + required_attributes = ['svn'] + + def __init__(self, **kwargs): + super(SvnFetchStrategy, self).__init__( + 'svn', 'revision', **kwargs) + self._svn = None + + + @property + def svn(self): + if not self._svn: + self._svn = which('svn', required=True) + return self._svn + + + def fetch(self): + assert(self.stage) + self.stage.chdir() + + if self.stage.source_path: + tty.msg("Already fetched %s." % self.stage.source_path) + return + + tty.msg("Trying to check out svn repository: %s" % self.url) + + args = ['checkout', '--force'] + if self.revision: + args += ['-r', self.revision] + + self.svn(*args) self.stage.chdir_to_source() - git('checkout', '.') - git('clean', '-f') - def __str__(self): - return self.url + def _remove_untracked_files(self): + """Removes untracked files in an svn repository.""" + status = self.svn('status', '--no-ignore', check_output=True) + for line in status.split('\n'): + if not re.match('^[I?]'): + continue + path = line[8:].strip() + shutil.rmtree(path, ignore_errors=True) -class SvnFetchStrategy(FetchStrategy): - attributes = ('svn', 'rev', 'revision') - pass + def reset(self): + assert(self.stage) + self.stage.chdir_to_source() + self._remove_untracked_files() + self.svn('revert', '.', '-R') def from_url(url): @@ -312,25 +408,31 @@ def from_url(url): def args_are_for(args, fetcher): - return any(arg in args for arg in fetcher.attributes) + fetcher.matches(args) def from_args(args, pkg): """Determine a fetch strategy based on the arguments supplied to version() in the package description.""" - fetchers = (URLFetchStrategy, GitFetchStrategy) - for fetcher in fetchers: - if args_are_for(args, fetcher): - attrs = {} - for attr in fetcher.attributes: - default = getattr(pkg, attr, None) - if default: - attrs[attr] = default - - attrs.update(args) + + # Test all strategies against per-version arguments. + for fetcher in all_strategies: + if fetcher.matches(args): + return fetcher(**args) + + # If nothing matched for a *specific* version, test all strategies + # against + for fetcher in all_strategies: + attrs = dict((attr, getattr(pkg, attr, None)) + for attr in fetcher.required_attributes) + attrs.update(args) + if fetcher.matches(attrs): return fetcher(**attrs) - return None + raise InvalidArgsError( + "Could not construct fetch strategy for package %s", + pkg.spec.format("%_%@")) + class FetchStrategyError(spack.error.SpackError): def __init__(self, msg, long_msg): diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 553e0118e3..e9fca9ec49 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -453,19 +453,18 @@ class Package(object): raise ValueError("Can only get a stage for a concrete package.") if self._stage is None: - if not self.url: - raise PackageVersionError(self.version) - - # TODO: move this logic into a mirror module. - # TODO: get rid of dependence on extension. - mirror_path = "%s/%s" % (self.name, "%s-%s.%s" % ( - self.name, self.version, extension(self.url))) - self._stage = Stage( - self.fetcher, mirror_path=mirror_path, name=self.spec.short_spec) + self.fetcher, mirror_path=self.mirror_path(), name=self.spec.short_spec) return self._stage + def mirror_path(self): + """Get path to this package's archive in a mirror.""" + filename = "%s-%s." % (self.name, self.version) + filename += extension(self.url) if self.has_url() else "tar.gz" + return "%s/%s" % (self.name, filename) + + def preorder_traversal(self, visited=None, **kwargs): """This does a preorder traversal of the package's dependence DAG.""" virtual = kwargs.get("virtual", False) @@ -617,9 +616,7 @@ class Package(object): self.stage.fetch() if spack.do_checksum and self.version in self.versions: - digest = self.versions[self.version].checksum - self.stage.check(digest) - tty.msg("Checksum passed for %s@%s" % (self.name, self.version)) + self.stage.check() def do_stage(self): @@ -645,8 +642,14 @@ class Package(object): if not self.spec.concrete: raise ValueError("Can only patch concrete packages.") + # Kick off the stage first. self.do_stage() + # If there are no patches, note it. + if not self.patches: + tty.msg("No patches needed for %s." % self.name) + return + # Construct paths to special files in the archive dir used to # keep track of whether patches were successfully applied. archive_dir = self.stage.source_path diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 5dc6eac488..ed92fb17f7 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -84,14 +84,12 @@ class Stage(object): """ if isinstance(url_or_fetch_strategy, basestring): self.fetcher = fetch_strategy.from_url(url_or_fetch_strategy) - self.fetcher.set_stage(self) - elif isinstance(url_or_fetch_strategy, fetch_strategy.FetchStrategy): self.fetcher = url_or_fetch_strategy - else: raise ValueError("Can't construct Stage without url or fetch strategy") + self.fetcher.set_stage(self) self.name = kwargs.get('name') self.mirror_path = kwargs.get('mirror_path') @@ -260,7 +258,7 @@ class Stage(object): continue - def check(self, digest): + def check(self): """Check the downloaded archive against a checksum digest. No-op if this stage checks code out of a repository.""" self.fetcher.check() diff --git a/var/spack/packages/callpath/package.py b/var/spack/packages/callpath/package.py index 84170d9c9e..6102458291 100644 --- a/var/spack/packages/callpath/package.py +++ b/var/spack/packages/callpath/package.py @@ -33,6 +33,8 @@ class Callpath(Package): version('1.0.1', '0047983d2a52c5c335f8ba7f5bab2325') + depends_on("libelf") + depends_on("libdwarf") depends_on("dyninst") depends_on("adept-utils") depends_on("mpi") -- cgit v1.2.3-70-g09d2 From da84764e97ead919bee7fb02d469c25a6b03ab63 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 1 Oct 2014 23:32:36 -0700 Subject: Add test case for git fetching. --- lib/spack/spack/fetch_strategy.py | 15 ++- lib/spack/spack/package.py | 21 +++- lib/spack/spack/packages.py | 21 +++- lib/spack/spack/test/__init__.py | 3 +- lib/spack/spack/test/git_fetch.py | 175 ++++++++++++++++++++++++++++ lib/spack/spack/test/install.py | 5 - var/spack/mock_packages/git-test/package.py | 10 ++ 7 files changed, 232 insertions(+), 18 deletions(-) create mode 100644 lib/spack/spack/test/git_fetch.py create mode 100644 var/spack/mock_packages/git-test/package.py diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index cba0ace6d3..328f45c3d6 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -225,15 +225,14 @@ class VCSFetchStrategy(FetchStrategy): "%s requires %s argument." % (self.__class__, name)) # Ensure that there's only one of the rev_types - if sum((k in kwargs for k in rev_types)) > 1: + if sum(k in kwargs for k in rev_types) > 1: raise FetchStrategyError( "Supply only one of %s to fetch with %s." % ( comma_or(rev_types), name)) # Set attributes for each rev type. for rt in rev_types: - setattr(self, rt, getattr(kwargs, rt, None)) - + setattr(self, rt, kwargs.get(rt, None)) def check(self): assert(self.stage) @@ -301,7 +300,14 @@ class GitFetchStrategy(VCSFetchStrategy): tty.msg("Already fetched %s." % self.stage.source_path) return - tty.msg("Trying to clone git repository: %s" % self.url) + args = [] + if self.commit: + args.append('at commit %s' % self.commit) + elif self.tag: + args.append('at tag %s' % self.branch) + elif self.branch: + args.append('on branch %s' % self.branch) + tty.msg("Trying to clone git repository:", self.url, *args) if self.commit: # Need to do a regular clone and check out everything if @@ -460,4 +466,3 @@ class NoDigestError(FetchStrategyError): class InvalidArgsError(FetchStrategyError): def __init__(self, msg, long_msg): super(InvalidArgsError, self).__init__(msg, long_msg) - diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index e9fca9ec49..c6e1fd90ef 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -372,10 +372,8 @@ class Package(object): if not hasattr(self, 'url'): self.url = None - # Set up a fetch strategy for this package. - self.fetcher = None - if self.spec.concrete: - self.fetcher = fs.from_args(self.versions[self.version], self) + # Init fetch strategy to None + self._fetcher = None # Set a default list URL (place to find available versions) if not hasattr(self, 'list_url'): @@ -458,6 +456,21 @@ class Package(object): return self._stage + @property + def fetcher(self): + if not self.spec.concrete: + raise ValueError("Can only get a fetcher for a concrete package.") + + if not self._fetcher: + self._fetcher = fs.from_args(self.versions[self.version], self) + return self._fetcher + + + @fetcher.setter + def fetcher(self, f): + self._fetcher = f + + def mirror_path(self): """Get path to this package's archive in a mirror.""" filename = "%s-%s." % (self.name, self.version) diff --git a/lib/spack/spack/packages.py b/lib/spack/spack/packages.py index 72f9403a64..047d82a93a 100644 --- a/lib/spack/spack/packages.py +++ b/lib/spack/spack/packages.py @@ -47,10 +47,10 @@ _package_file_name = 'package.py' def _autospec(function): """Decorator that automatically converts the argument of a single-arg function to a Spec.""" - def converter(self, spec_like): + def converter(self, spec_like, **kwargs): if not isinstance(spec_like, spack.spec.Spec): spec_like = spack.spec.Spec(spec_like) - return function(self, spec_like) + return function(self, spec_like, **kwargs) return converter @@ -63,10 +63,14 @@ class PackageDB(object): @_autospec - def get(self, spec): + def get(self, spec, **kwargs): if spec.virtual: raise UnknownPackageError(spec.name) + if kwargs.get('new', False): + if spec in self.instances: + del self.instances[spec] + if not spec in self.instances: package_class = self.get_class_for_package_name(spec.name) try: @@ -77,6 +81,17 @@ class PackageDB(object): return self.instances[spec] + @_autospec + def delete(self, spec): + """Force a package to be recreated.""" + del self.instances[spec] + + + def purge(self): + """Clear entire package instance cache.""" + self.instances.clear() + + @_autospec def get_installed(self, spec): """Get all the installed specs that satisfy the provided spec constraint.""" diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index 8ddc7f227d..b00f9a31ce 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -47,7 +47,8 @@ test_names = ['versions', 'package_sanity', 'config', 'directory_layout', - 'python_version'] + 'python_version', + 'git_fetch'] def list_tests(): diff --git a/lib/spack/spack/test/git_fetch.py b/lib/spack/spack/test/git_fetch.py new file mode 100644 index 0000000000..c7c11621f9 --- /dev/null +++ b/lib/spack/spack/test/git_fetch.py @@ -0,0 +1,175 @@ +############################################################################## +# 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 +############################################################################## +import os +import unittest +import shutil +import tempfile +from contextlib import closing + +from llnl.util.filesystem import * + +import spack +from spack.version import ver +from spack.stage import Stage +from spack.util.executable import which +from spack.test.mock_packages_test import * + +test_repo_path = 'test-repo' +test_file_name = 'test-file.txt' + +test_branch = 'test-branch' +test_branch_file_name = 'branch-test-file' + +test_tag_branch = 'test-tag-branch' +test_tag = 'test-tag' +test_tag_file_name = 'tag-test-file' + +untracked = 'foobarbaz' + +git = which('git', required=True) + +def rev_hash(rev): + return git('rev-parse', rev, return_output=True).strip() + + +class GitFetchTest(MockPackagesTest): + """Tests fetching from a dummy git repository.""" + + def setUp(self): + """Create a git repository with master and two other branches, + and one tag, so that we can experiment on it.""" + super(GitFetchTest, self).setUp() + self.stage = Stage('fetch-test') + + self.repo_path = join_path(self.stage.path, test_repo_path) + mkdirp(self.repo_path) + + self.test_file = join_path(self.repo_path, test_file_name) + touch(self.test_file) + + with working_dir(self.repo_path): + git('init') + git('add', self.test_file) + git('commit', '-m', 'testing') + + git('branch', test_branch) + git('branch', test_tag_branch) + + git('checkout', test_branch) + touch(test_branch_file_name) + git('add', test_branch_file_name) + git('commit', '-m' 'branch test') + + git('checkout', test_tag_branch) + touch(test_tag_file_name) + git('add', test_tag_file_name) + git('commit', '-m' 'tag test') + git('tag', test_tag) + + git('checkout', 'master') + + self.commit = rev_hash(test_tag) + + spec = Spec('git-test') + spec.concretize() + self.pkg = spack.db.get(spec, new=True) + + + def tearDown(self): + """Destroy the stage space used by this test.""" + super(GitFetchTest, self).tearDown() + + if self.stage is not None: + self.stage.destroy() + + self.pkg.do_clean_dist() + + + def assert_rev(self, rev): + """Check that the current git revision is equal to the supplied rev.""" + self.assertEqual(rev_hash('HEAD'), rev_hash(rev)) + + + def try_fetch(self, rev, test_file, args): + """Tries to: + 1. Fetch the repo using a fetch strategy constructed with + supplied args. + 2. Check if the test_file is in the checked out repository. + 3. Assert that the repository is at the revision supplied. + 4. Add and remove some files, then reset the repo, and + ensure it's all there again. + """ + self.pkg.versions[ver('git')] = args + + self.pkg.do_stage() + self.assert_rev(rev) + + file_path = join_path(self.pkg.stage.source_path, test_file) + self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) + self.assertTrue(os.path.isfile(file_path)) + + os.unlink(file_path) + self.assertFalse(os.path.isfile(file_path)) + + touch(untracked) + self.assertTrue(os.path.isfile(untracked)) + self.pkg.do_clean_work() + self.assertFalse(os.path.isfile(untracked)) + + self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) + self.assertTrue(os.path.isfile(file_path)) + + self.assert_rev(rev) + + + def test_fetch_master(self): + """Test a default git checkout with no commit or tag specified.""" + self.try_fetch('master', test_file_name, { + 'git' : self.repo_path + }) + + + def test_fetch_branch(self): + """Test fetching a branch.""" + self.try_fetch(test_branch, test_branch_file_name, { + 'git' : self.repo_path, + 'branch' : test_branch + }) + + + def test_fetch_tag(self): + """Test fetching a tag.""" + self.try_fetch(test_tag, test_tag_file_name, { + 'git' : self.repo_path, + 'tag' : test_tag + }) + + + def test_fetch_commit(self): + """Test fetching a particular commit.""" + self.try_fetch(self.commit, test_tag_file_name, { + 'git' : self.repo_path, + 'commit' : self.commit + }) diff --git a/lib/spack/spack/test/install.py b/lib/spack/spack/test/install.py index 896f19ac01..0d53bb45c7 100644 --- a/lib/spack/spack/test/install.py +++ b/lib/spack/spack/test/install.py @@ -101,13 +101,8 @@ class InstallTest(MockPackagesTest): self.assertTrue(spec.concrete) # Get the package - print - print "======== GETTING PACKAGE ========" pkg = spack.db.get(spec) - print "======== GOT PACKAGE ========" - print - # Fake the URL for the package so it downloads from a file. archive_path = join_path(self.stage.path, archive_name) pkg.fetcher = URLFetchStrategy('file://' + archive_path) diff --git a/var/spack/mock_packages/git-test/package.py b/var/spack/mock_packages/git-test/package.py new file mode 100644 index 0000000000..689185463c --- /dev/null +++ b/var/spack/mock_packages/git-test/package.py @@ -0,0 +1,10 @@ +from spack import * + +class GitTest(Package): + """Mock package that uses git for fetching.""" + homepage = "http://www.git-fetch-example.com" + + version('git', git='to-be-filled-in-by-test') + + def install(self, spec, prefix): + pass -- cgit v1.2.3-70-g09d2 From faae720c3693733ac272c191b7c3ab4908b02b6b Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 2 Oct 2014 01:14:00 -0700 Subject: add tests for svn fetching. --- lib/spack/spack/fetch_strategy.py | 26 ++++- lib/spack/spack/package.py | 2 +- lib/spack/spack/stage.py | 2 +- lib/spack/spack/test/__init__.py | 3 +- lib/spack/spack/test/svn_fetch.py | 150 ++++++++++++++++++++++++++++ var/spack/mock_packages/svn-test/package.py | 10 ++ 6 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 lib/spack/spack/test/svn_fetch.py create mode 100644 var/spack/mock_packages/svn-test/package.py diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 328f45c3d6..411c8cc276 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -209,11 +209,18 @@ class URLFetchStrategy(FetchStrategy): self.expand() - def __str__(self): + def __repr__(self): url = self.url if self.url else "no url" return "URLFetchStrategy<%s>" % url + def __str__(self): + if self.url: + return self.url + else: + return "URLFetchStrategy" + + class VCSFetchStrategy(FetchStrategy): def __init__(self, name, *rev_types, **kwargs): super(VCSFetchStrategy, self).__init__() @@ -245,6 +252,10 @@ class VCSFetchStrategy(FetchStrategy): def __str__(self): + return self.url + + + def __repr__(self): return "%s<%s>" % (self.__class__, self.url) @@ -359,6 +370,8 @@ class SvnFetchStrategy(VCSFetchStrategy): super(SvnFetchStrategy, self).__init__( 'svn', 'revision', **kwargs) self._svn = None + if self.revision is not None: + self.revision = str(self.revision) @property @@ -381,6 +394,7 @@ class SvnFetchStrategy(VCSFetchStrategy): args = ['checkout', '--force'] if self.revision: args += ['-r', self.revision] + args.append(self.url) self.svn(*args) self.stage.chdir_to_source() @@ -388,12 +402,16 @@ class SvnFetchStrategy(VCSFetchStrategy): def _remove_untracked_files(self): """Removes untracked files in an svn repository.""" - status = self.svn('status', '--no-ignore', check_output=True) + status = self.svn('status', '--no-ignore', return_output=True) + self.svn('status', '--no-ignore') for line in status.split('\n'): - if not re.match('^[I?]'): + if not re.match('^[I?]', line): continue path = line[8:].strip() - shutil.rmtree(path, ignore_errors=True) + if os.path.isfile(path): + os.unlink(path) + elif os.path.isdir(path): + shutil.rmtree(path, ignore_errors=True) def reset(self): diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index c6e1fd90ef..59bfafa241 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -643,7 +643,7 @@ class Package(object): archive_dir = self.stage.source_path if not archive_dir: self.stage.expand_archive() - tty.msg("Created stage directory in %s." % self.stage.path) + tty.msg("Created stage in %s." % self.stage.path) else: tty.msg("Already staged %s in %s." % (self.name, self.stage.path)) self.stage.chdir_to_source() diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index ed92fb17f7..0d684df92d 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -254,7 +254,7 @@ class Stage(object): fetcher.fetch() break except spack.error.SpackError, e: - tty.msg("Download from %s failed." % fetcher) + tty.msg("Fetching %s failed." % fetcher) continue diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index b00f9a31ce..61464293d2 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -48,7 +48,8 @@ test_names = ['versions', 'config', 'directory_layout', 'python_version', - 'git_fetch'] + 'git_fetch', + 'svn_fetch'] def list_tests(): diff --git a/lib/spack/spack/test/svn_fetch.py b/lib/spack/spack/test/svn_fetch.py new file mode 100644 index 0000000000..e253f21921 --- /dev/null +++ b/lib/spack/spack/test/svn_fetch.py @@ -0,0 +1,150 @@ +############################################################################## +# 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 +############################################################################## +import os +import re +import unittest +import shutil +import tempfile +from contextlib import closing + +from llnl.util.filesystem import * + +import spack +from spack.version import ver +from spack.stage import Stage +from spack.util.executable import which +from spack.test.mock_packages_test import * + +test_repo_path = 'test-repo' + +test_import_path = 'test-import' +test_file_name = 'test-file.txt' +test_rev_file_name = 'test-rev-file' + +untracked = 'foobarbaz' + +svn = which('svn', required=True) +svnadmin = which('svnadmin', required=True) + + +class SvnFetchTest(MockPackagesTest): + """Tests fetching from a dummy git repository.""" + + def setUp(self): + """Create an svn repository with two revisions.""" + super(SvnFetchTest, self).setUp() + self.stage = Stage('fetch-test') + self.stage.chdir() + + repo_path = join_path(self.stage.path, test_repo_path) + svnadmin('create', repo_path) + self.repo_url = 'file://' + repo_path + + self.import_path = join_path(self.stage.path, test_import_path) + mkdirp(self.import_path) + with working_dir(self.import_path): + touch(test_file_name) + + svn('import', self.import_path, self.repo_url, '-m', 'Initial import') + + shutil.rmtree(self.import_path) + svn('checkout', self.repo_url, self.import_path) + with working_dir(self.import_path): + touch(test_rev_file_name) + svn('add', test_rev_file_name) + svn('ci', '-m', 'second revision') + + spec = Spec('svn-test') + spec.concretize() + self.pkg = spack.db.get(spec, new=True) + + + def tearDown(self): + """Destroy the stage space used by this test.""" + super(SvnFetchTest, self).tearDown() + + if self.stage is not None: + self.stage.destroy() + + self.pkg.do_clean_dist() + + + def assert_rev(self, rev): + """Check that the current revision is equal to the supplied rev.""" + def get_rev(): + output = svn('info', return_output=True) + self.assertTrue("Revision" in output) + for line in output.split('\n'): + match = re.match(r'Revision: (\d+)', line) + if match: + return int(match.group(1)) + self.assertEqual(get_rev(), rev) + + + def try_fetch(self, rev, test_file, args): + """Tries to: + 1. Fetch the repo using a fetch strategy constructed with + supplied args. + 2. Check if the test_file is in the checked out repository. + 3. Assert that the repository is at the revision supplied. + 4. Add and remove some files, then reset the repo, and + ensure it's all there again. + """ + self.pkg.versions[ver('svn')] = args + + self.pkg.do_stage() + self.assert_rev(rev) + + file_path = join_path(self.pkg.stage.source_path, test_file) + self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) + self.assertTrue(os.path.isfile(file_path)) + + os.unlink(file_path) + self.assertFalse(os.path.isfile(file_path)) + + touch(untracked) + self.assertTrue(os.path.isfile(untracked)) + self.pkg.do_clean_work() + self.assertFalse(os.path.isfile(untracked)) + + self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) + self.assertTrue(os.path.isfile(file_path)) + + self.assert_rev(rev) + + + def test_fetch_default(self): + """Test a default checkout and make sure it's on rev 1""" + self.try_fetch(2, test_rev_file_name, { + 'svn' : self.repo_url + }) + + + def test_fetch_r1(self): + """Test fetching an older revision (0).""" + self.try_fetch(1, test_file_name, { + 'svn' : self.repo_url, + 'revision' : 1 + }) diff --git a/var/spack/mock_packages/svn-test/package.py b/var/spack/mock_packages/svn-test/package.py new file mode 100644 index 0000000000..ba4d5522b4 --- /dev/null +++ b/var/spack/mock_packages/svn-test/package.py @@ -0,0 +1,10 @@ +from spack import * + +class SvnTest(Package): + """Mock package that uses svn for fetching.""" + url = "http://www.example.com/svn-test-1.0.tar.gz" + + version('svn', 'to-be-filled-in-by-test') + + def install(self, spec, prefix): + pass -- cgit v1.2.3-70-g09d2 From 727d313c3052d117ec3268ccc8d3f34f1c443b1c Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 00:03:23 -0700 Subject: Fix location.py to use source_path --- lib/spack/spack/cmd/location.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/location.py b/lib/spack/spack/cmd/location.py index 074d984ee6..e92737ab4e 100644 --- a/lib/spack/spack/cmd/location.py +++ b/lib/spack/spack/cmd/location.py @@ -52,7 +52,7 @@ def setup_parser(subparser): '-s', '--stage-dir', action='store_true', help="Stage directory for a spec.") directories.add_argument( '-b', '--build-dir', action='store_true', - help="Expanded archive directory for a spec (requires it to be staged first).") + help="Checked out or expanded source directory for a spec (requires it to be staged first).") subparser.add_argument( 'spec', nargs=argparse.REMAINDER, help="spec of package to fetch directory for.") @@ -86,8 +86,8 @@ def location(parser, args): print pkg.stage.path else: # args.build_dir is the default. - if not os.listdir(pkg.stage.path): + if not pkg.stage.source_path: tty.die("Build directory does not exist yet. Run this to create it:", "spack stage " + " ".join(args.spec)) - print pkg.stage.expanded_archive_path + print pkg.stage.source_path -- cgit v1.2.3-70-g09d2 From 0fa1c5b0a54c2b64dfc431449b1ba4491b9981c0 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 00:04:50 -0700 Subject: Add Mercurial fetch strategy and lwm2. --- lib/spack/spack/fetch_strategy.py | 70 ++++++++++++++++++++++++++++++++++++++ var/spack/packages/lwm2/package.py | 18 ++++++++++ 2 files changed, 88 insertions(+) create mode 100644 var/spack/packages/lwm2/package.py diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 411c8cc276..ad9af43c96 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -421,6 +421,76 @@ class SvnFetchStrategy(VCSFetchStrategy): self.svn('revert', '.', '-R') +class HgFetchStrategy(VCSFetchStrategy): + """Fetch strategy that gets source code from a Mercurial repository. + Use like this in a package: + + version('name', hg='https://jay.grs.rwth-aachen.de/hg/lwm2') + + Optionally, you can provide a branch, or revision to check out, e.g.: + + version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus') + + You can use these three optional attributes in addition to ``hg``: + + * ``branch``: Particular branch to build from (default is 'default') + * ``tag``: Particular tag to check out + * ``revision``: Particular revision hash in the repo + """ + enabled = True + required_attributes = ['hg'] + + def __init__(self, **kwargs): + super(HgFetchStrategy, self).__init__( + 'hg', 'tag', 'branch', 'revision', **kwargs) + self._hg = None + + # For git fetch branches and tags the same way. + if not self.revision: + self.revision = self.branch + if not self.revision: + self.revision = self.tag + + + @property + def hg(self): + if not self._hg: + self._hg = which('hg', required=True) + return self._hg + + + def fetch(self): + assert(self.stage) + self.stage.chdir() + + if self.stage.source_path: + tty.msg("Already fetched %s." % self.stage.source_path) + return + + tty.msg("Trying to clone Mercurial repository: %s" % self.url) + + args = ['clone', self.url] + if self.revision: + args += ['-r', self.revision] + + self.hg(*args) + + + def reset(self): + assert(self.stage) + self.stage.chdir() + + scrubbed = "scrubbed-source-tmp" + args = ['clone'] + if self.revision: + args += ['-r', self.revision] + args += [self.stage.source_path, scrubbed] + + self.hg(*args) + shutil.rmtree(self.stage.source_path, ignore_errors=True) + shutil.move(scrubbed, self.stage.source_path) + + def from_url(url): """Given a URL, find an appropriate fetch strategy for it. Currently just gives you a URLFetchStrategy that uses curl. diff --git a/var/spack/packages/lwm2/package.py b/var/spack/packages/lwm2/package.py new file mode 100644 index 0000000000..bf95c3fe12 --- /dev/null +++ b/var/spack/packages/lwm2/package.py @@ -0,0 +1,18 @@ +from spack import * + +class Lwm2(Package): + """LWM2: Light Weight Measurement Module. This is a PMPI module + that can collect a number of time-sliced MPI and POSIX I/O + measurements from a program. + """ + homepage = "https://jay.grs.rwth-aachen.de/redmine/projects/lwm2" + + version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus') + + depends_on("papi") + depends_on("mpi") + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + make() + make("install") -- cgit v1.2.3-70-g09d2 From 37e96ff6e14e419fbc31a43a1de966a7221e8ac1 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 4 Oct 2014 18:38:47 -0700 Subject: Added test for Mercurial fetching. --- lib/spack/spack/fetch_strategy.py | 35 +++---- lib/spack/spack/test/__init__.py | 3 +- lib/spack/spack/test/hg_fetch.py | 143 +++++++++++++++++++++++++++++ var/spack/mock_packages/hg-test/package.py | 10 ++ var/spack/packages/lwm2/package.py | 2 +- 5 files changed, 174 insertions(+), 19 deletions(-) create mode 100644 lib/spack/spack/test/hg_fetch.py create mode 100644 var/spack/mock_packages/hg-test/package.py diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index ad9af43c96..321c7fbd54 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -315,7 +315,7 @@ class GitFetchStrategy(VCSFetchStrategy): if self.commit: args.append('at commit %s' % self.commit) elif self.tag: - args.append('at tag %s' % self.branch) + args.append('at tag %s' % self.tag) elif self.branch: args.append('on branch %s' % self.branch) tty.msg("Trying to clone git repository:", self.url, *args) @@ -431,26 +431,21 @@ class HgFetchStrategy(VCSFetchStrategy): version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus') - You can use these three optional attributes in addition to ``hg``: + You can use the optional 'revision' attribute to check out a + branch, tag, or particular revision in hg. To prevent + non-reproducible builds, using a moving target like a branch is + discouraged. - * ``branch``: Particular branch to build from (default is 'default') - * ``tag``: Particular tag to check out - * ``revision``: Particular revision hash in the repo + * ``revision``: Particular revision, branch, or tag. """ enabled = True required_attributes = ['hg'] def __init__(self, **kwargs): super(HgFetchStrategy, self).__init__( - 'hg', 'tag', 'branch', 'revision', **kwargs) + 'hg', 'revision', **kwargs) self._hg = None - # For git fetch branches and tags the same way. - if not self.revision: - self.revision = self.branch - if not self.revision: - self.revision = self.tag - @property def hg(self): @@ -467,7 +462,10 @@ class HgFetchStrategy(VCSFetchStrategy): tty.msg("Already fetched %s." % self.stage.source_path) return - tty.msg("Trying to clone Mercurial repository: %s" % self.url) + args = [] + if self.revision: + args.append('at revision %s' % self.revision) + tty.msg("Trying to clone Mercurial repository:", self.url, *args) args = ['clone', self.url] if self.revision: @@ -480,15 +478,18 @@ class HgFetchStrategy(VCSFetchStrategy): assert(self.stage) self.stage.chdir() + source_path = self.stage.source_path scrubbed = "scrubbed-source-tmp" + args = ['clone'] if self.revision: args += ['-r', self.revision] - args += [self.stage.source_path, scrubbed] - + args += [source_path, scrubbed] self.hg(*args) - shutil.rmtree(self.stage.source_path, ignore_errors=True) - shutil.move(scrubbed, self.stage.source_path) + + shutil.rmtree(source_path, ignore_errors=True) + shutil.move(scrubbed, source_path) + self.stage.chdir_to_source() def from_url(url): diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index 61464293d2..ca4c869e42 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -49,7 +49,8 @@ test_names = ['versions', 'directory_layout', 'python_version', 'git_fetch', - 'svn_fetch'] + 'svn_fetch', + 'hg_fetch'] def list_tests(): diff --git a/lib/spack/spack/test/hg_fetch.py b/lib/spack/spack/test/hg_fetch.py new file mode 100644 index 0000000000..4b9a2f8bc9 --- /dev/null +++ b/lib/spack/spack/test/hg_fetch.py @@ -0,0 +1,143 @@ +############################################################################## +# 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 +############################################################################## +import os +import unittest +import shutil +import tempfile +from contextlib import closing + +from llnl.util.filesystem import * + +import spack +from spack.version import ver +from spack.stage import Stage +from spack.util.executable import which +from spack.test.mock_packages_test import * + +test_repo_path = 'test-repo' +test_file_name = 'test-file.txt' +test_rev1_file_name = 'test-file2.txt' +untracked = 'foobarbaz' + +hg = which('hg', required=True) + +class HgFetchTest(MockPackagesTest): + """Tests fetching from a dummy hg repository.""" + + def get_rev(self): + """Get current mercurial revision.""" + return hg('id', '-i', return_output=True).strip() + + + def setUp(self): + """Create a hg repository with master and two other branches, + and one tag, so that we can experiment on it.""" + super(HgFetchTest, self).setUp() + self.stage = Stage('fetch-test') + + self.repo_path = join_path(self.stage.path, test_repo_path) + mkdirp(self.repo_path) + + test_file = join_path(self.repo_path, test_file_name) + test_file_rev1 = join_path(self.repo_path, test_rev1_file_name) + + with working_dir(self.repo_path): + hg('init') + + touch(test_file) + hg('add', test_file) + hg('commit', '-m', 'revision 0', '-u', 'test') + self.rev0 = self.get_rev() + + touch(test_file_rev1) + hg('add', test_file_rev1) + hg('commit', '-m' 'revision 1', '-u', 'test') + self.rev1 = self.get_rev() + + spec = Spec('hg-test') + spec.concretize() + self.pkg = spack.db.get(spec, new=True) + + + def tearDown(self): + """Destroy the stage space used by this test.""" + super(HgFetchTest, self).tearDown() + + if self.stage is not None: + self.stage.destroy() + + self.pkg.do_clean_dist() + + + def assert_rev(self, rev): + """Check that the current hg revision is equal to the supplied rev.""" + self.assertEqual(self.get_rev(), rev) + + + def try_fetch(self, rev, test_file, args): + """Tries to: + 1. Fetch the repo using a fetch strategy constructed with + supplied args. + 2. Check if the test_file is in the checked out repository. + 3. Assert that the repository is at the revision supplied. + 4. Add and remove some files, then reset the repo, and + ensure it's all there again. + """ + self.pkg.versions[ver('hg')] = args + + self.pkg.do_stage() + self.assert_rev(rev) + + file_path = join_path(self.pkg.stage.source_path, test_file) + self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) + self.assertTrue(os.path.isfile(file_path)) + + os.unlink(file_path) + self.assertFalse(os.path.isfile(file_path)) + + touch(untracked) + self.assertTrue(os.path.isfile(untracked)) + self.pkg.do_clean_work() + self.assertFalse(os.path.isfile(untracked)) + + self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) + self.assertTrue(os.path.isfile(file_path)) + + self.assert_rev(rev) + + + def test_fetch_default(self): + """Test a default hg checkout with no commit or tag specified.""" + self.try_fetch(self.rev1, test_rev1_file_name, { + 'hg' : self.repo_path + }) + + + def test_fetch_rev0(self): + """Test fetching a branch.""" + self.try_fetch(self.rev0, test_file_name, { + 'hg' : self.repo_path, + 'revision' : self.rev0 + }) diff --git a/var/spack/mock_packages/hg-test/package.py b/var/spack/mock_packages/hg-test/package.py new file mode 100644 index 0000000000..462f1e4c3a --- /dev/null +++ b/var/spack/mock_packages/hg-test/package.py @@ -0,0 +1,10 @@ +from spack import * + +class HgTest(Package): + """Test package that does fetching with mercurial.""" + homepage = "http://www.hg-fetch-example.com" + + version('hg', hg='to-be-filled-in-by-test') + + def install(self, spec, prefix): + pass diff --git a/var/spack/packages/lwm2/package.py b/var/spack/packages/lwm2/package.py index bf95c3fe12..31afff8816 100644 --- a/var/spack/packages/lwm2/package.py +++ b/var/spack/packages/lwm2/package.py @@ -7,7 +7,7 @@ class Lwm2(Package): """ homepage = "https://jay.grs.rwth-aachen.de/redmine/projects/lwm2" - version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus') + version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', revision='torus') depends_on("papi") depends_on("mpi") -- cgit v1.2.3-70-g09d2 From 616d2322570937dfd9e0a90d7166c1d7489467c6 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 6 Oct 2014 10:26:54 -0700 Subject: Add package for Torsten's netgauge tool. --- var/spack/packages/netgauge/package.py | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 var/spack/packages/netgauge/package.py diff --git a/var/spack/packages/netgauge/package.py b/var/spack/packages/netgauge/package.py new file mode 100644 index 0000000000..851cd6d135 --- /dev/null +++ b/var/spack/packages/netgauge/package.py @@ -0,0 +1,35 @@ +# FIXME: +# This is a template package file for Spack. We've conveniently +# put "FIXME" labels next to all the things you'll want to change. +# +# Once you've edited all the FIXME's, delete this whole message, +# save this file, and test out your package like this: +# +# spack install netgauge +# +# You can always get back here to change things with: +# +# spack edit netgauge +# +# See the spack documentation for more information on building +# packages. +# +from spack import * + +class Netgauge(Package): + """Netgauge is a high-precision network parameter measurement + tool. It supports benchmarking of many different network protocols + and communication patterns. The main focus lies on accuracy, + statistical analysis and easy extensibility. + """ + homepage = "http://unixer.de/research/netgauge/" + url = "http://unixer.de/research/netgauge/netgauge-2.4.6.tar.gz" + + version('2.4.6', 'e0e040ec6452e93ca21ccc54deac1d7f') + + depends_on("mpi") + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + make() + make("install") -- cgit v1.2.3-70-g09d2 From 4cae48c8df8e637d6fc10a62d84c9408e82cbd2a Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 6 Oct 2014 13:48:50 -0700 Subject: Add libNBC (non-blocking collectives) --- var/spack/packages/libNBC/package.py | 43 ++++++++++++++++++++++++++++++++++ var/spack/packages/netgauge/package.py | 30 +++++++++++++++--------- 2 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 var/spack/packages/libNBC/package.py diff --git a/var/spack/packages/libNBC/package.py b/var/spack/packages/libNBC/package.py new file mode 100644 index 0000000000..6d08f3219c --- /dev/null +++ b/var/spack/packages/libNBC/package.py @@ -0,0 +1,43 @@ +############################################################################## +# 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 import * + +class Libnbc(Package): + """LibNBC is a prototypic implementation of a nonblocking + interface for MPI collective operations. Based on ANSI C and + MPI-1, it supports all MPI-1 collective operations in a + nonblocking manner. LibNBC is distributed under the BSD license. + """ + homepage = "http://unixer.de/research/nbcoll/libnbc/" + url = "http://unixer.de/research/nbcoll/libnbc/libNBC-1.1.1.tar.gz" + + version('1.1.1', 'ece5c94992591a9fa934a90e5dbe50ce') + + depends_on("mpi") + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + make() + make("install") diff --git a/var/spack/packages/netgauge/package.py b/var/spack/packages/netgauge/package.py index 851cd6d135..c2378b0718 100644 --- a/var/spack/packages/netgauge/package.py +++ b/var/spack/packages/netgauge/package.py @@ -1,19 +1,27 @@ -# FIXME: -# This is a template package file for Spack. We've conveniently -# put "FIXME" labels next to all the things you'll want to change. +############################################################################## +# Copyright (c) 2013, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. # -# Once you've edited all the FIXME's, delete this whole message, -# save this file, and test out your package like this: +# This file is part of Spack. +# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 # -# spack install netgauge +# For details, see https://scalability-llnl.github.io/spack +# Please also see the LICENSE file for our notice and the LGPL. # -# You can always get back here to change things with: +# 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. # -# spack edit netgauge -# -# See the spack documentation for more information on building -# packages. +# 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 import * class Netgauge(Package): -- cgit v1.2.3-70-g09d2 From 1c60b3967d426a6ebf42304cda113377499ea8fb Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 6 Oct 2014 14:11:19 -0700 Subject: Add simple fnmatch filtering to spack list. --- lib/spack/spack/cmd/list.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 2b996371ea..99bc64e991 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -22,15 +22,44 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## +import sys +import argparse +import llnl.util.tty as tty from llnl.util.tty.colify import colify + import spack +import fnmatch description ="List available spack packages" def setup_parser(subparser): - pass + subparser.add_argument( + 'filter', nargs=argparse.REMAINDER, + help='Optional glob patterns to filter results.') + subparser.add_argument( + '-i', '--insensitive', action='store_true', default=False, + help='Filtering will be case insensitive.') def list(parser, args): + # Start with all package names. + pkgs = spack.db.all_package_names() + + # filter if a filter arg was provided + if args.filter: + def match(p, f): + if args.insensitive: + p = p.lower() + f = f.lower() + return fnmatch.fnmatchcase(p, f) + pkgs = [p for p in pkgs if any(match(p, f) for f in args.filter)] + + # sort before displaying. + sorted_packages = sorted(pkgs, key=lambda s:s.lower()) + # Print all the package names in columns - colify(spack.db.all_package_names()) + indent=0 + if sys.stdout.isatty(): + tty.msg("%d packages." % len(sorted_packages)) + indent=2 + colify(sorted_packages, indent=indent) -- cgit v1.2.3-70-g09d2 From 4bde771970547682142bf266ccd5001d99a0d07e Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 4 Oct 2014 22:34:24 -0700 Subject: Fix for SPACK-39: Concretization was too restrictive. - concretize_version() now Use satisfies(), not intersection. - version class updated with better intersection/union commands - version now 1.6 "contains" 1.6.5 - added test for new version functionality - remove none_high and none_low classes - version module is now self-contained; save for external 2.7 functools.total_ordering for 2.6 compatibility. --- lib/spack/llnl/util/compare/__init__.py | 0 lib/spack/llnl/util/compare/none_high.py | 70 ----------------- lib/spack/llnl/util/compare/none_low.py | 70 ----------------- lib/spack/spack/concretize.py | 10 ++- lib/spack/spack/test/versions.py | 52 +++++++++++- lib/spack/spack/version.py | 131 +++++++++++++++++++++++++------ 6 files changed, 163 insertions(+), 170 deletions(-) delete mode 100644 lib/spack/llnl/util/compare/__init__.py delete mode 100644 lib/spack/llnl/util/compare/none_high.py delete mode 100644 lib/spack/llnl/util/compare/none_low.py diff --git a/lib/spack/llnl/util/compare/__init__.py b/lib/spack/llnl/util/compare/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/spack/llnl/util/compare/none_high.py b/lib/spack/llnl/util/compare/none_high.py deleted file mode 100644 index 78b41cbaf6..0000000000 --- a/lib/spack/llnl/util/compare/none_high.py +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################## -# 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 -############################################################################## -""" -Functions for comparing values that may potentially be None. -These none_high functions consider None as greater than all other values. -""" - -# Preserve builtin min and max functions -_builtin_min = min -_builtin_max = max - - -def lt(lhs, rhs): - """Less-than comparison. None is greater than any value.""" - return lhs != rhs and (rhs is None or (lhs is not None and lhs < rhs)) - - -def le(lhs, rhs): - """Less-than-or-equal comparison. None is greater than any value.""" - return lhs == rhs or lt(lhs, rhs) - - -def gt(lhs, rhs): - """Greater-than comparison. None is greater than any value.""" - return lhs != rhs and not lt(lhs, rhs) - - -def ge(lhs, rhs): - """Greater-than-or-equal comparison. None is greater than any value.""" - return lhs == rhs or gt(lhs, rhs) - - -def min(lhs, rhs): - """Minimum function where None is greater than any value.""" - if lhs is None: - return rhs - elif rhs is None: - return lhs - else: - return _builtin_min(lhs, rhs) - - -def max(lhs, rhs): - """Maximum function where None is greater than any value.""" - if lhs is None or rhs is None: - return None - else: - return _builtin_max(lhs, rhs) diff --git a/lib/spack/llnl/util/compare/none_low.py b/lib/spack/llnl/util/compare/none_low.py deleted file mode 100644 index 307bcc8a26..0000000000 --- a/lib/spack/llnl/util/compare/none_low.py +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################## -# 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 -############################################################################## -""" -Functions for comparing values that may potentially be None. -These none_low functions consider None as less than all other values. -""" - -# Preserve builtin min and max functions -_builtin_min = min -_builtin_max = max - - -def lt(lhs, rhs): - """Less-than comparison. None is lower than any value.""" - return lhs != rhs and (lhs is None or (rhs is not None and lhs < rhs)) - - -def le(lhs, rhs): - """Less-than-or-equal comparison. None is less than any value.""" - return lhs == rhs or lt(lhs, rhs) - - -def gt(lhs, rhs): - """Greater-than comparison. None is less than any value.""" - return lhs != rhs and not lt(lhs, rhs) - - -def ge(lhs, rhs): - """Greater-than-or-equal comparison. None is less than any value.""" - return lhs == rhs or gt(lhs, rhs) - - -def min(lhs, rhs): - """Minimum function where None is less than any value.""" - if lhs is None or rhs is None: - return None - else: - return _builtin_min(lhs, rhs) - - -def max(lhs, rhs): - """Maximum function where None is less than any value.""" - if lhs is None: - return rhs - elif rhs is None: - return lhs - else: - return _builtin_max(lhs, rhs) diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py index e6d1bb87d4..9f9cd1789d 100644 --- a/lib/spack/spack/concretize.py +++ b/lib/spack/spack/concretize.py @@ -68,11 +68,13 @@ class DefaultConcretizer(object): # If there are known avaialble versions, return the most recent # version that satisfies the spec pkg = spec.package - valid_versions = pkg.available_versions.intersection(spec.versions) + valid_versions = [v for v in pkg.available_versions + if any(v.satisfies(sv) for sv in spec.versions)] if valid_versions: spec.versions = ver([valid_versions[-1]]) else: - raise NoValidVerionError(spec) + print spec + raise NoValidVersionError(spec) def concretize_architecture(self, spec): @@ -160,9 +162,9 @@ class UnavailableCompilerVersionError(spack.error.SpackError): "Run 'spack compilers' to see available compiler Options.") -class NoValidVerionError(spack.error.SpackError): +class NoValidVersionError(spack.error.SpackError): """Raised when there is no available version for a package that satisfies a spec.""" def __init__(self, spec): - super(NoValidVerionError, self).__init__( + super(NoValidVersionError, self).__init__( "No available version of %s matches '%s'" % (spec.name, spec.versions)) diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index 454ab36b8a..20e946e90e 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -95,6 +95,10 @@ class VersionsTest(unittest.TestCase): self.assertEqual(ver(expected), ver(a).intersection(ver(b))) + def check_union(self, expected, a, b): + self.assertEqual(ver(expected), ver(a).union(ver(b))) + + def test_two_segments(self): self.assert_ver_eq('1.0', '1.0') self.assert_ver_lt('1.0', '2.0') @@ -217,12 +221,16 @@ class VersionsTest(unittest.TestCase): self.assert_in('1.3.5-7', '1.2:1.4') self.assert_not_in('1.1', '1.2:1.4') self.assert_not_in('1.5', '1.2:1.4') - self.assert_not_in('1.4.2', '1.2:1.4') + + self.assert_in('1.4.2', '1.2:1.4') + self.assert_not_in('1.4.2', '1.2:1.4.0') self.assert_in('1.2.8', '1.2.7:1.4') self.assert_in('1.2.7:1.4', ':') self.assert_not_in('1.2.5', '1.2.7:1.4') - self.assert_not_in('1.4.1', '1.2.7:1.4') + + self.assert_in('1.4.1', '1.2.7:1.4') + self.assert_not_in('1.4.1', '1.2.7:1.4.0') def test_in_list(self): @@ -254,6 +262,17 @@ class VersionsTest(unittest.TestCase): self.assert_overlaps('1.6:1.9', ':') + def test_overlap_with_containment(self): + self.assert_in('1.6.5', '1.6') + self.assert_in('1.6.5', ':1.6') + + self.assert_overlaps('1.6.5', ':1.6') + self.assert_overlaps(':1.6', '1.6.5') + + self.assert_not_in(':1.6', '1.6.5') + self.assert_in('1.6.5', ':1.6') + + def test_lists_overlap(self): self.assert_overlaps('1.2b:1.7,5', '1.6:1.9,1') self.assert_overlaps('1,2,3,4,5', '3,4,5,6,7') @@ -311,6 +330,32 @@ class VersionsTest(unittest.TestCase): self.check_intersection(['0:1'], [':'], ['0:1']) + def test_intersect_with_containment(self): + self.check_intersection('1.6.5', '1.6.5', ':1.6') + self.check_intersection('1.6.5', ':1.6', '1.6.5') + + self.check_intersection('1.6:1.6.5', ':1.6.5', '1.6') + self.check_intersection('1.6:1.6.5', '1.6', ':1.6.5') + + + def test_union_with_containment(self): + self.check_union(':1.6', '1.6.5', ':1.6') + self.check_union(':1.6', ':1.6', '1.6.5') + + self.check_union(':1.6', ':1.6.5', '1.6') + self.check_union(':1.6', '1.6', ':1.6.5') + + + def test_union_with_containment(self): + self.check_union(':', '1.0:', ':2.0') + + self.check_union('1:4', '1:3', '2:4') + self.check_union('1:4', '2:4', '1:3') + + # Tests successor/predecessor case. + self.check_union('1:4', '1:2', '3:4') + + def test_basic_version_satisfaction(self): self.assert_satisfies('4.7.3', '4.7.3') @@ -326,6 +371,7 @@ class VersionsTest(unittest.TestCase): self.assert_does_not_satisfy('4.8', '4.9') self.assert_does_not_satisfy('4', '4.9') + def test_basic_version_satisfaction_in_lists(self): self.assert_satisfies(['4.7.3'], ['4.7.3']) @@ -341,6 +387,7 @@ class VersionsTest(unittest.TestCase): self.assert_does_not_satisfy(['4.8'], ['4.9']) self.assert_does_not_satisfy(['4'], ['4.9']) + def test_version_range_satisfaction(self): self.assert_satisfies('4.7b6', '4.3:4.7') self.assert_satisfies('4.3.0', '4.3:4.7') @@ -352,6 +399,7 @@ class VersionsTest(unittest.TestCase): self.assert_satisfies('4.7b6', '4.3:4.7') self.assert_does_not_satisfy('4.8.0', '4.3:4.7') + def test_version_range_satisfaction_in_lists(self): self.assert_satisfies(['4.7b6'], ['4.3:4.7']) self.assert_satisfies(['4.3.0'], ['4.3:4.7']) diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py index fbf86db8e1..cc83634137 100644 --- a/lib/spack/spack/version.py +++ b/lib/spack/spack/version.py @@ -50,10 +50,6 @@ from bisect import bisect_left from functools import wraps from external.functools import total_ordering -import llnl.util.compare.none_high as none_high -import llnl.util.compare.none_low as none_low -import spack.error - # Valid version characters VALID_VERSION = r'[A-Za-z0-9_.-]' @@ -256,18 +252,39 @@ class Version(object): @coerced def __contains__(self, other): - return self == other + if other is None: + return False + return other.version[:len(self.version)] == self.version + + + def is_predecessor(self, other): + """True if the other version is the immediate predecessor of this one. + That is, NO versions v exist such that: + (self < v < other and v not in self). + """ + if len(self.version) != len(other.version): + return False + + sl = self.version[-1] + ol = other.version[-1] + return type(sl) == int and type(ol) == int and (ol - sl == 1) + + + def is_successor(self, other): + return other.is_predecessor(self) @coerced def overlaps(self, other): - return self == other + return self in other or other in self @coerced def union(self, other): - if self == other: + if self == other or other in self: return self + elif self in other: + return other else: return VersionList([self, other]) @@ -290,7 +307,7 @@ class VersionRange(object): self.start = start self.end = end - if start and end and end < start: + if start and end and end < start: raise ValueError("Invalid Version range: %s" % self) @@ -312,9 +329,12 @@ class VersionRange(object): if other is None: return False - return (none_low.lt(self.start, other.start) or - (self.start == other.start and - none_high.lt(self.end, other.end))) + s, o = self, other + if s.start != o.start: + return s.start is None or (o.start is not None and s.start < o.start) + + return (s.end != o.end and + o.end is None or (s.end is not None and s.end < o.end)) @coerced @@ -335,8 +355,23 @@ class VersionRange(object): @coerced def __contains__(self, other): - return (none_low.ge(other.start, self.start) and - none_high.le(other.end, self.end)) + if other is None: + return False + + in_lower = (self.start == other.start or + self.start is None or + (other.start is not None and ( + self.start < other.start or + other.start in self.start))) + if not in_lower: + return False + + in_upper = (self.end == other.end or + self.end is None or + (other.end is not None and ( + self.end > other.end or + other.end in self.end))) + return in_upper @coerced @@ -372,27 +407,75 @@ class VersionRange(object): @coerced def overlaps(self, other): - return (other in self or self in other or - ((self.start == None or other.end is None or - self.start <= other.end) and - (other.start is None or self.end == None or - other.start <= self.end))) + return ((self.start == None or other.end is None or + self.start <= other.end or + other.end in self.start or self.start in other.end) and + (other.start is None or self.end == None or + other.start <= self.end or + other.start in self.end or self.end in other.start)) @coerced def union(self, other): - if self.overlaps(other): - return VersionRange(none_low.min(self.start, other.start), - none_high.max(self.end, other.end)) - else: + if not self.overlaps(other): + if (self.end is not None and other.start is not None and + self.end.is_predecessor(other.start)): + return VersionRange(self.start, other.end) + + if (other.end is not None and self.start is not None and + other.end.is_predecessor(self.start)): + return VersionRange(other.start, self.end) + return VersionList([self, other]) + # if we're here, then we know the ranges overlap. + if self.start is None or other.start is None: + start = None + else: + start = self.start + # TODO: See note in intersection() about < and in discrepancy. + if self.start in other.start or other.start < self.start: + start = other.start + + if self.end is None or other.end is None: + end = None + else: + end = self.end + # TODO: See note in intersection() about < and in discrepancy. + if not other.end in self.end: + if end in other.end or other.end > self.end: + end = other.end + + return VersionRange(start, end) + @coerced def intersection(self, other): if self.overlaps(other): - return VersionRange(none_low.max(self.start, other.start), - none_high.min(self.end, other.end)) + if self.start is None: + start = other.start + else: + start = self.start + if other.start is not None: + if other.start > start or other.start in start: + start = other.start + + if self.end is None: + end = other.end + else: + end = self.end + # TODO: does this make sense? + # This is tricky: + # 1.6.5 in 1.6 = True (1.6.5 is more specific) + # 1.6 < 1.6.5 = True (lexicographic) + # Should 1.6 NOT be less than 1.6.5? Hm. + # Here we test (not end in other.end) first to avoid paradox. + if other.end is not None and not end in other.end: + if other.end < end or other.end in end: + end = other.end + + return VersionRange(start, end) + else: return VersionList() -- cgit v1.2.3-70-g09d2 From 1801a859666aae832e393a534c47064c68cb1b22 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 7 Oct 2014 23:22:58 -0700 Subject: Move tty output commands out of package and into clean command. --- lib/spack/spack/cmd/clean.py | 10 +++++++++- lib/spack/spack/package.py | 15 +++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/spack/spack/cmd/clean.py b/lib/spack/spack/cmd/clean.py index 1df9d87ae2..79dd91c5bf 100644 --- a/lib/spack/spack/cmd/clean.py +++ b/lib/spack/spack/cmd/clean.py @@ -52,7 +52,15 @@ def clean(parser, args): package = spack.db.get(spec) if args.dist: package.do_clean_dist() + tty.msg("Cleaned %s" % package.name) + elif args.work: package.do_clean_work() + tty.msg("Restaged %s" % package.name) + else: - package.do_clean() + try: + package.do_clean() + except subprocess.CalledProcessError, e: + tty.warn("Warning: 'make clean' didn't work. Consider 'spack clean --work'.") + tty.msg("Made clean for %s" % package.name) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 59bfafa241..ee3e73a072 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -427,7 +427,7 @@ class Package(object): return self.url or self.version_urls() - # TODO: move this out of here and into some URL extrapolation module. + # TODO: move this out of here and into some URL extrapolation module? def url_for_version(self, version): """Returns a URL that you can download a new version of this package from.""" if not isinstance(version, Version): @@ -598,7 +598,7 @@ class Package(object): @property def default_url(self): - if self.concrete: + if self.spec.version.concrete: return self.url_for_version(self.version) else: url = getattr(self, 'url', None) @@ -841,13 +841,9 @@ class Package(object): def clean(self): """By default just runs make clean. Override if this isn't good.""" - try: - # TODO: should we really call make clean, ro just blow away the directory? - make = build_env.MakeExecutable('make', self.parallel) - make('clean') - tty.msg("Successfully cleaned %s" % self.name) - except subprocess.CalledProcessError, e: - tty.warn("Warning: 'make clean' didn't work. Consider 'spack clean --work'.") + # TODO: should we really call make clean, ro just blow away the directory? + make = build_env.MakeExecutable('make', self.parallel) + make('clean') def do_clean_work(self): @@ -859,7 +855,6 @@ class Package(object): """Removes the stage directory where this package was built.""" if os.path.exists(self.stage.path): self.stage.destroy() - tty.msg("Successfully cleaned %s" % self.name) def fetch_available_versions(self): -- cgit v1.2.3-70-g09d2 From e8d131ef96e33b5fc7f5f7c31511d2fc9e99cb52 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 7 Oct 2014 23:23:18 -0700 Subject: Minor bugfix in exception constructor. --- lib/spack/spack/spec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 4838fd9946..a0ab38c049 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -1619,7 +1619,7 @@ class UnsatisfiableSpecError(SpecError): class UnsatisfiableSpecNameError(UnsatisfiableSpecError): """Raised when two specs aren't even for the same package.""" def __init__(self, provided, required): - super(UnsatisfiableVersionSpecError, self).__init__( + super(UnsatisfiableSpecNameError, self).__init__( provided, required, "name") -- cgit v1.2.3-70-g09d2 From ee23cc2527c5294aea85b571eb1c39b73da0924a Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 7 Oct 2014 23:26:39 -0700 Subject: Add archive creation capability to fetch strategies. - fetch strategy needs to know how to create archive of fetched repo - allows mirrors to be created from git/other VCS fetches. --- lib/spack/spack/fetch_strategy.py | 52 ++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 321c7fbd54..8905dc7d5f 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -50,7 +50,7 @@ import spack.util.crypto as crypto from spack.util.executable import * from spack.util.string import * from spack.version import Version, ver -from spack.util.compression import decompressor_for +from spack.util.compression import decompressor_for, extension """List of all fetch strategies, created by FetchStrategy metaclass.""" all_strategies = [] @@ -81,11 +81,14 @@ class FetchStrategy(object): # Subclasses need to implement these methods - def fetch(self): pass # Return True on success, False on fail - def check(self): pass - def expand(self): pass - def reset(self): pass - def __str__(self): + def fetch(self): pass # Return True on success, False on fail. + def check(self): pass # Do checksum. + def expand(self): pass # Expand archive. + def reset(self): pass # Revert to freshly downloaded state. + + def archive(self, destination): pass # Used to create tarball for mirror. + + def __str__(self): # Should be human readable URL. return "FetchStrategy.__str___" # This method is used to match fetch strategies to version() @@ -185,6 +188,14 @@ class URLFetchStrategy(FetchStrategy): decompress(self.archive_file) + def archive(self, destination): + """This archive""" + if not self.archive_file: + raise NoArchiveFileError("Cannot call archive() before fetching.") + assert(extension(destination) == extension(self.archive_file)) + shutil.move(self.archive_file, destination) + + def check(self): """Check the downloaded archive against a checksum digest. No-op if this stage checks code out of a repository.""" @@ -251,6 +262,23 @@ class VCSFetchStrategy(FetchStrategy): tty.debug("Source fetched with %s is already expanded." % self.name) + def archive(self, destination, **kwargs): + assert(extension(destination) == 'tar.gz') + assert(self.stage.source_path.startswith(self.stage.path)) + + tar = which('tar', required=True) + + patterns = kwargs.get('exclude', None) + if patterns is not None: + if isinstance(patterns, basestring): + patterns = [patterns] + for p in patterns: + tar.add_default_arg('--exclude=%s' % p) + + self.stage.chdir() + tar('-czf', destination, os.path.basename(self.stage.source_path)) + + def __str__(self): return self.url @@ -345,6 +373,10 @@ class GitFetchStrategy(VCSFetchStrategy): self.stage.chdir_to_source() + def archive(self, destination): + super(GitFetchStrategy, self).archive(destination, exclude='.git') + + def reset(self): assert(self.stage) self.stage.chdir_to_source() @@ -414,6 +446,10 @@ class SvnFetchStrategy(VCSFetchStrategy): shutil.rmtree(path, ignore_errors=True) + def archive(self, destination): + super(SvnFetchStrategy, self).archive(destination, exclude='.svn') + + def reset(self): assert(self.stage) self.stage.chdir_to_source() @@ -474,6 +510,10 @@ class HgFetchStrategy(VCSFetchStrategy): self.hg(*args) + def archive(self, destination): + super(HgFetchStrategy, self).archive(destination, exclude='.hg') + + def reset(self): assert(self.stage) self.stage.chdir() -- cgit v1.2.3-70-g09d2 From ff546358f3395efb6ec8999804b79cea85cf7fa9 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 7 Oct 2014 23:32:34 -0700 Subject: Update docs to use new version format. --- lib/spack/docs/features.rst | 2 +- lib/spack/docs/packaging_guide.rst | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/spack/docs/features.rst b/lib/spack/docs/features.rst index 22dc594d7f..b39dcd3390 100644 --- a/lib/spack/docs/features.rst +++ b/lib/spack/docs/features.rst @@ -93,7 +93,7 @@ creates a simple python file: homepage = "http://www.example.com/" url = "http://www.mr511.de/software/libelf-0.8.13.tar.gz" - versions = { '0.8.13' : '4136d7b4c04df68b686570afa26988ac' } + version('0.8.13', '4136d7b4c04df68b686570afa26988ac') def install(self, prefix): configure("--prefix=%s" % prefix) diff --git a/lib/spack/docs/packaging_guide.rst b/lib/spack/docs/packaging_guide.rst index 13785e25b7..0ec8047dad 100644 --- a/lib/spack/docs/packaging_guide.rst +++ b/lib/spack/docs/packaging_guide.rst @@ -286,9 +286,9 @@ Now Spack generates boilerplate code and opens the new homepage = "http://www.example.com" url = "http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz" - versions = { '2.8.12.1' : '9d38cd4e2c94c3cea97d0e2924814acc', - '2.8.12' : '105bc6d21cc2e9b6aff901e43c53afea', - '2.8.11.2' : '6f5d7b8e7534a5d9e1a7664ba63cf882', } + version('2.8.12.1', '9d38cd4e2c94c3cea97d0e2924814acc') + version('2.8.12', '105bc6d21cc2e9b6aff901e43c53afea') + version('2.8.11.2', '6f5d7b8e7534a5d9e1a7664ba63cf882') def install(self, spec, prefix): # FIXME: Modify the configure line to suit your build system here. @@ -349,7 +349,7 @@ Which will generate a minimal package structure for you to fill in: homepage = "http://www.example.com" url = "http://www.example.com/foo-1.0.tar.gz" - versions = { '1.0' : '0123456789abcdef0123456789abcdef' } + version('1.0', '0123456789abcdef0123456789abcdef') def install(self, spec, prefix): configure("--prefix=" + prefix) @@ -395,12 +395,10 @@ and paste into your package file: .. code-block:: sh ==> Checksummed new versions of libelf: - { - '0.8.13' : '4136d7b4c04df68b686570afa26988ac', - '0.8.12' : 'e21f8273d9f5f6d43a59878dc274fec7', - '0.8.11' : 'e931910b6d100f6caa32239849947fbf', - '0.8.10' : '9db4d36c283d9790d8fa7df1f4d7b4d9', - } + version('0.8.13', '4136d7b4c04df68b686570afa26988ac') + version('0.8.12', 'e21f8273d9f5f6d43a59878dc274fec7') + version('0.8.11', 'e931910b6d100f6caa32239849947fbf') + version('0.8.10', '9db4d36c283d9790d8fa7df1f4d7b4d9') You should be able to add these checksums directly to the versions field in your package. -- cgit v1.2.3-70-g09d2 From 319b37af0ea84a6ba88d9a6b3a71f17b35c7f0f5 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 7 Oct 2014 23:52:32 -0700 Subject: Add spack edit -c option to edit commands. --- lib/spack/spack/cmd/edit.py | 49 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/spack/spack/cmd/edit.py b/lib/spack/spack/cmd/edit.py index 3647186a3c..842dcd7faf 100644 --- a/lib/spack/spack/cmd/edit.py +++ b/lib/spack/spack/cmd/edit.py @@ -27,9 +27,10 @@ import string from contextlib import closing import llnl.util.tty as tty -from llnl.util.filesystem import mkdirp +from llnl.util.filesystem import mkdirp, join_path import spack +import spack.cmd from spack.util.naming import mod_to_class description = "Open package files in $EDITOR" @@ -57,6 +58,9 @@ def setup_parser(subparser): subparser.add_argument( '-f', '--force', dest='force', action='store_true', help="Open a new file in $EDITOR even if package doesn't exist.") + subparser.add_argument( + '-c', '--command', dest='edit_command', action='store_true', + help="Edit the command with the supplied name instead of a package.") subparser.add_argument( 'name', nargs='?', default=None, help="name of package to edit") @@ -64,25 +68,34 @@ def setup_parser(subparser): def edit(parser, args): name = args.name - # By default open the directory where packages live. - if not name: - path = spack.packages_path + if args.edit_command: + if not name: + path = spack.cmd.command_path + else: + path = join_path(spack.cmd.command_path, name + ".py") + if not os.path.exists(path): + tty.die("No command named '%s'." % name) + else: - path = spack.db.filename_for_package_name(name) - - if os.path.exists(path): - if not os.path.isfile(path): - tty.die("Something's wrong. '%s' is not a file!" % path) - if not os.access(path, os.R_OK|os.W_OK): - tty.die("Insufficient permissions on '%s'!" % path) - elif not args.force: - tty.die("No package '%s'. Use spack create, or supply -f/--force " - "to edit a new file." % name) + # By default open the directory where packages or commands live. + if not name: + path = spack.packages_path else: - mkdirp(os.path.dirname(path)) - with closing(open(path, "w")) as pkg_file: - pkg_file.write( - package_template.substitute(name=name, class_name=mod_to_class(name))) + path = spack.db.filename_for_package_name(name) + + if os.path.exists(path): + if not os.path.isfile(path): + tty.die("Something's wrong. '%s' is not a file!" % path) + if not os.access(path, os.R_OK|os.W_OK): + tty.die("Insufficient permissions on '%s'!" % path) + elif not args.force: + tty.die("No package '%s'. Use spack create, or supply -f/--force " + "to edit a new file." % name) + else: + mkdirp(os.path.dirname(path)) + with closing(open(path, "w")) as pkg_file: + pkg_file.write( + package_template.substitute(name=name, class_name=mod_to_class(name))) # If everything checks out, go ahead and edit. spack.editor(path) -- cgit v1.2.3-70-g09d2 From 36a87f5bf9884978ba1f672322d9b7f663cf4f58 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 8 Oct 2014 03:07:54 -0700 Subject: Update documentation to add an auto-generated list of packages. --- lib/spack/docs/.gitignore | 1 + lib/spack/docs/Makefile | 9 +- .../docs/_themes/sphinx_rtd_theme/footer.html | 2 +- lib/spack/docs/conf.py | 2 +- lib/spack/docs/index.rst | 1 + lib/spack/llnl/util/tty/colify.py | 8 +- lib/spack/spack/cmd/info.py | 118 +++++++++++++++++---- var/spack/packages/cmake/package.py | 2 + var/spack/packages/dyninst/package.py | 2 + var/spack/packages/launchmon/package.py | 2 + var/spack/packages/libunwind/package.py | 2 + var/spack/packages/scr/package.py | 3 + var/spack/packages/spindle/package.py | 5 + 13 files changed, 133 insertions(+), 24 deletions(-) diff --git a/lib/spack/docs/.gitignore b/lib/spack/docs/.gitignore index 4d5300fbb9..7701dd9f12 100644 --- a/lib/spack/docs/.gitignore +++ b/lib/spack/docs/.gitignore @@ -1,2 +1,3 @@ +package_list.rst spack*.rst _build diff --git a/lib/spack/docs/Makefile b/lib/spack/docs/Makefile index 4baba720ef..4d71c2052e 100644 --- a/lib/spack/docs/Makefile +++ b/lib/spack/docs/Makefile @@ -21,6 +21,12 @@ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . all: html +# +# This autogenerates a package list. +# +package_list: + spack info -r > package_list.rst + # # This creates a git repository and commits generated html docs. # It them pushes the new branch into THIS repository as gh-pages. @@ -69,9 +75,10 @@ help: @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: + -rm -f package_list.rst -rm -rf $(BUILDDIR)/* $(APIDOC_FILES) -html: apidoc +html: apidoc package_list $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." diff --git a/lib/spack/docs/_themes/sphinx_rtd_theme/footer.html b/lib/spack/docs/_themes/sphinx_rtd_theme/footer.html index 0eccd11178..5ec315e58f 100644 --- a/lib/spack/docs/_themes/sphinx_rtd_theme/footer.html +++ b/lib/spack/docs/_themes/sphinx_rtd_theme/footer.html @@ -13,7 +13,7 @@

- © Copyright 2013, + © Copyright 2013-2014, Lawrence Livermore National Laboratory.
Written by Todd Gamblin, tgamblin@llnl.gov, LLNL-CODE-647188 diff --git a/lib/spack/docs/conf.py b/lib/spack/docs/conf.py index 700cb00299..b4d49c594d 100644 --- a/lib/spack/docs/conf.py +++ b/lib/spack/docs/conf.py @@ -90,7 +90,7 @@ master_doc = 'index' # General information about the project. project = u'Spack' -copyright = u'2013, Lawrence Livermore National Laboratory' +copyright = u'2013-2014, Lawrence Livermore National Laboratory' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/lib/spack/docs/index.rst b/lib/spack/docs/index.rst index ac0eac93f3..73eff43ab7 100644 --- a/lib/spack/docs/index.rst +++ b/lib/spack/docs/index.rst @@ -48,6 +48,7 @@ Table of Contents packaging_guide site_configuration developer_guide + package_list API Docs Indices and tables diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py index 5586b2681a..ff06241937 100644 --- a/lib/spack/llnl/util/tty/colify.py +++ b/lib/spack/llnl/util/tty/colify.py @@ -109,13 +109,15 @@ def colify(elts, **options): # elts needs to be an array of strings so we can count the elements elts = [str(elt) for elt in elts] if not elts: - return + return (0, ()) if not tty: if tty is False or not isatty(output): for elt in elts: output.write("%s\n" % elt) - return + + maxlen = max(len(str(s)) for s in elts) + return (1, (maxlen,)) console_cols = options.get("cols", None) if not console_cols: @@ -150,6 +152,8 @@ def colify(elts, **options): if row == rows_last_col: cols -= 1 + return (config.cols, tuple(config.widths)) + def colified(elts, **options): """Invokes the colify() function but returns the result as a string diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index bb147b30f5..c86dcac2f5 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -24,52 +24,132 @@ ############################################################################## import re import textwrap -from llnl.util.tty.colify import colify +from StringIO import StringIO +from llnl.util.tty.colify import * import spack description = "Get detailed information on a particular package" def setup_parser(subparser): - subparser.add_argument('name', metavar="PACKAGE", help="name of packages to get info on") + subparser.add_argument('-r', '--rst', action='store_true', + help="List all packages in reStructured text, for docs.") + subparser.add_argument('name', metavar="PACKAGE", nargs='?', help="name of packages to get info on") -def info(parser, args): - package = spack.db.get(args.name) - print "Package: ", package.name - print "Homepage: ", package.homepage +def format_doc(pkg, **kwargs): + """Wrap doc string at 72 characters and format nicely""" + indent = kwargs.get('indent', 0) + + if not pkg.__doc__: + return "" + + doc = re.sub(r'\s+', ' ', pkg.__doc__) + lines = textwrap.wrap(doc, 72) + results = StringIO() + for line in lines: + results.write((" " * indent) + line + "\n") + return results.getvalue() + + +def github_url(pkg): + """Link to a package file on github.""" + return ("https://github.com/scalability-llnl/spack/blob/master/var/spack/packages/%s/package.py" % + pkg.name) + + +def rst_table(elts): + """Print out a RST-style table.""" + cols = StringIO() + ncol, widths = colify(elts, output=cols, tty=True) + header = " ".join("=" * (w-1) for w in widths) + return "%s\n%s%s" % (header, cols.getvalue(), header) + + +def info_rst(): + """Print out information on all packages in restructured text.""" + pkgs = sorted(spack.db.all_packages(), key=lambda s:s.name.lower()) + + print "Package List" + print "==================" + + print "This is a list of things you can install using Spack. It is" + print "automatically generated based on the packages in the latest Spack" + print "release." + print + + print "Spack currently has %d mainline packages:" % len(pkgs) + print + print rst_table("`%s`_" % p.name for p in pkgs) + print + print "-----" + + # Output some text for each package. + for pkg in pkgs: + print + print ".. _%s:" % pkg.name + print + print pkg.name + print "-" * len(pkg.name) + print "Links" + print " * `Homepage <%s>`__" % pkg.homepage + print " * `%s/package.py <%s>`__" % (pkg.name, github_url(pkg)) + print + if pkg.dependencies: + print "Dependencies" + print " " + ", ".join("`%s`_" % d if d != "mpi" else d + for d in pkg.dependencies) + print + print "Description" + print format_doc(pkg, indent=2) + print + print "-----" + + +def info_text(pkg): + """Print out a plain text description of a package.""" + print "Package: ", pkg.name + print "Homepage: ", pkg.homepage print print "Safe versions: " - if not package.versions: + if not pkg.versions: print("None.") else: - maxlen = max(len(str(v)) for v in package.versions) + maxlen = max(len(str(v)) for v in pkg.versions) fmt = "%%-%ss" % maxlen - for v in reversed(sorted(package.versions)): - print " " + (fmt % v) + " " + package.url_for_version(v) + for v in reversed(sorted(pkg.versions)): + print " " + (fmt % v) + " " + pkg.url_for_version(v) print print "Dependencies:" - if package.dependencies: - colify(package.dependencies, indent=4) + if pkg.dependencies: + colify(pkg.dependencies, indent=4) else: print " None" print print "Virtual packages: " - if package.provided: - for spec, when in package.provided.items(): + if pkg.provided: + for spec, when in pkg.provided.items(): print " %s provides %s" % (when, spec) else: print " None" print print "Description:" - if package.__doc__: - doc = re.sub(r'\s+', ' ', package.__doc__) - lines = textwrap.wrap(doc, 72) - for line in lines: - print " " + line + if pkg.__doc__: + print format_doc(pkg, indent=4) else: print " None" + + +def info(parser, args): + if args.rst: + info_rst() + + else: + if not args.name: + tty.die("You must supply a package name.") + pkg = spack.db.get(args.name) + info_text(pkg) diff --git a/var/spack/packages/cmake/package.py b/var/spack/packages/cmake/package.py index ca6553df84..890af9baa9 100644 --- a/var/spack/packages/cmake/package.py +++ b/var/spack/packages/cmake/package.py @@ -25,6 +25,8 @@ from spack import * class Cmake(Package): + """A cross-platform, open-source build system. CMake is a family of + tools designed to build, test and package software.""" homepage = 'https://www.cmake.org' url = 'http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz' diff --git a/var/spack/packages/dyninst/package.py b/var/spack/packages/dyninst/package.py index 069237f7ff..df19ac7bc0 100644 --- a/var/spack/packages/dyninst/package.py +++ b/var/spack/packages/dyninst/package.py @@ -25,6 +25,8 @@ from spack import * class Dyninst(Package): + """API for dynamic binary instrumentation. Modify programs while they + are executing without recompiling, re-linking, or re-executing.""" homepage = "https://paradyn.org" url = "http://www.dyninst.org/sites/default/files/downloads/dyninst/8.1.2/DyninstAPI-8.1.2.tgz" list_url = "http://www.dyninst.org/downloads/dyninst-8.x" diff --git a/var/spack/packages/launchmon/package.py b/var/spack/packages/launchmon/package.py index b6773a85bc..bdf988bdd3 100644 --- a/var/spack/packages/launchmon/package.py +++ b/var/spack/packages/launchmon/package.py @@ -25,6 +25,8 @@ from spack import * class Launchmon(Package): + """Software infrastructure that enables HPC run-time tools to + co-locate tool daemons with a parallel job.""" homepage = "http://sourceforge.net/projects/launchmon" url = "http://downloads.sourceforge.net/project/launchmon/launchmon/1.0.1%20release/launchmon-1.0.1.tar.gz" diff --git a/var/spack/packages/libunwind/package.py b/var/spack/packages/libunwind/package.py index aeadc85eb3..239fcbcfd5 100644 --- a/var/spack/packages/libunwind/package.py +++ b/var/spack/packages/libunwind/package.py @@ -25,6 +25,8 @@ from spack import * class Libunwind(Package): + """A portable and efficient C programming interface (API) to determine + the call-chain of a program.""" homepage = "http://www.nongnu.org/libunwind/" url = "http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz" diff --git a/var/spack/packages/scr/package.py b/var/spack/packages/scr/package.py index d480dba62f..d456ecaba0 100644 --- a/var/spack/packages/scr/package.py +++ b/var/spack/packages/scr/package.py @@ -25,6 +25,9 @@ from spack import * class Scr(Package): + """SCR caches checkpoint data in storage on the compute nodes of a + Linux cluster to provide a fast, scalable checkpoint/restart + capability for MPI codes""" homepage = "https://computation-rnd.llnl.gov/scr" url = "http://downloads.sourceforge.net/project/scalablecr/releases/scr-1.1-7.tar.gz" diff --git a/var/spack/packages/spindle/package.py b/var/spack/packages/spindle/package.py index bb0b74ab6f..fd59282ebb 100644 --- a/var/spack/packages/spindle/package.py +++ b/var/spack/packages/spindle/package.py @@ -25,6 +25,11 @@ from spack import * class Spindle(Package): + """Spindle improves the library-loading performance of dynamically + linked HPC applications. Without Spindle large MPI jobs can + overload on a shared file system when loading dynamically + linked libraries, causing site-wide performance problems. + """ homepage = "https://computation-rnd.llnl.gov/spindle" url = "https://github.com/hpc/Spindle/archive/v0.8.1.tar.gz" list_url = "https://github.com/hpc/Spindle/releases" -- cgit v1.2.3-70-g09d2 From 4c614ac768dafd465d50f31bfebc0c3296881113 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 7 Oct 2014 09:21:05 -0700 Subject: Add SUNDIALS solver package. --- var/spack/packages/sundials/package.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 var/spack/packages/sundials/package.py diff --git a/var/spack/packages/sundials/package.py b/var/spack/packages/sundials/package.py new file mode 100644 index 0000000000..8b784c8c3c --- /dev/null +++ b/var/spack/packages/sundials/package.py @@ -0,0 +1,39 @@ +############################################################################## +# 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 import * + +class Sundials(Package): + """SUNDIALS (SUite of Nonlinear and DIfferential/ALgebraic equation Solvers)""" + homepage = "http://computation.llnl.gov/casc/sundials/" + url = "http://computation.llnl.gov/casc/sundials/download/code/sundials-2.5.0.tar.gz" + + version('2.5.0', 'aba8b56eec600de3109cfb967aa3ba0f') + + depends_on("mpi") + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + make() + make("install") -- cgit v1.2.3-70-g09d2 From dd2cea4107b5c8b29121932967c6527781329266 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 8 Oct 2014 14:08:11 -0700 Subject: Add available versions to generated package list documentation. --- lib/spack/docs/Makefile | 4 +++- lib/spack/spack/cmd/info.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/spack/docs/Makefile b/lib/spack/docs/Makefile index 4d71c2052e..e3068ea10c 100644 --- a/lib/spack/docs/Makefile +++ b/lib/spack/docs/Makefile @@ -42,12 +42,14 @@ gh-pages: _build/html touch .nojekyll && \ git init && \ git add . && \ - git commit -m "Initial commit" && \ + git commit -m "Spack Documentation" && \ git push -f $$root master:gh-pages && \ rm -rf .git upload: rsync -avz --rsh=ssh --delete _build/html/ cab:/usr/global/web-pages/lc/www/adept/docs/spack + git push -f origin gh-pages + git push -f github gh-pages apidoc: sphinx-apidoc -T -o . $(PYTHONPATH)/spack diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index c86dcac2f5..87d272dbc6 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -94,6 +94,9 @@ def info_rst(): print " * `Homepage <%s>`__" % pkg.homepage print " * `%s/package.py <%s>`__" % (pkg.name, github_url(pkg)) print + if pkg.versions: + print "Versions:" + print " " + ", ".join(str(v) for v in reversed(sorted(pkg.versions))) if pkg.dependencies: print "Dependencies" print " " + ", ".join("`%s`_" % d if d != "mpi" else d -- cgit v1.2.3-70-g09d2 From 8857b1f69e4a2dca5d08e7817c69e080da8e8266 Mon Sep 17 00:00:00 2001 From: David Boehme Date: Wed, 8 Oct 2014 17:31:11 -0700 Subject: Add Scalasca 2.1 --- var/spack/packages/scalasca/package.py | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/var/spack/packages/scalasca/package.py b/var/spack/packages/scalasca/package.py index b76d0a7df5..cf7a40c1f5 100644 --- a/var/spack/packages/scalasca/package.py +++ b/var/spack/packages/scalasca/package.py @@ -11,25 +11,47 @@ class Scalasca(Package): # FIXME: add a proper url for your package's homepage here. homepage = "http://www.scalasca.org" - url = "http://apps.fz-juelich.de/scalasca/releases/scalasca/2.1/dist/scalasca-2.1-rc2.tar.gz" + url = "http://apps.fz-juelich.de/scalasca/releases/scalasca/2.1/dist/scalasca-2.1.tar.gz" - version('2.1-rc2', '1a95a39e5430539753e956a7524a756b') + version('2.1', 'bab9c2b021e51e2ba187feec442b96e6', + url = 'http://apps.fz-juelich.de/scalasca/releases/scalasca/2.1/dist/scalasca-2.1.tar.gz' ) depends_on("mpi") depends_on("otf2@1.4") - depends_on("cube") + depends_on("cube@4.2.3") + + backend_user_provided = """\ +CC=cc +CXX=c++ +F77=f77 +FC=f90 +CFLAGS=-fPIC +CXXFLAGS=-fPIC +""" + frontend_user_provided = """\ +CC_FOR_BUILD=cc +CXX_FOR_BUILD=c++ +F77_FOR_BUILD=f70 +FC_FOR_BUILD=f90 +CFLAGS_FOR_BUILD=-fPIC +CXXFLAGS_FOR_BUILD=-fPIC +""" + mpi_user_provided = """\ +MPICC=mpicc +MPICXX=mpicxx +MPIF77=mpif77 +MPIFC=mpif90 +MPI_CFLAGS=-fPIC +MPI_CXXFLAGS=-fPIC +""" def install(self, spec, prefix): configure_args = ["--prefix=%s" % prefix, + "--with-custom-compilers", "--with-otf2=%s" % spec['otf2'].prefix.bin, "--with-cube=%s" % spec['cube'].prefix.bin, "--enable-shared"] - if spec.satisfies('%gcc'): - configure_args.append('--with-nocross-compiler-suite=gcc') - if spec.satisfies('%intel'): - configure_args.append('--with-nocross-compiler-suite=intel') - configure(*configure_args) make() -- cgit v1.2.3-70-g09d2 From 1fcfb80bdd688775e30660c7a777a368dd8fcc71 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 10 Oct 2014 09:21:31 -0700 Subject: SPACK-19 no longer an issue. Removing libtool copy. --- var/spack/packages/stat/package.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/var/spack/packages/stat/package.py b/var/spack/packages/stat/package.py index 956b0dcc8c..5df07975f7 100644 --- a/var/spack/packages/stat/package.py +++ b/var/spack/packages/stat/package.py @@ -27,9 +27,5 @@ class Stat(Package): "--with-stackwalker=%s" % spec['dyninst'].prefix, "--with-libdwarf=%s" % spec['libdwarf'].prefix) - # TODO: remove once SPACK-19 is fixed - import shutil - shutil.copy2('/usr/bin/libtool', 'libtool') - make(parallel=False) make("install") -- cgit v1.2.3-70-g09d2 From 8fd4d324087c6467e6aa68ae93bf7c83b43cec89 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 10 Oct 2014 09:45:48 -0700 Subject: Use external argparse in spack list, for 2.6 compatibility. --- lib/spack/spack/cmd/list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/list.py b/lib/spack/spack/cmd/list.py index 99bc64e991..5c7051d6a9 100644 --- a/lib/spack/spack/cmd/list.py +++ b/lib/spack/spack/cmd/list.py @@ -23,8 +23,8 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import sys -import argparse import llnl.util.tty as tty +from external import argparse from llnl.util.tty.colify import colify import spack -- cgit v1.2.3-70-g09d2 From fbd7e966808abf28b04ad9a98d359d425c8d7635 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 14 Oct 2014 23:26:43 -0700 Subject: Add a mirror module that handles new fetch strategies. - Uses new fetchers to get source - Add archive() method to fetch strategies to support this. - Updated mirror command to use new mirror module --- lib/spack/spack/cmd/mirror.py | 130 ++++++++--------------------- lib/spack/spack/fetch_strategy.py | 59 +++++++++++-- lib/spack/spack/mirror.py | 171 ++++++++++++++++++++++++++++++++++++++ lib/spack/spack/package.py | 19 +++-- 4 files changed, 270 insertions(+), 109 deletions(-) create mode 100644 lib/spack/spack/mirror.py diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index b42b329085..6a6c2b60c7 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -23,23 +23,19 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import os -import shutil +import sys from datetime import datetime -from contextlib import closing from external import argparse import llnl.util.tty as tty from llnl.util.tty.colify import colify -from llnl.util.filesystem import mkdirp, join_path import spack import spack.cmd import spack.config +import spack.mirror from spack.spec import Spec from spack.error import SpackError -from spack.stage import Stage -from spack.util.compression import extension - description = "Manage mirrors." @@ -105,26 +101,33 @@ def mirror_list(args): print fmt % (name, val) +def _read_specs_from_file(filename): + with closing(open(filename, "r")) as stream: + for i, string in enumerate(stream): + try: + s = Spec(string) + s.package + args.specs.append(s) + except SpackError, e: + tty.die("Parse error in %s, line %d:" % (args.file, i+1), + ">>> " + string, str(e)) + + def mirror_create(args): """Create a directory to be used as a spack mirror, and fill it with package archives.""" # try to parse specs from the command line first. - args.specs = spack.cmd.parse_specs(args.specs) + specs = spack.cmd.parse_specs(args.specs) # If there is a file, parse each line as a spec and add it to the list. if args.file: - with closing(open(args.file, "r")) as stream: - for i, string in enumerate(stream): - try: - s = Spec(string) - s.package - args.specs.append(s) - except SpackError, e: - tty.die("Parse error in %s, line %d:" % (args.file, i+1), - ">>> " + string, str(e)) - - if not args.specs: - args.specs = [Spec(n) for n in spack.db.all_package_names()] + if specs: + tty.die("Cannot pass specs on the command line with --file.") + specs = _read_specs_from_file(args.file) + + # If nothing is passed, use all packages. + if not specs: + specs = [Spec(n) for n in spack.db.all_package_names()] # Default name for directory is spack-mirror- if not args.directory: @@ -132,85 +135,23 @@ def mirror_create(args): args.directory = 'spack-mirror-' + timestamp # Make sure nothing is in the way. + existed = False if os.path.isfile(args.directory): tty.error("%s already exists and is a file." % args.directory) + elif os.path.isdir(args.directory): + existed = True - # Create a directory if none exists - if not os.path.isdir(args.directory): - mkdirp(args.directory) - tty.msg("Created new mirror in %s" % args.directory) - else: - tty.msg("Adding to existing mirror in %s" % args.directory) - - # Things to keep track of while parsing specs. - working_dir = os.getcwd() - num_mirrored = 0 - num_error = 0 - - # Iterate through packages and download all the safe tarballs for each of them - for spec in args.specs: - pkg = spec.package - - # Skip any package that has no checksummed versions. - if not pkg.versions: - tty.msg("No safe (checksummed) versions for package %s." - % pkg.name) - continue - - # create a subdir for the current package. - pkg_path = join_path(args.directory, pkg.name) - mkdirp(pkg_path) - - # Download all the tarballs using Stages, then move them into place - for version in pkg.versions: - # Skip versions that don't match the spec - vspec = Spec('%s@%s' % (pkg.name, version)) - if not vspec.satisfies(spec): - continue - - mirror_path = "%s/%s-%s.%s" % ( - pkg.name, pkg.name, version, extension(pkg.url)) - - os.chdir(working_dir) - mirror_file = join_path(args.directory, mirror_path) - if os.path.exists(mirror_file): - tty.msg("Already fetched %s." % mirror_file) - num_mirrored += 1 - continue - - # Get the URL for the version and set up a stage to download it. - url = pkg.url_for_version(version) - stage = Stage(url) - try: - # fetch changes directory into the stage - stage.fetch() + # Actually do the work to create the mirror + present, mirrored, error = spack.mirror.create(args.directory, specs) + p, m, e = len(present), len(mirrored), len(error) - if not args.no_checksum and version in pkg.versions: - digest = pkg.versions[version] - stage.check(digest) - tty.msg("Checksum passed for %s@%s" % (pkg.name, version)) - - # change back and move the new archive into place. - os.chdir(working_dir) - shutil.move(stage.archive_file, mirror_file) - tty.msg("Added %s to mirror" % mirror_file) - num_mirrored += 1 - - except Exception, e: - tty.warn("Error while fetching %s." % url, e.message) - num_error += 1 - - finally: - stage.destroy() - - # If nothing happened, try to say why. - if not num_mirrored: - if num_error: - tty.error("No packages added to mirror.", - "All packages failed to fetch.") - else: - tty.error("No packages added to mirror. No versions matched specs:") - colify(args.specs, indent=4) + verb = "updated" if existed else "created" + tty.msg( + "Successfully %s mirror in %s." % (verb, args.directory), + "Archive stats:", + " %-4d already present" % p, + " %-4d added" % m, + " %-4d failed to fetch." % e) def mirror(parser, args): @@ -218,4 +159,5 @@ def mirror(parser, args): 'add' : mirror_add, 'remove' : mirror_remove, 'list' : mirror_list } + action[args.mirror_command](args) diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 8905dc7d5f..2cff15845b 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -37,6 +37,8 @@ in order to build it. They need to define the following methods: Restore original state of downloaded code. Used by clean commands. This may just remove the expanded source and re-expand an archive, or it may run something like git reset --hard. + * archive() + Archive a source directory, e.g. for creating a mirror. """ import os import re @@ -91,6 +93,9 @@ class FetchStrategy(object): def __str__(self): # Should be human readable URL. return "FetchStrategy.__str___" + @property + def unique_name(self): pass + # This method is used to match fetch strategies to version() # arguments in packages. @classmethod @@ -189,7 +194,7 @@ class URLFetchStrategy(FetchStrategy): def archive(self, destination): - """This archive""" + """Just moves this archive to the destination.""" if not self.archive_file: raise NoArchiveFileError("Cannot call archive() before fetching.") assert(extension(destination) == extension(self.archive_file)) @@ -231,6 +236,10 @@ class URLFetchStrategy(FetchStrategy): else: return "URLFetchStrategy" + @property + def unique_name(self): + return "spack-fetch-url:%s" % self + class VCSFetchStrategy(FetchStrategy): def __init__(self, name, *rev_types, **kwargs): @@ -384,6 +393,17 @@ class GitFetchStrategy(VCSFetchStrategy): self.git('clean', '-f') + @property + def unique_name(self): + name = "spack-fetch-git:%s" % self.url + if self.commit: + name += "@" + self.commit + elif self.branch: + name += "@" + self.branch + elif self.tag: + name += "@" + self.tag + + class SvnFetchStrategy(VCSFetchStrategy): """Fetch strategy that gets source code from a subversion repository. Use like this in a package: @@ -457,6 +477,14 @@ class SvnFetchStrategy(VCSFetchStrategy): self.svn('revert', '.', '-R') + @property + def unique_name(self): + name = "spack-fetch-svn:%s" % self.url + if self.revision: + name += "@" + self.revision + + + class HgFetchStrategy(VCSFetchStrategy): """Fetch strategy that gets source code from a Mercurial repository. Use like this in a package: @@ -532,6 +560,14 @@ class HgFetchStrategy(VCSFetchStrategy): self.stage.chdir_to_source() + @property + def unique_name(self): + name = "spack-fetch-hg:%s" % self.url + if self.revision: + name += "@" + self.revision + + + def from_url(url): """Given a URL, find an appropriate fetch strategy for it. Currently just gives you a URLFetchStrategy that uses curl. @@ -546,9 +582,18 @@ def args_are_for(args, fetcher): fetcher.matches(args) -def from_args(args, pkg): +def for_package_version(pkg, version): """Determine a fetch strategy based on the arguments supplied to version() in the package description.""" + # If it's not a known version, extrapolate one. + if not version in pkg.versions: + url = pkg.url_for_verison(version) + if not url: + raise InvalidArgsError(pkg, version) + return URLFetchStrategy() + + # Grab a dict of args out of the package version dict + args = pkg.versions[version] # Test all strategies against per-version arguments. for fetcher in all_strategies: @@ -564,9 +609,7 @@ def from_args(args, pkg): if fetcher.matches(attrs): return fetcher(**attrs) - raise InvalidArgsError( - "Could not construct fetch strategy for package %s", - pkg.spec.format("%_%@")) + raise InvalidArgsError(pkg, version) class FetchStrategyError(spack.error.SpackError): @@ -593,5 +636,7 @@ class NoDigestError(FetchStrategyError): class InvalidArgsError(FetchStrategyError): - def __init__(self, msg, long_msg): - super(InvalidArgsError, self).__init__(msg, long_msg) + def __init__(self, pkg, version): + msg = "Could not construct a fetch strategy for package %s at version %s" + msg %= (pkg.name, version) + super(InvalidArgsError, self).__init__(msg) diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py new file mode 100644 index 0000000000..e116ce83b2 --- /dev/null +++ b/lib/spack/spack/mirror.py @@ -0,0 +1,171 @@ +############################################################################## +# 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 +############################################################################## +""" +This file contains code for creating spack mirror directories. A +mirror is an organized hierarchy containing specially named archive +files. This enabled spack to know where to find files in a mirror if +the main server for a particualr package is down. Or, if the computer +where spack is run is not connected to the internet, it allows spack +to download packages directly from a mirror (e.g., on an intranet). +""" +import sys +import os +import llnl.util.tty as tty +from llnl.util.filesystem import * + +import spack +import spack.error +import spack.fetch_strategy as fs +from spack.spec import Spec +from spack.stage import Stage +from spack.version import * +from spack.util.compression import extension + + +def mirror_archive_filename(spec): + """Get the path that this spec will live at within a mirror.""" + if not spec.version.concrete: + raise ValueError("mirror.path requires spec with concrete version.") + + url = spec.package.default_url + if url is None: + ext = 'tar.gz' + else: + ext = extension(url) + + return "%s-%s.%s" % (spec.package.name, spec.version, ext) + + +def get_matching_versions(specs): + """Get a spec for EACH known version matching any spec in the list.""" + matching = [] + for spec in specs: + pkg = spec.package + + # Skip any package that has no known versions. + if not pkg.versions: + tty.msg("No safe (checksummed) versions for package %s." % pkg.name) + continue + + for v in reversed(sorted(pkg.versions)): + if v.satisfies(spec.versions): + s = Spec(pkg.name) + s.versions = VersionList([v]) + matching.append(s) + return matching + + +def create(path, specs, **kwargs): + """Create a directory to be used as a spack mirror, and fill it with + package archives. + + Arguments: + path Path to create a mirror directory hierarchy in. + specs Any package versions matching these specs will be added + to the mirror. + + Return Value: + Returns a tuple of lists: (present, mirrored, error) + * present: Package specs that were already prsent. + * mirrored: Package specs that were successfully mirrored. + * error: Package specs that failed to mirror due to some error. + + This routine iterates through all known package versions, and + it creates specs for those versions. If the version satisfies any spec + in the specs list, it is downloaded and added to the mirror. + """ + # Make sure nothing is in the way. + if os.path.isfile(path): + raise MirrorError("%s already exists and is a file." % path) + + # automatically spec-ify anything in the specs array. + specs = [s if isinstance(s, Spec) else Spec(s) for s in specs] + + # Get concrete specs for each matching version of these specs. + version_specs = get_matching_versions(specs) + for s in version_specs: + s.concretize() + + # Create a directory if none exists + if not os.path.isdir(path): + mkdirp(path) + + # Things to keep track of while parsing specs. + present = [] + mirrored = [] + error = [] + + # Iterate through packages and download all the safe tarballs for each of them + for spec in version_specs: + pkg = spec.package + + stage = None + try: + # create a subdirectory for the current package@version + realpath = os.path.realpath(path) + subdir = join_path(realpath, pkg.name) + mkdirp(subdir) + + archive_file = mirror_archive_filename(spec) + archive_path = join_path(subdir, archive_file) + if os.path.exists(archive_path): + present.append(spec) + continue + + # Set up a stage and a fetcher for the download + fetcher = fs.for_package_version(pkg, pkg.version) + stage = Stage(fetcher, name=fetcher.unique_name) + fetcher.set_stage(stage) + + # Do the fetch and checksum if necessary + fetcher.fetch() + if not kwargs.get('no_checksum', False): + fetcher.check() + tty.msg("Checksum passed for %s@%s" % (pkg.name, pkg.version)) + + # Fetchers have to know how to archive their files. Use + # that to move/copy/create an archive in the mirror. + fetcher.archive(archive_path) + tty.msg("Added %s to mirror" % archive_path) + mirrored.append(spec) + + except Exception, e: + if spack.debug: + sys.excepthook(*sys.exc_info()) + else: + tty.warn("Error while fetching %s." % spec.format('$_$@'), e.message) + error.append(spec) + + finally: + if stage: + stage.destroy() + + return (present, mirrored, error) + + +class MirrorError(spack.error.SpackError): + """Superclass of all mirror-creation related errors.""" + def __init__(self, msg, long_msg=None): + super(MirrorError, self).__init__(msg, long_msg) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index ee3e73a072..34efe1bec9 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -385,8 +385,8 @@ class Package(object): @property def version(self): - if not self.spec.concrete: - raise ValueError("Can only get version of concrete package.") + if not self.spec.versions.concrete: + raise ValueError("Can only get of package with concrete version.") return self.spec.versions[0] @@ -451,18 +451,20 @@ class Package(object): raise ValueError("Can only get a stage for a concrete package.") if self._stage is None: - self._stage = Stage( - self.fetcher, mirror_path=self.mirror_path(), name=self.spec.short_spec) + self._stage = Stage(self.fetcher, + mirror_path=self.mirror_path(), + name=self.spec.short_spec) return self._stage @property def fetcher(self): - if not self.spec.concrete: - raise ValueError("Can only get a fetcher for a concrete package.") + if not self.spec.versions.concrete: + raise ValueError( + "Can only get a fetcher for a package with concrete versions.") if not self._fetcher: - self._fetcher = fs.from_args(self.versions[self.version], self) + self._fetcher = fs.for_package_version(self, self.version) return self._fetcher @@ -598,13 +600,14 @@ class Package(object): @property def default_url(self): - if self.spec.version.concrete: + if self.spec.versions.concrete: return self.url_for_version(self.version) else: url = getattr(self, 'url', None) if url: return url + return None def remove_prefix(self): -- cgit v1.2.3-70-g09d2 From 8e3c2d8a26ea1515479e369c2fe9594ac8ed8ed1 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 15 Oct 2014 07:40:01 -0700 Subject: Refactor fetch tests to use common mock repo module. --- lib/spack/spack/test/git_fetch.py | 90 ++++++----------------- lib/spack/spack/test/hg_fetch.py | 56 +++----------- lib/spack/spack/test/mock_repo.py | 151 ++++++++++++++++++++++++++++++++++++++ lib/spack/spack/test/svn_fetch.py | 49 +++---------- 4 files changed, 198 insertions(+), 148 deletions(-) create mode 100644 lib/spack/spack/test/mock_repo.py diff --git a/lib/spack/spack/test/git_fetch.py b/lib/spack/spack/test/git_fetch.py index c7c11621f9..f6d9bfcf05 100644 --- a/lib/spack/spack/test/git_fetch.py +++ b/lib/spack/spack/test/git_fetch.py @@ -34,24 +34,9 @@ import spack from spack.version import ver from spack.stage import Stage from spack.util.executable import which -from spack.test.mock_packages_test import * - -test_repo_path = 'test-repo' -test_file_name = 'test-file.txt' - -test_branch = 'test-branch' -test_branch_file_name = 'branch-test-file' - -test_tag_branch = 'test-tag-branch' -test_tag = 'test-tag' -test_tag_file_name = 'tag-test-file' -untracked = 'foobarbaz' - -git = which('git', required=True) - -def rev_hash(rev): - return git('rev-parse', rev, return_output=True).strip() +from spack.test.mock_packages_test import * +from spack.test.mock_repo import MockGitRepo class GitFetchTest(MockPackagesTest): @@ -61,36 +46,8 @@ class GitFetchTest(MockPackagesTest): """Create a git repository with master and two other branches, and one tag, so that we can experiment on it.""" super(GitFetchTest, self).setUp() - self.stage = Stage('fetch-test') - - self.repo_path = join_path(self.stage.path, test_repo_path) - mkdirp(self.repo_path) - - self.test_file = join_path(self.repo_path, test_file_name) - touch(self.test_file) - - with working_dir(self.repo_path): - git('init') - git('add', self.test_file) - git('commit', '-m', 'testing') - - git('branch', test_branch) - git('branch', test_tag_branch) - - git('checkout', test_branch) - touch(test_branch_file_name) - git('add', test_branch_file_name) - git('commit', '-m' 'branch test') - - git('checkout', test_tag_branch) - touch(test_tag_file_name) - git('add', test_tag_file_name) - git('commit', '-m' 'tag test') - git('tag', test_tag) - - git('checkout', 'master') - self.commit = rev_hash(test_tag) + self.repo = MockGitRepo() spec = Spec('git-test') spec.concretize() @@ -101,15 +58,15 @@ class GitFetchTest(MockPackagesTest): """Destroy the stage space used by this test.""" super(GitFetchTest, self).tearDown() - if self.stage is not None: - self.stage.destroy() + if self.repo.stage is not None: + self.repo.stage.destroy() self.pkg.do_clean_dist() def assert_rev(self, rev): """Check that the current git revision is equal to the supplied rev.""" - self.assertEqual(rev_hash('HEAD'), rev_hash(rev)) + self.assertEqual(self.repo.rev_hash('HEAD'), self.repo.rev_hash(rev)) def try_fetch(self, rev, test_file, args): @@ -133,10 +90,11 @@ class GitFetchTest(MockPackagesTest): os.unlink(file_path) self.assertFalse(os.path.isfile(file_path)) - touch(untracked) - self.assertTrue(os.path.isfile(untracked)) + untracked_file = 'foobarbaz' + touch(untracked_file) + self.assertTrue(os.path.isfile(untracked_file)) self.pkg.do_clean_work() - self.assertFalse(os.path.isfile(untracked)) + self.assertFalse(os.path.isfile(untracked_file)) self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) self.assertTrue(os.path.isfile(file_path)) @@ -146,30 +104,30 @@ class GitFetchTest(MockPackagesTest): def test_fetch_master(self): """Test a default git checkout with no commit or tag specified.""" - self.try_fetch('master', test_file_name, { - 'git' : self.repo_path + self.try_fetch('master', self.repo.r0_file, { + 'git' : self.repo.path }) - def test_fetch_branch(self): + def ztest_fetch_branch(self): """Test fetching a branch.""" - self.try_fetch(test_branch, test_branch_file_name, { - 'git' : self.repo_path, - 'branch' : test_branch + self.try_fetch(self.repo.branch, self.repo.branch_file, { + 'git' : self.repo.path, + 'branch' : self.repo.branch }) - def test_fetch_tag(self): + def ztest_fetch_tag(self): """Test fetching a tag.""" - self.try_fetch(test_tag, test_tag_file_name, { - 'git' : self.repo_path, - 'tag' : test_tag + self.try_fetch(self.repo.tag, self.repo.tag_file, { + 'git' : self.repo.path, + 'tag' : self.repo.tag }) - def test_fetch_commit(self): + def ztest_fetch_commit(self): """Test fetching a particular commit.""" - self.try_fetch(self.commit, test_tag_file_name, { - 'git' : self.repo_path, - 'commit' : self.commit + self.try_fetch(self.repo.r1, self.repo.r1_file, { + 'git' : self.repo.path, + 'commit' : self.repo.r1 }) diff --git a/lib/spack/spack/test/hg_fetch.py b/lib/spack/spack/test/hg_fetch.py index 4b9a2f8bc9..97c5b665e7 100644 --- a/lib/spack/spack/test/hg_fetch.py +++ b/lib/spack/spack/test/hg_fetch.py @@ -35,46 +35,18 @@ from spack.version import ver from spack.stage import Stage from spack.util.executable import which from spack.test.mock_packages_test import * +from spack.test.mock_repo import MockHgRepo -test_repo_path = 'test-repo' -test_file_name = 'test-file.txt' -test_rev1_file_name = 'test-file2.txt' -untracked = 'foobarbaz' - -hg = which('hg', required=True) class HgFetchTest(MockPackagesTest): """Tests fetching from a dummy hg repository.""" - def get_rev(self): - """Get current mercurial revision.""" - return hg('id', '-i', return_output=True).strip() - - def setUp(self): """Create a hg repository with master and two other branches, and one tag, so that we can experiment on it.""" super(HgFetchTest, self).setUp() - self.stage = Stage('fetch-test') - - self.repo_path = join_path(self.stage.path, test_repo_path) - mkdirp(self.repo_path) - - test_file = join_path(self.repo_path, test_file_name) - test_file_rev1 = join_path(self.repo_path, test_rev1_file_name) - with working_dir(self.repo_path): - hg('init') - - touch(test_file) - hg('add', test_file) - hg('commit', '-m', 'revision 0', '-u', 'test') - self.rev0 = self.get_rev() - - touch(test_file_rev1) - hg('add', test_file_rev1) - hg('commit', '-m' 'revision 1', '-u', 'test') - self.rev1 = self.get_rev() + self.repo = MockHgRepo() spec = Spec('hg-test') spec.concretize() @@ -85,17 +57,12 @@ class HgFetchTest(MockPackagesTest): """Destroy the stage space used by this test.""" super(HgFetchTest, self).tearDown() - if self.stage is not None: - self.stage.destroy() + if self.repo.stage is not None: + self.repo.stage.destroy() self.pkg.do_clean_dist() - def assert_rev(self, rev): - """Check that the current hg revision is equal to the supplied rev.""" - self.assertEqual(self.get_rev(), rev) - - def try_fetch(self, rev, test_file, args): """Tries to: 1. Fetch the repo using a fetch strategy constructed with @@ -108,7 +75,7 @@ class HgFetchTest(MockPackagesTest): self.pkg.versions[ver('hg')] = args self.pkg.do_stage() - self.assert_rev(rev) + self.assertEqual(self.repo.get_rev(), rev) file_path = join_path(self.pkg.stage.source_path, test_file) self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) @@ -117,6 +84,7 @@ class HgFetchTest(MockPackagesTest): os.unlink(file_path) self.assertFalse(os.path.isfile(file_path)) + untracked = 'foobarbaz' touch(untracked) self.assertTrue(os.path.isfile(untracked)) self.pkg.do_clean_work() @@ -125,19 +93,19 @@ class HgFetchTest(MockPackagesTest): self.assertTrue(os.path.isdir(self.pkg.stage.source_path)) self.assertTrue(os.path.isfile(file_path)) - self.assert_rev(rev) + self.assertEqual(self.repo.get_rev(), rev) def test_fetch_default(self): """Test a default hg checkout with no commit or tag specified.""" - self.try_fetch(self.rev1, test_rev1_file_name, { - 'hg' : self.repo_path + self.try_fetch(self.repo.r1, self.repo.r1_file, { + 'hg' : self.repo.path }) def test_fetch_rev0(self): """Test fetching a branch.""" - self.try_fetch(self.rev0, test_file_name, { - 'hg' : self.repo_path, - 'revision' : self.rev0 + self.try_fetch(self.repo.r0, self.repo.r0_file, { + 'hg' : self.repo.path, + 'revision' : self.repo.r0 }) diff --git a/lib/spack/spack/test/mock_repo.py b/lib/spack/spack/test/mock_repo.py new file mode 100644 index 0000000000..ae28f7224e --- /dev/null +++ b/lib/spack/spack/test/mock_repo.py @@ -0,0 +1,151 @@ +############################################################################## +# 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 +############################################################################## +import shutil + +from llnl.util.filesystem import * + +import spack +from spack.version import ver +from spack.stage import Stage +from spack.util.executable import which + + +class MockRepo(object): + def __init__(self, stage_name, repo_name): + """This creates a stage and a repo directory within the stage.""" + # Stage where this repo has been created + self.stage = Stage(stage_name) + + # Full path to the repo within the stage. + self.path = join_path(self.stage.path, 'mock-git-repo') + mkdirp(self.path) + + # Name for rev0 & rev1 files in the repo to be + self.r0_file = 'r0_file' + self.r1_file = 'r1_file' + + +# +# VCS Systems used by mock repo code. +# +git = which('git', required=True) +svn = which('svn', required=True) +svnadmin = which('svnadmin', required=True) +hg = which('hg', required=True) + + +class MockGitRepo(MockRepo): + def __init__(self): + super(MockGitRepo, self).__init__('mock-git-stage', 'mock-git-repo') + + with working_dir(self.path): + git('init') + + # r0 is just the first commit + touch(self.r0_file) + git('add', self.r0_file) + git('commit', '-m', 'mock-git-repo r0') + + self.branch = 'test-branch' + self.branch_file = 'branch_file' + git('branch', self.branch) + + self.tag_branch = 'tag-branch' + self.tag_file = 'tag_file' + git('branch', self.tag_branch) + + # Check out first branch + git('checkout', self.branch) + touch(self.branch_file) + git('add', self.branch_file) + git('commit', '-m' 'r1 test branch') + + # Check out a second branch and tag it + git('checkout', self.tag_branch) + touch(self.tag_file) + git('add', self.tag_file) + git('commit', '-m' 'tag test branch') + + self.tag = 'test-tag' + git('tag', self.tag) + + git('checkout', 'master') + + # R1 test is the same as test for branch + self.r1 = self.rev_hash(self.branch) + self.r1_file = self.branch_file + + def rev_hash(self, rev): + return git('rev-parse', rev, return_output=True).strip() + + +class MockSvnRepo(MockRepo): + def __init__(self): + super(MockSvnRepo, self).__init__('mock-svn-stage', 'mock-svn-repo') + + with working_dir(self.stage.path): + svnadmin('create', self.path) + self.url = 'file://' + self.path + + tmp_path = join_path(self.stage.path, 'tmp-path') + mkdirp(tmp_path) + with working_dir(tmp_path): + touch(self.r0_file) + + svn('import', tmp_path, self.url, '-m', 'Initial import r0') + + shutil.rmtree(tmp_path) + svn('checkout', self.url, tmp_path) + with working_dir(tmp_path): + touch(self.r1_file) + svn('add', self.r1_file) + svn('ci', '-m', 'second revision r1') + + shutil.rmtree(tmp_path) + + self.r0 = '1' + self.r1 = '2' + + +class MockHgRepo(MockRepo): + def __init__(self): + super(MockHgRepo, self).__init__('mock-hg-stage', 'mock-hg-repo') + + with working_dir(self.path): + hg('init') + + touch(self.r0_file) + hg('add', self.r0_file) + hg('commit', '-m', 'revision 0', '-u', 'test') + self.r0 = self.get_rev() + + touch(self.r1_file) + hg('add', self.r1_file) + hg('commit', '-m' 'revision 1', '-u', 'test') + self.r1 = self.get_rev() + + def get_rev(self): + """Get current mercurial revision.""" + return hg('id', '-i', return_output=True).strip() diff --git a/lib/spack/spack/test/svn_fetch.py b/lib/spack/spack/test/svn_fetch.py index e253f21921..a48a86dcc3 100644 --- a/lib/spack/spack/test/svn_fetch.py +++ b/lib/spack/spack/test/svn_fetch.py @@ -36,17 +36,7 @@ from spack.version import ver from spack.stage import Stage from spack.util.executable import which from spack.test.mock_packages_test import * - -test_repo_path = 'test-repo' - -test_import_path = 'test-import' -test_file_name = 'test-file.txt' -test_rev_file_name = 'test-rev-file' - -untracked = 'foobarbaz' - -svn = which('svn', required=True) -svnadmin = which('svnadmin', required=True) +from spack.test.mock_repo import svn, MockSvnRepo class SvnFetchTest(MockPackagesTest): @@ -55,26 +45,8 @@ class SvnFetchTest(MockPackagesTest): def setUp(self): """Create an svn repository with two revisions.""" super(SvnFetchTest, self).setUp() - self.stage = Stage('fetch-test') - self.stage.chdir() - - repo_path = join_path(self.stage.path, test_repo_path) - svnadmin('create', repo_path) - self.repo_url = 'file://' + repo_path - - self.import_path = join_path(self.stage.path, test_import_path) - mkdirp(self.import_path) - with working_dir(self.import_path): - touch(test_file_name) - - svn('import', self.import_path, self.repo_url, '-m', 'Initial import') - shutil.rmtree(self.import_path) - svn('checkout', self.repo_url, self.import_path) - with working_dir(self.import_path): - touch(test_rev_file_name) - svn('add', test_rev_file_name) - svn('ci', '-m', 'second revision') + self.repo = MockSvnRepo() spec = Spec('svn-test') spec.concretize() @@ -85,8 +57,8 @@ class SvnFetchTest(MockPackagesTest): """Destroy the stage space used by this test.""" super(SvnFetchTest, self).tearDown() - if self.stage is not None: - self.stage.destroy() + if self.repo.stage is not None: + self.repo.stage.destroy() self.pkg.do_clean_dist() @@ -99,7 +71,7 @@ class SvnFetchTest(MockPackagesTest): for line in output.split('\n'): match = re.match(r'Revision: (\d+)', line) if match: - return int(match.group(1)) + return match.group(1) self.assertEqual(get_rev(), rev) @@ -124,6 +96,7 @@ class SvnFetchTest(MockPackagesTest): os.unlink(file_path) self.assertFalse(os.path.isfile(file_path)) + untracked = 'foobarbaz' touch(untracked) self.assertTrue(os.path.isfile(untracked)) self.pkg.do_clean_work() @@ -137,14 +110,14 @@ class SvnFetchTest(MockPackagesTest): def test_fetch_default(self): """Test a default checkout and make sure it's on rev 1""" - self.try_fetch(2, test_rev_file_name, { - 'svn' : self.repo_url + self.try_fetch(self.repo.r1, self.repo.r1_file, { + 'svn' : self.repo.url }) def test_fetch_r1(self): """Test fetching an older revision (0).""" - self.try_fetch(1, test_file_name, { - 'svn' : self.repo_url, - 'revision' : 1 + self.try_fetch(self.repo.r0, self.repo.r0_file, { + 'svn' : self.repo.url, + 'revision' : self.repo.r0 }) -- cgit v1.2.3-70-g09d2 From 6fdfd83e6b0f776bf79d9de0af82bcfc311072f9 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 15 Oct 2014 21:07:41 -0400 Subject: Add test cases for mirroring. --- bin/spack | 2 +- lib/spack/spack/cmd/mirror.py | 20 +++-- lib/spack/spack/concretize.py | 1 - lib/spack/spack/fetch_strategy.py | 39 +--------- lib/spack/spack/mirror.py | 48 ++++++++---- lib/spack/spack/package.py | 12 --- lib/spack/spack/test/__init__.py | 3 +- lib/spack/spack/test/install.py | 37 ++------- lib/spack/spack/test/mirror.py | 156 ++++++++++++++++++++++++++++++++++++++ lib/spack/spack/test/mock_repo.py | 76 +++++++++++++++---- 10 files changed, 277 insertions(+), 117 deletions(-) create mode 100644 lib/spack/spack/test/mirror.py diff --git a/bin/spack b/bin/spack index 2f74761a78..75874ca39e 100755 --- a/bin/spack +++ b/bin/spack @@ -96,7 +96,7 @@ if args.mock: # If the user asked for it, don't check ssl certs. if args.insecure: - tty.warn("You asked for --insecure, which does not check SSL certificates.") + tty.warn("You asked for --insecure, which does not check SSL certificates or checksums.") spack.curl.add_default_arg('-k') # Try to load the particular command asked for and run it diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index 6a6c2b60c7..6e2e4dfb24 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -54,6 +54,9 @@ def setup_parser(subparser): 'specs', nargs=argparse.REMAINDER, help="Specs of packages to put in mirror") create_parser.add_argument( '-f', '--file', help="File with specs of packages to put in mirror.") + create_parser.add_argument( + '-o', '--one-version-per-spec', action='store_const', const=1, default=0, + help="Only fetch one 'preferred' version per spec, not all known versions.") add_parser = sp.add_parser('add', help=mirror_add.__doc__) add_parser.add_argument('name', help="Mnemonic name for mirror.") @@ -128,26 +131,29 @@ def mirror_create(args): # If nothing is passed, use all packages. if not specs: specs = [Spec(n) for n in spack.db.all_package_names()] + specs.sort(key=lambda s: s.format("$_$@").lower()) # Default name for directory is spack-mirror- - if not args.directory: + directory = args.directory + if not directory: timestamp = datetime.now().strftime("%Y-%m-%d") - args.directory = 'spack-mirror-' + timestamp + directory = 'spack-mirror-' + timestamp # Make sure nothing is in the way. existed = False - if os.path.isfile(args.directory): - tty.error("%s already exists and is a file." % args.directory) - elif os.path.isdir(args.directory): + if os.path.isfile(directory): + tty.error("%s already exists and is a file." % directory) + elif os.path.isdir(directory): existed = True # Actually do the work to create the mirror - present, mirrored, error = spack.mirror.create(args.directory, specs) + present, mirrored, error = spack.mirror.create( + directory, specs, num_versions=args.one_version_per_spec) p, m, e = len(present), len(mirrored), len(error) verb = "updated" if existed else "created" tty.msg( - "Successfully %s mirror in %s." % (verb, args.directory), + "Successfully %s mirror in %s." % (verb, directory), "Archive stats:", " %-4d already present" % p, " %-4d added" % m, diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py index 9f9cd1789d..e603806af9 100644 --- a/lib/spack/spack/concretize.py +++ b/lib/spack/spack/concretize.py @@ -73,7 +73,6 @@ class DefaultConcretizer(object): if valid_versions: spec.versions = ver([valid_versions[-1]]) else: - print spec raise NoValidVersionError(spec) diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 2cff15845b..2b574eaba7 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -93,9 +93,6 @@ class FetchStrategy(object): def __str__(self): # Should be human readable URL. return "FetchStrategy.__str___" - @property - def unique_name(self): pass - # This method is used to match fetch strategies to version() # arguments in packages. @classmethod @@ -197,7 +194,10 @@ class URLFetchStrategy(FetchStrategy): """Just moves this archive to the destination.""" if not self.archive_file: raise NoArchiveFileError("Cannot call archive() before fetching.") - assert(extension(destination) == extension(self.archive_file)) + + if not extension(destination) == extension(self.archive_file): + raise ValueError("Cannot archive without matching extensions.") + shutil.move(self.archive_file, destination) @@ -236,10 +236,6 @@ class URLFetchStrategy(FetchStrategy): else: return "URLFetchStrategy" - @property - def unique_name(self): - return "spack-fetch-url:%s" % self - class VCSFetchStrategy(FetchStrategy): def __init__(self, name, *rev_types, **kwargs): @@ -393,17 +389,6 @@ class GitFetchStrategy(VCSFetchStrategy): self.git('clean', '-f') - @property - def unique_name(self): - name = "spack-fetch-git:%s" % self.url - if self.commit: - name += "@" + self.commit - elif self.branch: - name += "@" + self.branch - elif self.tag: - name += "@" + self.tag - - class SvnFetchStrategy(VCSFetchStrategy): """Fetch strategy that gets source code from a subversion repository. Use like this in a package: @@ -477,14 +462,6 @@ class SvnFetchStrategy(VCSFetchStrategy): self.svn('revert', '.', '-R') - @property - def unique_name(self): - name = "spack-fetch-svn:%s" % self.url - if self.revision: - name += "@" + self.revision - - - class HgFetchStrategy(VCSFetchStrategy): """Fetch strategy that gets source code from a Mercurial repository. Use like this in a package: @@ -560,14 +537,6 @@ class HgFetchStrategy(VCSFetchStrategy): self.stage.chdir_to_source() - @property - def unique_name(self): - name = "spack-fetch-hg:%s" % self.url - if self.revision: - name += "@" + self.revision - - - def from_url(url): """Given a URL, find an appropriate fetch strategy for it. Currently just gives you a URLFetchStrategy that uses curl. diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py index e116ce83b2..f7bbb3f840 100644 --- a/lib/spack/spack/mirror.py +++ b/lib/spack/spack/mirror.py @@ -49,16 +49,18 @@ def mirror_archive_filename(spec): if not spec.version.concrete: raise ValueError("mirror.path requires spec with concrete version.") - url = spec.package.default_url - if url is None: - ext = 'tar.gz' + fetcher = spec.package.fetcher + if isinstance(fetcher, fs.URLFetchStrategy): + # If we fetch this version with a URLFetchStrategy, use URL's archive type + ext = extension(fetcher.url) else: - ext = extension(url) + # Otherwise we'll make a .tar.gz ourselves + ext = 'tar.gz' return "%s-%s.%s" % (spec.package.name, spec.version, ext) -def get_matching_versions(specs): +def get_matching_versions(specs, **kwargs): """Get a spec for EACH known version matching any spec in the list.""" matching = [] for spec in specs: @@ -69,11 +71,18 @@ def get_matching_versions(specs): tty.msg("No safe (checksummed) versions for package %s." % pkg.name) continue - for v in reversed(sorted(pkg.versions)): + num_versions = kwargs.get('num_versions', 0) + for i, v in enumerate(reversed(sorted(pkg.versions))): + # Generate no more than num_versions versions for each spec. + if num_versions and i >= num_versions: + break + + # Generate only versions that satisfy the spec. if v.satisfies(spec.versions): s = Spec(pkg.name) s.versions = VersionList([v]) matching.append(s) + return matching @@ -86,6 +95,11 @@ def create(path, specs, **kwargs): specs Any package versions matching these specs will be added to the mirror. + Keyword args: + no_checksum: If True, do not checkpoint when fetching (default False) + num_versions: Max number of versions to fetch per spec, + if spec is ambiguous (default is 0 for all of them) + Return Value: Returns a tuple of lists: (present, mirrored, error) * present: Package specs that were already prsent. @@ -104,13 +118,15 @@ def create(path, specs, **kwargs): specs = [s if isinstance(s, Spec) else Spec(s) for s in specs] # Get concrete specs for each matching version of these specs. - version_specs = get_matching_versions(specs) + version_specs = get_matching_versions( + specs, num_versions=kwargs.get('num_versions', 0)) for s in version_specs: s.concretize() - # Create a directory if none exists - if not os.path.isdir(path): - mkdirp(path) + # Get the absolute path of the root before we start jumping around. + mirror_root = os.path.abspath(path) + if not os.path.isdir(mirror_root): + mkdirp(mirror_root) # Things to keep track of while parsing specs. present = [] @@ -124,19 +140,21 @@ def create(path, specs, **kwargs): stage = None try: # create a subdirectory for the current package@version - realpath = os.path.realpath(path) - subdir = join_path(realpath, pkg.name) + subdir = join_path(mirror_root, pkg.name) mkdirp(subdir) archive_file = mirror_archive_filename(spec) archive_path = join_path(subdir, archive_file) - if os.path.exists(archive_path): + + if os.path.exists(archive_file): + tty.msg("%s is already present. Skipping." % spec.format("$_$@")) present.append(spec) continue # Set up a stage and a fetcher for the download + unique_fetch_name = spec.format("$_$@") fetcher = fs.for_package_version(pkg, pkg.version) - stage = Stage(fetcher, name=fetcher.unique_name) + stage = Stage(fetcher, name=unique_fetch_name) fetcher.set_stage(stage) # Do the fetch and checksum if necessary @@ -148,7 +166,7 @@ def create(path, specs, **kwargs): # Fetchers have to know how to archive their files. Use # that to move/copy/create an archive in the mirror. fetcher.archive(archive_path) - tty.msg("Added %s to mirror" % archive_path) + tty.msg("Added %s." % spec.format("$_$@")) mirrored.append(spec) except Exception, e: diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 34efe1bec9..e462562e85 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -598,18 +598,6 @@ class Package(object): return str(version) - @property - def default_url(self): - if self.spec.versions.concrete: - return self.url_for_version(self.version) - else: - url = getattr(self, 'url', None) - if url: - return url - - return None - - def remove_prefix(self): """Removes the prefix for a package along with any empty parent directories.""" spack.install_layout.remove_path_for_spec(self.spec) diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index ca4c869e42..be9ac5a560 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -50,7 +50,8 @@ test_names = ['versions', 'python_version', 'git_fetch', 'svn_fetch', - 'hg_fetch'] + 'hg_fetch', + 'mirror'] def list_tests(): diff --git a/lib/spack/spack/test/install.py b/lib/spack/spack/test/install.py index 0d53bb45c7..e052f53e77 100644 --- a/lib/spack/spack/test/install.py +++ b/lib/spack/spack/test/install.py @@ -36,39 +36,17 @@ from spack.fetch_strategy import URLFetchStrategy from spack.directory_layout import SpecHashDirectoryLayout from spack.util.executable import which from spack.test.mock_packages_test import * +from spack.test.mock_repo import MockArchive -dir_name = 'trivial-1.0' -archive_name = 'trivial-1.0.tar.gz' -install_test_package = 'trivial_install_test_package' - class InstallTest(MockPackagesTest): """Tests install and uninstall on a trivial package.""" def setUp(self): super(InstallTest, self).setUp() - self.stage = Stage('not_a_real_url') - archive_dir = join_path(self.stage.path, dir_name) - dummy_configure = join_path(archive_dir, 'configure') - - mkdirp(archive_dir) - with closing(open(dummy_configure, 'w')) as configure: - configure.write( - "#!/bin/sh\n" - "prefix=$(echo $1 | sed 's/--prefix=//')\n" - "cat > Makefile < Makefile < Date: Thu, 16 Oct 2014 06:56:00 -0700 Subject: Bug fixes for URLs and mirror fetching. --- lib/spack/spack/cmd/mirror.py | 9 ++++++++- lib/spack/spack/concretize.py | 1 + lib/spack/spack/fetch_strategy.py | 24 +++++++++++++++++------- lib/spack/spack/mirror.py | 2 +- lib/spack/spack/stage.py | 23 ++++++++++------------- var/spack/packages/libmonitor/package.py | 3 +-- var/spack/packages/paraver/package.py | 4 ++-- var/spack/packages/stat/package.py | 2 +- 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index 6e2e4dfb24..22838e1344 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -71,8 +71,12 @@ def setup_parser(subparser): def mirror_add(args): """Add a mirror to Spack.""" + url = args.url + if url.startswith('/'): + url = 'file://' + url + config = spack.config.get_config('user') - config.set_value('mirror', args.name, 'url', args.url) + config.set_value('mirror', args.name, 'url', url) config.write() @@ -158,6 +162,9 @@ def mirror_create(args): " %-4d already present" % p, " %-4d added" % m, " %-4d failed to fetch." % e) + if error: + tty.error("Failed downloads:") + colify(s.format("$_$@") for s in error) def mirror(parser, args): diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py index e603806af9..eee8cb7fde 100644 --- a/lib/spack/spack/concretize.py +++ b/lib/spack/spack/concretize.py @@ -70,6 +70,7 @@ class DefaultConcretizer(object): pkg = spec.package valid_versions = [v for v in pkg.available_versions if any(v.satisfies(sv) for sv in spec.versions)] + if valid_versions: spec.versions = ver([valid_versions[-1]]) else: diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 2b574eaba7..5a508b130c 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -559,7 +559,7 @@ def for_package_version(pkg, version): url = pkg.url_for_verison(version) if not url: raise InvalidArgsError(pkg, version) - return URLFetchStrategy() + return URLFetchStrategy(url) # Grab a dict of args out of the package version dict args = pkg.versions[version] @@ -574,6 +574,8 @@ def for_package_version(pkg, version): for fetcher in all_strategies: attrs = dict((attr, getattr(pkg, attr, None)) for attr in fetcher.required_attributes) + if 'url' in attrs: + attrs['url'] = pkg.url_for_version(version) attrs.update(args) if fetcher.matches(attrs): return fetcher(**attrs) @@ -581,12 +583,12 @@ def for_package_version(pkg, version): raise InvalidArgsError(pkg, version) -class FetchStrategyError(spack.error.SpackError): +class FetchError(spack.error.SpackError): def __init__(self, msg, long_msg): - super(FetchStrategyError, self).__init__(msg, long_msg) + super(FetchError, self).__init__(msg, long_msg) -class FailedDownloadError(FetchStrategyError): +class FailedDownloadError(FetchError): """Raised wen a download fails.""" def __init__(self, url, msg=""): super(FailedDownloadError, self).__init__( @@ -594,18 +596,26 @@ class FailedDownloadError(FetchStrategyError): self.url = url -class NoArchiveFileError(FetchStrategyError): +class NoArchiveFileError(FetchError): def __init__(self, msg, long_msg): super(NoArchiveFileError, self).__init__(msg, long_msg) -class NoDigestError(FetchStrategyError): +class NoDigestError(FetchError): def __init__(self, msg, long_msg): super(NoDigestError, self).__init__(msg, long_msg) -class InvalidArgsError(FetchStrategyError): +class InvalidArgsError(FetchError): def __init__(self, pkg, version): msg = "Could not construct a fetch strategy for package %s at version %s" msg %= (pkg.name, version) super(InvalidArgsError, self).__init__(msg) + + +class ChecksumError(FetchError): + """Raised when archive fails to checksum.""" + def __init__(self, message, long_msg=None): + super(ChecksumError, self).__init__(message, long_msg) + + diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py index f7bbb3f840..2f822b13ab 100644 --- a/lib/spack/spack/mirror.py +++ b/lib/spack/spack/mirror.py @@ -146,7 +146,7 @@ def create(path, specs, **kwargs): archive_file = mirror_archive_filename(spec) archive_path = join_path(subdir, archive_file) - if os.path.exists(archive_file): + if os.path.exists(archive_path): tty.msg("%s is already present. Skipping." % spec.format("$_$@")) present.append(spec) continue diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 0d684df92d..b371761785 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -32,7 +32,7 @@ from llnl.util.filesystem import * import spack import spack.config -import spack.fetch_strategy as fetch_strategy +import spack.fetch_strategy as fs import spack.error @@ -83,8 +83,8 @@ class Stage(object): stage will be given a unique name automatically. """ if isinstance(url_or_fetch_strategy, basestring): - self.fetcher = fetch_strategy.from_url(url_or_fetch_strategy) - elif isinstance(url_or_fetch_strategy, fetch_strategy.FetchStrategy): + self.fetcher = fs.from_url(url_or_fetch_strategy) + elif isinstance(url_or_fetch_strategy, fs.FetchStrategy): self.fetcher = url_or_fetch_strategy else: raise ValueError("Can't construct Stage without url or fetch strategy") @@ -198,7 +198,10 @@ class Stage(object): @property def archive_file(self): """Path to the source archive within this stage directory.""" - paths = [os.path.join(self.path, os.path.basename(self.url))] + if not isinstance(self.fetcher, fs.URLFetchStrategy): + return None + + paths = [os.path.join(self.path, os.path.basename(self.fetcher.url))] if self.mirror_path: paths.append(os.path.join(self.path, os.path.basename(self.mirror_path))) @@ -242,9 +245,9 @@ class Stage(object): urls = ["%s/%s" % (m, self.mirror_path) for m in _get_mirrors()] digest = None - if isinstance(self.fetcher, fetch_strategy.URLFetchStrategy): + if isinstance(self.fetcher, fs.URLFetchStrategy): digest = self.fetcher.digest - fetchers = [fetch_strategy.URLFetchStrategy(url, digest) + fetchers = [fs.URLFetchStrategy(url, digest) for url in urls] + fetchers for f in fetchers: f.set_stage(self) @@ -365,12 +368,6 @@ class StageError(spack.error.SpackError): super(self, StageError).__init__(message, long_message) -class ChecksumError(StageError): - """Raised when archive fails to checksum.""" - def __init__(self, message, long_msg=None): - super(ChecksumError, self).__init__(message, long_msg) - - class RestageError(StageError): def __init__(self, message, long_msg=None): super(RestageError, self).__init__(message, long_msg) @@ -382,4 +379,4 @@ class ChdirError(StageError): # Keep this in namespace for convenience -FailedDownloadError = spack.fetch_strategy.FailedDownloadError +FailedDownloadError = fs.FailedDownloadError diff --git a/var/spack/packages/libmonitor/package.py b/var/spack/packages/libmonitor/package.py index 210712436a..ed619e4cce 100644 --- a/var/spack/packages/libmonitor/package.py +++ b/var/spack/packages/libmonitor/package.py @@ -27,9 +27,8 @@ from spack import * class Libmonitor(Package): """Libmonitor is a library for process and thread control.""" homepage = "http://hpctoolkit.org" - url = "file:///g/g0/legendre/tools/oss/openspeedshop-release-2.1/SOURCES/libmonitor-20130218.tar.gz" - version('20130218', 'aa85c2c580e2dafb823cc47b09374279') + version('20130218', svn='https://outreach.scidac.gov/svn/libmonitor/trunk', revision=146) def install(self, spec, prefix): configure("--prefix=" + prefix) diff --git a/var/spack/packages/paraver/package.py b/var/spack/packages/paraver/package.py index 45bac95b28..5f8a153d4c 100644 --- a/var/spack/packages/paraver/package.py +++ b/var/spack/packages/paraver/package.py @@ -7,9 +7,9 @@ class Paraver(Package): is expressed on its input trace format. Traces for parallel MPI, OpenMP and other programs can be genereated with Extrae.""" homepage = "http://www.bsc.es/computer-sciences/performance-tools/paraver" - url = "http://www.bsc.es/ssl/apps/performanceTools/files/paraver-sources-4.5.2.tar.gz" + url = "http://www.bsc.es/ssl/apps/performanceTools/files/paraver-sources-4.5.3.tar.gz" - version('4.5.2', 'ea463dd494519395c99ebae294edee17') + version('4.5.3', '625de9ec0d639acd18d1aaa644b38f72') depends_on("boost") #depends_on("extrae") diff --git a/var/spack/packages/stat/package.py b/var/spack/packages/stat/package.py index 956b0dcc8c..fbd1418d41 100644 --- a/var/spack/packages/stat/package.py +++ b/var/spack/packages/stat/package.py @@ -5,8 +5,8 @@ class Stat(Package): homepage = "http://paradyn.org/STAT/STAT.html" url = "https://github.com/lee218llnl/stat/archive/v2.0.0.tar.gz" - version('2.0.0', 'c7494210b0ba26b577171b92838e1a9b') version('2.1.0', 'ece26beaf057aa9134d62adcdda1ba91') + version('2.0.0', 'c7494210b0ba26b577171b92838e1a9b') depends_on('libdwarf') depends_on('dyninst') -- cgit v1.2.3-70-g09d2 From 0c4b8d45df8225624c2778e7d97f1e5017f21df5 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 16 Oct 2014 08:50:31 -0700 Subject: Consolidate archive_file() implementation into Stage. --- lib/spack/spack/fetch_strategy.py | 55 ++++++++++++++++++++++++--------------- lib/spack/spack/mirror.py | 2 +- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 5a508b130c..f79051c500 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -43,7 +43,7 @@ in order to build it. They need to define the following methods: import os import re import shutil - +from functools import wraps import llnl.util.tty as tty import spack @@ -57,6 +57,16 @@ from spack.util.compression import decompressor_for, extension """List of all fetch strategies, created by FetchStrategy metaclass.""" all_strategies = [] +def _needs_stage(fun): + """Many methods on fetch strategies require a stage to be set + using set_stage(). This decorator adds a check for self.stage.""" + @wraps(fun) + def wrapper(self, *args, **kwargs): + if not self.stage: + raise NoStageError(fun) + return fun(self, *args, **kwargs) + return wrapper + class FetchStrategy(object): """Superclass of all fetch strategies.""" @@ -121,10 +131,8 @@ class URLFetchStrategy(FetchStrategy): if not self.url: raise ValueError("URLFetchStrategy requires a url for fetching.") - + @_needs_stage def fetch(self): - assert(self.stage) - self.stage.chdir() if self.archive_file: @@ -172,13 +180,10 @@ class URLFetchStrategy(FetchStrategy): @property def archive_file(self): """Path to the source archive within this stage directory.""" - assert(self.stage) - path = os.path.join(self.stage.path, os.path.basename(self.url)) - return path if os.path.exists(path) else None - + return self.stage.archive_file + @_needs_stage def expand(self): - assert(self.stage) tty.msg("Staging archive: %s" % self.archive_file) self.stage.chdir() @@ -201,12 +206,13 @@ class URLFetchStrategy(FetchStrategy): shutil.move(self.archive_file, destination) + @_needs_stage def check(self): """Check the downloaded archive against a checksum digest. No-op if this stage checks code out of a repository.""" - assert(self.stage) if not self.digest: raise NoDigestError("Attempt to check URLFetchStrategy with no digest.") + checker = crypto.Checker(self.digest) if not checker.check(self.archive_file): raise ChecksumError( @@ -214,9 +220,9 @@ class URLFetchStrategy(FetchStrategy): "Expected %s but got %s." % (self.digest, checker.sum)) + @_needs_stage def reset(self): """Removes the source path if it exists, then re-expands the archive.""" - assert(self.stage) if not self.archive_file: raise NoArchiveFileError("Tried to reset URLFetchStrategy before fetching", "Failed on reset() for URL %s" % self.url) @@ -257,16 +263,18 @@ class VCSFetchStrategy(FetchStrategy): for rt in rev_types: setattr(self, rt, kwargs.get(rt, None)) + + @_needs_stage def check(self): - assert(self.stage) tty.msg("No checksum needed when fetching with %s." % self.name) + @_needs_stage def expand(self): - assert(self.stage) tty.debug("Source fetched with %s is already expanded." % self.name) + @_needs_stage def archive(self, destination, **kwargs): assert(extension(destination) == 'tar.gz') assert(self.stage.source_path.startswith(self.stage.path)) @@ -335,9 +343,8 @@ class GitFetchStrategy(VCSFetchStrategy): self._git = which('git', required=True) return self._git - + @_needs_stage def fetch(self): - assert(self.stage) self.stage.chdir() if self.stage.source_path: @@ -382,8 +389,8 @@ class GitFetchStrategy(VCSFetchStrategy): super(GitFetchStrategy, self).archive(destination, exclude='.git') + @_needs_stage def reset(self): - assert(self.stage) self.stage.chdir_to_source() self.git('checkout', '.') self.git('clean', '-f') @@ -418,8 +425,8 @@ class SvnFetchStrategy(VCSFetchStrategy): return self._svn + @_needs_stage def fetch(self): - assert(self.stage) self.stage.chdir() if self.stage.source_path: @@ -455,8 +462,8 @@ class SvnFetchStrategy(VCSFetchStrategy): super(SvnFetchStrategy, self).archive(destination, exclude='.svn') + @_needs_stage def reset(self): - assert(self.stage) self.stage.chdir_to_source() self._remove_untracked_files() self.svn('revert', '.', '-R') @@ -494,9 +501,8 @@ class HgFetchStrategy(VCSFetchStrategy): self._hg = which('hg', required=True) return self._hg - + @_needs_stage def fetch(self): - assert(self.stage) self.stage.chdir() if self.stage.source_path: @@ -519,8 +525,8 @@ class HgFetchStrategy(VCSFetchStrategy): super(HgFetchStrategy, self).archive(destination, exclude='.hg') + @_needs_stage def reset(self): - assert(self.stage) self.stage.chdir() source_path = self.stage.source_path @@ -619,3 +625,10 @@ class ChecksumError(FetchError): super(ChecksumError, self).__init__(message, long_msg) +class NoStageError(FetchError): + """Raised when fetch operations are called before set_stage().""" + def __init__(self, method): + super(NoStageError, self).__init__( + "Must call FetchStrategy.set_stage() before calling %s" % method.__name__) + + diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py index 2f822b13ab..9c700cd551 100644 --- a/lib/spack/spack/mirror.py +++ b/lib/spack/spack/mirror.py @@ -147,7 +147,7 @@ def create(path, specs, **kwargs): archive_path = join_path(subdir, archive_file) if os.path.exists(archive_path): - tty.msg("%s is already present. Skipping." % spec.format("$_$@")) + tty.msg("Already added %s" % spec.format("$_$@")) present.append(spec) continue -- cgit v1.2.3-70-g09d2 From e4c2891d4ba5cc57a39f24c68affec8ee1eeca2c Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 22 Oct 2014 00:49:16 -0700 Subject: Test for URL extrapolation. --- lib/spack/spack/package.py | 7 ++- lib/spack/spack/test/__init__.py | 3 +- lib/spack/spack/test/url_extrapolate.py | 90 ++++++++++++++++++++++++++++++ lib/spack/spack/test/url_parse.py | 7 ++- var/spack/mock_packages/dyninst/package.py | 11 ++-- 5 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 lib/spack/spack/test/url_extrapolate.py diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index e462562e85..f1a16fdea1 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -440,9 +440,10 @@ class Package(object): version_urls = self.version_urls() if version in version_urls: return version_urls[version] - else: - return url.substitute_version(self.nearest_url(version), - self.url_version(version)) + + # If we have no idea, try to substitute the version. + return url.substitute_version(self.nearest_url(version), + self.url_version(version)) @property diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index be9ac5a560..aa986662bf 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -51,7 +51,8 @@ test_names = ['versions', 'git_fetch', 'svn_fetch', 'hg_fetch', - 'mirror'] + 'mirror', + 'url_extrapolate'] def list_tests(): diff --git a/lib/spack/spack/test/url_extrapolate.py b/lib/spack/spack/test/url_extrapolate.py new file mode 100644 index 0000000000..514d119deb --- /dev/null +++ b/lib/spack/spack/test/url_extrapolate.py @@ -0,0 +1,90 @@ +############################################################################## +# 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 +############################################################################## +"""\ +Tests ability of spack to extrapolate URL versions from existing versions. +""" +import spack +import spack.url as url +from spack.spec import Spec +from spack.version import ver +from spack.test.mock_packages_test import * + + +class UrlExtrapolateTest(MockPackagesTest): + + def test_known_version(self): + d = spack.db.get('dyninst') + + self.assertEqual( + d.url_for_version('8.2'), 'http://www.paradyn.org/release8.2/DyninstAPI-8.2.tgz') + self.assertEqual( + d.url_for_version('8.1.2'), 'http://www.paradyn.org/release8.1.2/DyninstAPI-8.1.2.tgz') + self.assertEqual( + d.url_for_version('8.1.1'), 'http://www.paradyn.org/release8.1/DyninstAPI-8.1.1.tgz') + + + def test_extrapolate_version(self): + d = spack.db.get('dyninst') + + # Nearest URL for 8.1.1.5 is 8.1.1, and the URL there is + # release8.1/DyninstAPI-8.1.1.tgz. Only the last part matches + # the version, so only extrapolate the last part. Obviously + # dyninst has ambiguous URL versions, but we want to make sure + # extrapolation works in a well-defined way. + self.assertEqual( + d.url_for_version('8.1.1.5'), 'http://www.paradyn.org/release8.1/DyninstAPI-8.1.1.5.tgz') + + # 8.2 matches both the release8.2 component and the DyninstAPI-8.2 component. + # Extrapolation should replace both with the new version. + self.assertEqual( + d.url_for_version('8.2.3'), 'http://www.paradyn.org/release8.2.3/DyninstAPI-8.2.3.tgz') + + + def test_with_package(self): + d = spack.db.get('dyninst@8.2') + self.assertEqual(d.fetcher.url, 'http://www.paradyn.org/release8.2/DyninstAPI-8.2.tgz') + + d = spack.db.get('dyninst@8.1.2') + self.assertEqual(d.fetcher.url, 'http://www.paradyn.org/release8.1.2/DyninstAPI-8.1.2.tgz') + + d = spack.db.get('dyninst@8.1.1') + self.assertEqual(d.fetcher.url, 'http://www.paradyn.org/release8.1/DyninstAPI-8.1.1.tgz') + + + def test_concrete_package(self): + s = Spec('dyninst@8.2') + s.concretize() + d = spack.db.get(s) + self.assertEqual(d.fetcher.url, 'http://www.paradyn.org/release8.2/DyninstAPI-8.2.tgz') + + s = Spec('dyninst@8.1.2') + s.concretize() + d = spack.db.get(s) + self.assertEqual(d.fetcher.url, 'http://www.paradyn.org/release8.1.2/DyninstAPI-8.1.2.tgz') + + s = Spec('dyninst@8.1.1') + s.concretize() + d = spack.db.get(s) + self.assertEqual(d.fetcher.url, 'http://www.paradyn.org/release8.1/DyninstAPI-8.1.1.tgz') diff --git a/lib/spack/spack/test/url_parse.py b/lib/spack/spack/test/url_parse.py index a03d6098f1..7a4d201d90 100644 --- a/lib/spack/spack/test/url_parse.py +++ b/lib/spack/spack/test/url_parse.py @@ -281,11 +281,16 @@ class UrlParseTest(unittest.TestCase): 'synergy', '1.3.6p2', 'http://synergy.googlecode.com/files/synergy-1.3.6p2-MacOSX-Universal.zip') - def test_mvapich2_version(self): + def test_mvapich2_19_version(self): self.check( 'mvapich2', '1.9', 'http://mvapich.cse.ohio-state.edu/download/mvapich2/mv2/mvapich2-1.9.tgz') + def test_mvapich2_19_version(self): + self.check( + 'mvapich2', '2.0', + 'http://mvapich.cse.ohio-state.edu/download/mvapich/mv2/mvapich2-2.0.tar.gz') + def test_hdf5_version(self): self.check( 'hdf5', '1.8.13', diff --git a/var/spack/mock_packages/dyninst/package.py b/var/spack/mock_packages/dyninst/package.py index 7657e2c33f..7998578da1 100644 --- a/var/spack/mock_packages/dyninst/package.py +++ b/var/spack/mock_packages/dyninst/package.py @@ -26,11 +26,14 @@ from spack import * class Dyninst(Package): homepage = "https://paradyn.org" - url = "http://www.dyninst.org/sites/default/files/downloads/dyninst/8.1.2/DyninstAPI-8.1.2.tgz" - list_url = "http://www.dyninst.org/downloads/dyninst-8.x" + url = "http://www.paradyn.org/release8.1/DyninstAPI-8.1.1.tgz" - version('8.1.2', 'bf03b33375afa66fe0efa46ce3f4b17a') - version('8.1.1', '1f8743e3a5662b25ce64a7edf647e77d') + version('8.2', 'cxyzab', + url='http://www.paradyn.org/release8.2/DyninstAPI-8.2.tgz') + version('8.1.2', 'bcxyza', + url='http://www.paradyn.org/release8.1.2/DyninstAPI-8.1.2.tgz') + version('8.1.1', 'abcxyz', + url='http://www.paradyn.org/release8.1/DyninstAPI-8.1.1.tgz') depends_on("libelf") depends_on("libdwarf") -- cgit v1.2.3-70-g09d2 From c08985f7d1e9d8e7c0f05629033c72ef3ffe1a26 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 10 Oct 2014 15:02:46 -0700 Subject: Add bib2xhtml --- var/spack/packages/bib2xhtml/package.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 var/spack/packages/bib2xhtml/package.py diff --git a/var/spack/packages/bib2xhtml/package.py b/var/spack/packages/bib2xhtml/package.py new file mode 100644 index 0000000000..7f8e0cfe5a --- /dev/null +++ b/var/spack/packages/bib2xhtml/package.py @@ -0,0 +1,27 @@ +from spack import * +from glob import glob + +class Bib2xhtml(Package): + """bib2xhtml is a program that converts BibTeX files into HTML.""" + homepage = "http://www.spinellis.gr/sw/textproc/bib2xhtml/" + url='http://www.spinellis.gr/sw/textproc/bib2xhtml/bib2xhtml-v3.0-15-gf506.tar.gz' + + version('3.0-15-gf506', 'a26ba02fe0053bbbf2277bdf0acf8645') + + def url_for_version(self, v): + return ('http://www.spinellis.gr/sw/textproc/bib2xhtml/bib2xhtml-v%s.tar.gz' % v) + + def install(self, spec, prefix): + # Add the bst include files to the install directory + bst_include = join_path(prefix.share, 'bib2xhtml') + mkdirp(bst_include) + for bstfile in glob('html-*bst'): + install(bstfile, bst_include) + + # Install the script and point it at the user's favorite perl + # and the bst include directory. + mkdirp(prefix.bin) + install('bib2xhtml', prefix.bin) + filter_file(r'#!/usr/bin/perl', + '#!/usr/bin/env BSTINPUTS=%s perl' % bst_include, + join_path(prefix.bin, 'bib2xhtml')) -- cgit v1.2.3-70-g09d2 From 87b87199f28542be20e49549f48462aed4b73e51 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 22 Oct 2014 01:03:12 -0700 Subject: Fix for SPACK-43: compiler finding fails gracefully on unknown error. --- lib/spack/spack/compiler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/spack/spack/compiler.py b/lib/spack/spack/compiler.py index 90fbf08241..35e3b898ec 100644 --- a/lib/spack/spack/compiler.py +++ b/lib/spack/spack/compiler.py @@ -190,6 +190,12 @@ class Compiler(object): except ProcessError, e: tty.debug("Couldn't get version for compiler %s" % full_path, e) return None + except Exception, e: + # Catching "Exception" here is fine because it just + # means something went wrong running a candidate executable. + tty.debug("Error while executing candidate compiler %s" % full_path, + "%s: %s" %(e.__class__.__name__, e)) + return None successful = [key for key in parmap(check, checks) if key is not None] return dict(((v, p, s), path) for v, p, s, path in successful) -- cgit v1.2.3-70-g09d2 From 94a52a87105044ab276af901860c0fe3fbdca321 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 22 Oct 2014 00:49:41 -0700 Subject: Start documenting new features. --- lib/spack/docs/developer_guide.rst | 2 +- lib/spack/docs/packaging_guide.rst | 340 +++++++++++++++++++------------------ 2 files changed, 172 insertions(+), 170 deletions(-) diff --git a/lib/spack/docs/developer_guide.rst b/lib/spack/docs/developer_guide.rst index 1f0977b4de..969ed60b15 100644 --- a/lib/spack/docs/developer_guide.rst +++ b/lib/spack/docs/developer_guide.rst @@ -4,7 +4,7 @@ Developer Guide ===================== This guide is intended for people who want to work on Spack itself. -If you just want to develop pacakges, see the :ref:`packaging-guide`. +If you just want to develop packages, see the :ref:`packaging-guide`. It is assumed that you've read the :ref:`basic-usage` and :ref:`packaging-guide` sections, and that you're familiar with the diff --git a/lib/spack/docs/packaging_guide.rst b/lib/spack/docs/packaging_guide.rst index 13785e25b7..439e9f8f63 100644 --- a/lib/spack/docs/packaging_guide.rst +++ b/lib/spack/docs/packaging_guide.rst @@ -27,178 +27,22 @@ be ubiquitous in the HPC community due to its use in numerical codes. Second, it's a modern language and has many powerful features to help make package writing easy. -Finally, we've gone to great lengths to make it *easy* to create -packages. The ``spack create`` command lets you generate a -boilerplate package template from a tarball URL, and ideally you'll -only need to run this once and slightly modify the boilerplate to get -your package working. - -This section of the guide goes through the parts of a package, and -then tells you how to make your own. If you're impatient, jump ahead -to :ref:`spack-create`. - -Package Files ---------------------------- - -It's probably easiest to learn about packages by looking at an -example. Let's take a look at the ``libelf`` package: - -.. literalinclude:: ../../../var/spack/packages/libelf/package.py - :lines: 25- - :linenos: - -Directory Structure -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A Spack installation directory is structured like a standard UNIX -install prefix (``bin``, ``lib``, ``include``, ``var``, ``opt``, -etc.). Most of the code for Spack lives in ``$SPACK_ROOT/lib/spack``. -Packages themselves live in ``$SPACK_ROOT/var/spack/packages``. - -If you ``cd`` to that directory, you will see directories for each -package: - -.. command-output:: cd $SPACK_ROOT/var/spack/packages; ls - :shell: - :ellipsis: 10 - -Each of these directories contains a file called ``package.py``. This -file is where all the python code for a package goes. For example, -the ``libelf`` package looks like this:: - - $SPACK_ROOT/var/spack/packages/ - libelf/ - package.py - -Alongside the ``package.py`` file, a package may contain extra files (like -patches) that it needs to build. - - -Package Names -~~~~~~~~~~~~~~~~~~ - -Packages are named after the directory containing ``package.py``. So, -``libelf``'s ``package.py`` lives in a directory called ``libelf``. -The ``package.py`` file contains a class called ``Libelf``, which -extends Spack's ``Package`` class. This is what makes it a Spack -package. The **directory name** is what users need to provide on the -command line. e.g., if you type any of these: - -.. code-block:: sh - - $ spack install libelf - $ spack install libelf@0.8.13 - -Spack sees the package name in the spec and looks for -``libelf/package.py`` in ``var/spack/packages``. Likewise, if you say -``spack install docbook-xml``, then Spack looks for -``docbook-xml/package.py``. - -We use the directory name to packagers more freedom when naming their -packages. Package names can contain letters, numbers, dashes, and -underscores. You can name a package ``3proxy`` or ``_foo`` and Spack -won't care -- it just needs to see that name in the package spec. -These aren't valid Python module names, but we allow them in Spack and -import ``package.py`` file dynamically. - -Package class names -~~~~~~~~~~~~~~~~~~~~~~~ - -The **class name** (``Libelf`` in our example) is formed by converting -words separated by `-` or ``_`` in the file name to camel case. If -the name starts with a number, we prefix the class name with -``_``. Here are some examples: - -================= ================= - Module Name Class Name -================= ================= - ``foo_bar`` ``FooBar`` - ``docbook-xml`` ``DocbookXml`` - ``FooBar`` ``Foobar`` - ``3proxy`` ``_3proxy`` -================= ================= - -The class name is needed by Spack to properly import a package, but -not for much else. In general, you won't have to remember this naming -convention because ``spack create`` will generate a boilerplate class -for you, and you can just fill in the blanks. - -.. _metadata: - -Metadata -~~~~~~~~~~~~~~~~~~~~ - -Just under the class name is a description of the ``libelf`` package. -In Python, this is called a *docstring*: a multi-line, triple-quoted -(``"""``) string that comes just after the definition of a class. -Spack uses the docstring to generate the description of the package -that is shown when you run ``spack info``. If you don't provide a -description, Spack will just print "None" for the description. - -In addition to the package description, there are a few fields you'll -need to fill out. They are as follows: - -``homepage`` (required) - This is the URL where you can learn about the package and get - information. It is displayed to users when they run ``spack info``. - -``url`` (required) - This is the URL where you can download a distribution tarball of - the pacakge's source code. - -``versions`` (optional) - This is a `dictionary - `_ - mapping versions to MD5 hashes. Spack uses the hashes to checksum - archives when it downloads a particular version. - -``parallel`` (optional) Whether make should be parallel by default. - By default, this is ``True``, and package authors need to call - ``make(parallel=False)`` to override. If you set this to ``False`` - at the package level then each call to ``make`` will be sequential - by default, and users will have to call ``make(parallel=True)`` to - override it. - -``versions`` is optional but strongly recommended. Spack will warn -usrs if they try to install a version (e.g., ``libelf@0.8.10`` for -which there is not a checksum available. They can force it to -download the new version and install, but it's better to provide -checksums so users don't have to install from an unchecked archive. - - -Install method -~~~~~~~~~~~~~~~~~~~~~~~ - -The last element of the ``libelf`` package is its ``install()`` -method. This is where the real work of installation happens, and -it's the main part of the package you'll need to customize for each -piece of software. - -.. literalinclude:: ../../../var/spack/packages/libelf/package.py - :start-after: 0.8.12 - :linenos: +Creating Packages +---------------------------------- -``install`` takes a ``spec``: a description of how the package should -be built, and a ``prefix``: the path to the directory where the -software should be installed. +Spack tries to make it *very* easy to create packages. The ``spack +create`` command lets you generate a boilerplate package template from +a tarball URL. In most cases, you'll only need to run this once, then +slightly modify the boilerplate to get your package working. -:ref:`Writing the install method ` is documented in -detail later, but in general, the ``install()`` method should look -familiar. ``libelf`` uses autotools, so the package first calls -``configure``, passing the prefix and some other package-specific -arguments. It then calls ``make`` and ``make install``. +If ``spack create`` does not work for you, you can always use ``spack +edit``. This section of the guide goes through the parts of a package, +and then tells you how to make your own. If you're impatient, jump +ahead to :ref:`spack-create`. -Spack provides wrapper functions for ``configure`` and ``make`` so -that you can call them in a similar way to how you'd call a shell -comamnd. In reality, these are Python functions. Spack provides -these functions to make writing packages more natural. See the section -on :ref:`shell wrappers `. .. _spack-create: -Creating Packages ----------------------------------- - ``spack create`` ~~~~~~~~~~~~~~~~~~~~~ @@ -212,9 +56,9 @@ All you need is the URL to a tarball you want to package: $ spack create http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz -When you run this, Spack will look at the tarball URL, and it will try -to figure out the name of the package to be created. It will also try -to figure out what version strings for that package look like. Once +When you run this, Spack looks at the tarball URL and tries to figure +out the name of the package to be created. It will also try to +determine out what version strings look like for this package. Once that is done, it tries to find *additional* versions by spidering the package's webpage. Spack then prompts you to tell it how many versions you want to download and checksum. @@ -411,6 +255,164 @@ syntax errors, or the ``import`` will fail. Use this once you've got your package in working order. + +Package Files +--------------------------- + +It's probably easiest to learn about packages by looking at an +example. Let's take a look at the ``libelf`` package: + +.. literalinclude:: ../../../var/spack/packages/libelf/package.py + :lines: 25- + :linenos: + +Directory Structure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A Spack installation directory is structured like a standard UNIX +install prefix (``bin``, ``lib``, ``include``, ``var``, ``opt``, +etc.). Most of the code for Spack lives in ``$SPACK_ROOT/lib/spack``. +Packages themselves live in ``$SPACK_ROOT/var/spack/packages``. + +If you ``cd`` to that directory, you will see directories for each +package: + +.. command-output:: cd $SPACK_ROOT/var/spack/packages; ls + :shell: + :ellipsis: 10 + +Each of these directories contains a file called ``package.py``. This +file is where all the python code for a package goes. For example, +the ``libelf`` package looks like this:: + + $SPACK_ROOT/var/spack/packages/ + libelf/ + package.py + +Alongside the ``package.py`` file, a package may contain extra files (like +patches) that it needs to build. + + +Package Names +~~~~~~~~~~~~~~~~~~ + +Packages are named after the directory containing ``package.py``. So, +``libelf``'s ``package.py`` lives in a directory called ``libelf``. +The ``package.py`` file contains a class called ``Libelf``, which +extends Spack's ``Package`` class. This is what makes it a Spack +package. The **directory name** is what users need to provide on the +command line. e.g., if you type any of these: + +.. code-block:: sh + + $ spack install libelf + $ spack install libelf@0.8.13 + +Spack sees the package name in the spec and looks for +``libelf/package.py`` in ``var/spack/packages``. Likewise, if you say +``spack install docbook-xml``, then Spack looks for +``docbook-xml/package.py``. + +We use the directory name to packagers more freedom when naming their +packages. Package names can contain letters, numbers, dashes, and +underscores. You can name a package ``3proxy`` or ``_foo`` and Spack +lwon't care -- it just needs to see that name in the package spec. +These aren't valid Python module names, but we allow them in Spack and +import ``package.py`` file dynamically. + +Package class names +~~~~~~~~~~~~~~~~~~~~~~~ + +The **class name** (``Libelf`` in our example) is formed by converting +words separated by `-` or ``_`` in the file name to camel case. If +the name starts with a number, we prefix the class name with +``_``. Here are some examples: + +================= ================= + Module Name Class Name +================= ================= + ``foo_bar`` ``FooBar`` + ``docbook-xml`` ``DocbookXml`` + ``FooBar`` ``Foobar`` + ``3proxy`` ``_3proxy`` +================= ================= + +The class name is needed by Spack to properly import a package, but +not for much else. In general, you won't have to remember this naming +convention because ``spack create`` will generate a boilerplate class +for you, and you can just fill in the blanks. + +.. _metadata: + +Package metadata +-------------------- + +Under the class declaration is a *docstring* (as Python calls it) +enclosed in triple-quotes (``"""``). Spack uses the docstring to +generate the description of the package that is shown when you run +``spack info``. If you don't provide a description, Spack will just +print "None" for the description. + +In addition to the package description, there are a few fields you'll +need to fill out. They are as follows: + +``homepage`` (required) + This is the URL where you can learn about the package and get + information. It is displayed to users when they run ``spack info``. + +``url`` (required) + This is the URL where you can download a distribution tarball of + the pacakge's source code. + +``versions`` (optional) + This is a `dictionary + `_ + mapping versions to MD5 hashes. Spack uses the hashes to checksum + archives when it downloads a particular version. + +``parallel`` (optional) Whether make should be parallel by default. + By default, this is ``True``, and package authors need to call + ``make(parallel=False)`` to override. If you set this to ``False`` + at the package level then each call to ``make`` will be sequential + by default, and users will have to call ``make(parallel=True)`` to + override it. + +``versions`` is optional but strongly recommended. Spack will warn +usrs if they try to install a version (e.g., ``libelf@0.8.10`` for +which there is not a checksum available. They can force it to +download the new version and install, but it's better to provide +checksums so users don't have to install from an unchecked archive. + + +Install method +~~~~~~~~~~~~~~~~~~~~~~~ + +The last element of the ``libelf`` package is its ``install()`` +method. This is where the real work of installation happens, and +it's the main part of the package you'll need to customize for each +piece of software. + +.. literalinclude:: ../../../var/spack/packages/libelf/package.py + :start-after: 0.8.12 + :linenos: + +``install`` takes a ``spec``: a description of how the package should +be built, and a ``prefix``: the path to the directory where the +software should be installed. + +:ref:`Writing the install method ` is documented in +detail later, but in general, the ``install()`` method should look +familiar. ``libelf`` uses autotools, so the package first calls +``configure``, passing the prefix and some other package-specific +arguments. It then calls ``make`` and ``make install``. + +Spack provides wrapper functions for ``configure`` and ``make`` so +that you can call them in a similar way to how you'd call a shell +comamnd. In reality, these are Python functions. Spack provides +these functions to make writing packages more natural. See the section +on :ref:`shell wrappers `. + + Optional Package Attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3-70-g09d2 From ce1b30c2298ed3a335c18bd27d5f34621c3197cd Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 23 Oct 2014 21:08:13 -0700 Subject: Adding initial version of MPE2 package. --- var/spack/packages/mpe2/package.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 var/spack/packages/mpe2/package.py diff --git a/var/spack/packages/mpe2/package.py b/var/spack/packages/mpe2/package.py new file mode 100644 index 0000000000..f043ad6ba6 --- /dev/null +++ b/var/spack/packages/mpe2/package.py @@ -0,0 +1,24 @@ +from spack import * + +class Mpe2(Package): + """Message Passing Extensions (MPE) -- Parallel, shared X window graphics""" + + homepage = "http://www.mcs.anl.gov/research/projects/perfvis/software/MPE/" + url = "ftp://ftp.mcs.anl.gov/pub/mpi/mpe/mpe2-1.3.0.tar.gz" + + version('1.3.0', '67bf0c7b2e573df3ba0d2059a96c2f7b') + + depends_on("mpi") + + def install(self, spec, prefix): + configure("--prefix=" + prefix, + "--x-includes=/usr/X11R6/include", + "--x-libraries=/usr/X11R6/lib", + "--enable-mpe_graphics=yes", + "--disable-f77", + "--enable-viewers=no", + "--enable-slog2=no", + "--with-mpicc=mpicc") + + make() + make("install") -- cgit v1.2.3-70-g09d2 From fa4d58db52ae90fa3159487af484578038d55b42 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 25 Oct 2014 14:38:42 -0700 Subject: Add a dummy depends_on to the boilerplate. --- lib/spack/spack/cmd/create.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index 5f6350c8e8..7ac10285a4 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -72,6 +72,9 @@ class ${class_name}(Package): ${versions} + # FIXME: Add dependencies if this package requires them. + # depends_on("foo") + def install(self, spec, prefix): # FIXME: Modify the configure line to suit your build system here. ${configure} -- cgit v1.2.3-70-g09d2 From 2e2e720a2a9f55af6d9e18f43d6c78e66c573c1a Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 25 Oct 2014 14:40:17 -0700 Subject: Add spack md5 command for simple checksumming. --- lib/spack/spack/cmd/md5.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/spack/spack/cmd/md5.py diff --git a/lib/spack/spack/cmd/md5.py b/lib/spack/spack/cmd/md5.py new file mode 100644 index 0000000000..496835c64b --- /dev/null +++ b/lib/spack/spack/cmd/md5.py @@ -0,0 +1,52 @@ +############################################################################## +# Copyright (c) 2013-2014, 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 +############################################################################## +import os +import hashlib +from external import argparse + +import llnl.util.tty as tty +from llnl.util.filesystem import * + +import spack.util.crypto + +description = "Calculate md5 checksums for files." + +def setup_parser(subparser): + setup_parser.parser = subparser + subparser.add_argument('files', nargs=argparse.REMAINDER, + help="Files to checksum.") + +def md5(parser, args): + if not args.files: + setup_parser.parser.print_help() + + for f in args.files: + if not os.path.isfile(f): + tty.die("Not a file: %s" % f) + if not can_access(f): + tty.die("Cannot read file: %s" % f) + + checksum = spack.util.crypto.checksum(hashlib.md5, f) + print "%s %s" % (checksum, f) -- cgit v1.2.3-70-g09d2 From 340b5590f17b1023f469c654f18eb6ee71c0db2b Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 25 Oct 2014 14:41:06 -0700 Subject: Add coreutils package. --- var/spack/packages/coreutils/package.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 var/spack/packages/coreutils/package.py diff --git a/var/spack/packages/coreutils/package.py b/var/spack/packages/coreutils/package.py new file mode 100644 index 0000000000..78c608d8eb --- /dev/null +++ b/var/spack/packages/coreutils/package.py @@ -0,0 +1,17 @@ +from spack import * + +class Coreutils(Package): + """The GNU Core Utilities are the basic file, shell and text + manipulation utilities of the GNU operating system. These are + the core utilities which are expected to exist on every + operating system. + """ + homepage = "http://www.gnu.org/software/coreutils/" + url = "http://ftp.gnu.org/gnu/coreutils/coreutils-8.23.tar.xz" + + version('8.23', 'abed135279f87ad6762ce57ff6d89c41') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + make() + make("install") -- cgit v1.2.3-70-g09d2 From 76ed5c212cdf41e44428ef723c3d7f5695efbcc8 Mon Sep 17 00:00:00 2001 From: Bob Robey Date: Sat, 25 Oct 2014 21:25:25 -0600 Subject: Adding autotools and ImageMagick and patch for mpe2 --- var/spack/packages/ImageMagick/package.py | 21 +++++++++++++++++++++ var/spack/packages/autoconf/package.py | 14 ++++++++++++++ var/spack/packages/automake/package.py | 16 ++++++++++++++++ var/spack/packages/cmake/package.py | 10 ++++++++-- var/spack/packages/fontconfig/package.py | 16 ++++++++++++++++ var/spack/packages/freetype/package.py | 16 ++++++++++++++++ var/spack/packages/jpeg/package.py | 14 ++++++++++++++ var/spack/packages/libpng/package.py | 14 ++++++++++++++ var/spack/packages/libtiff/package.py | 16 ++++++++++++++++ var/spack/packages/libtool/package.py | 14 ++++++++++++++ var/spack/packages/mpe2/mpe2.patch | 12 ++++++++++++ var/spack/packages/mpe2/package.py | 4 ++++ 12 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 var/spack/packages/ImageMagick/package.py create mode 100644 var/spack/packages/autoconf/package.py create mode 100644 var/spack/packages/automake/package.py create mode 100644 var/spack/packages/fontconfig/package.py create mode 100644 var/spack/packages/freetype/package.py create mode 100644 var/spack/packages/jpeg/package.py create mode 100644 var/spack/packages/libpng/package.py create mode 100644 var/spack/packages/libtiff/package.py create mode 100644 var/spack/packages/libtool/package.py create mode 100644 var/spack/packages/mpe2/mpe2.patch diff --git a/var/spack/packages/ImageMagick/package.py b/var/spack/packages/ImageMagick/package.py new file mode 100644 index 0000000000..fc1ee56bbd --- /dev/null +++ b/var/spack/packages/ImageMagick/package.py @@ -0,0 +1,21 @@ +from spack import * + +class Imagemagick(Package): + """ImageMagick is a image processing library""" + homepage = "http://www.imagemagic.org" + url = "http://www.imagemagick.org/download/ImageMagick-6.8.9-8.tar.gz" + + version('6.8.9-8', '74aa203286bfb8aaadd320f787eea64e') + + depends_on(libtool) + depends_on(jpeg) + depends_on(libpng) + depends_on(freetype) + depends_on(fontconfig) + depends_on(libtiff) + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/autoconf/package.py b/var/spack/packages/autoconf/package.py new file mode 100644 index 0000000000..5189faf054 --- /dev/null +++ b/var/spack/packages/autoconf/package.py @@ -0,0 +1,14 @@ +from spack import * + +class Autoconf(Package): + """Autoconf -- system configuration part of autotools""" + homepage = "https://www.gnu.org/software/autoconf/" + url = "http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz" + + version('2.69', '82d05e03b93e45f5a39b828dc9c6c29b') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/automake/package.py b/var/spack/packages/automake/package.py new file mode 100644 index 0000000000..73c01afdd6 --- /dev/null +++ b/var/spack/packages/automake/package.py @@ -0,0 +1,16 @@ +from spack import * + +class Automake(Package): + """Automake -- make file builder part of autotools""" + homepage = "http://www.gnu.org/software/automake/" + url = "http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz" + + version('1.14.1', 'd052a3e884631b9c7892f2efce542d75') + + depends_on(autoconf) + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/cmake/package.py b/var/spack/packages/cmake/package.py index 890af9baa9..9efa370c8b 100644 --- a/var/spack/packages/cmake/package.py +++ b/var/spack/packages/cmake/package.py @@ -28,9 +28,15 @@ class Cmake(Package): """A cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software.""" homepage = 'https://www.cmake.org' - url = 'http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz' - version('2.8.10.2', '097278785da7182ec0aea8769d06860c') + version('2.8.10.2', '097278785da7182ec0aea8769d06860c', + url = 'http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz') + + version('3.0.2', 'db4c687a31444a929d2fdc36c4dfb95f', + url = 'http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz') + +# version('3.0.1', 'e2e05d84cb44a42f1371d9995631dcf5') +# version('3.0.0', '21a1c85e1a3b803c4b48e7ff915a863e') def install(self, spec, prefix): configure('--prefix=' + prefix, diff --git a/var/spack/packages/fontconfig/package.py b/var/spack/packages/fontconfig/package.py new file mode 100644 index 0000000000..89b13604e8 --- /dev/null +++ b/var/spack/packages/fontconfig/package.py @@ -0,0 +1,16 @@ +from spack import * + +class Fontconfig(Package): + """Fontconfig customizing font access""" + homepage = "http://www.freedesktop.org/wiki/Software/fontconfig/" + url = "http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.11.1.tar.gz" + + version('2.11.1' , 'e75e303b4f7756c2b16203a57ac87eba') + + depends_on('freetype') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/freetype/package.py b/var/spack/packages/freetype/package.py new file mode 100644 index 0000000000..0309b858a1 --- /dev/null +++ b/var/spack/packages/freetype/package.py @@ -0,0 +1,16 @@ +from spack import * + +class Freetype(Package): + """Font package""" + homepage = "http://http://www.freetype.org" + url = "http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz" + + version('2.5.3' , 'cafe9f210e45360279c730d27bf071e9') + + depends_on('libpng') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/jpeg/package.py b/var/spack/packages/jpeg/package.py new file mode 100644 index 0000000000..b34fd5cb2d --- /dev/null +++ b/var/spack/packages/jpeg/package.py @@ -0,0 +1,14 @@ +from spack import * + +class Jpeg(Package): + """jpeg library""" + homepage = "http://www.ijg.org" + url = "http://www.ijg.org/files/jpegsrc.v9a.tar.gz" + + version('9', 'b397211ddfd506b92cd5e02a22ac924d') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/libpng/package.py b/var/spack/packages/libpng/package.py new file mode 100644 index 0000000000..a6d9bf0b46 --- /dev/null +++ b/var/spack/packages/libpng/package.py @@ -0,0 +1,14 @@ +from spack import * + +class Libpng(Package): + """libpng graphics file format""" + homepage = "http://www.libpng.org/pub/png/libpng.html" + url = "http://sourceforge.net/projects/libpng/files/libpng16/1.6.14/libpng-1.6.14.tar.gz/download" + + version('1.6.14', '2101b3de1d5f348925990f9aa8405660') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/libtiff/package.py b/var/spack/packages/libtiff/package.py new file mode 100644 index 0000000000..0de544ad92 --- /dev/null +++ b/var/spack/packages/libtiff/package.py @@ -0,0 +1,16 @@ +from spack import * + +class libtiff(Package): + """libtiff graphics format library""" + homepage = "http://www.remotesensing.org/libtiff/" + url = "http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz" + + version('4.0.3', '051c1068e6a0627f461948c365290410') + + depends_on('jpeg') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/libtool/package.py b/var/spack/packages/libtool/package.py new file mode 100644 index 0000000000..a07daf9781 --- /dev/null +++ b/var/spack/packages/libtool/package.py @@ -0,0 +1,14 @@ +from spack import * + +class Libtool(Package): + """libtool -- library building part of autotools""" + homepage = "https://www.gnu.org/software/libtool/" + url = "http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz" + + version('2.4.2' , 'd2f3b7d4627e69e13514a40e72a24d50') + + def install(self, spec, prefix): + configure("--prefix=%s" % prefix) + + make() + make("install") diff --git a/var/spack/packages/mpe2/mpe2.patch b/var/spack/packages/mpe2/mpe2.patch new file mode 100644 index 0000000000..3ade1f04f4 --- /dev/null +++ b/var/spack/packages/mpe2/mpe2.patch @@ -0,0 +1,12 @@ +diff -rupN mpe2-1.3.0/src/graphics/src/mpe_graphics.c mpe2-1.3.0.new/src/graphics/src/mpe_graphics.c +--- mpe2-1.3.0/src/graphics/src/mpe_graphics.c 2009-06-15 10:36:22.000000000 -0600 ++++ mpe2-1.3.0.new/src/graphics/src/mpe_graphics.c 2014-10-25 00:11:22.000000000 -0600 +@@ -982,7 +982,7 @@ char *string; + return MPE_ERR_BAD_ARGS; + } + +- printf("color = %d, string = %s\n",(int) color, string); ++//printf("color = %d, string = %s\n",(int) color, string); + + XBSetPixVal( graph->xwin, graph->xwin->cmapping[color] ); + returnVal = XDrawString( graph->xwin->disp, XBDrawable(graph->xwin), diff --git a/var/spack/packages/mpe2/package.py b/var/spack/packages/mpe2/package.py index f043ad6ba6..27295172cc 100644 --- a/var/spack/packages/mpe2/package.py +++ b/var/spack/packages/mpe2/package.py @@ -8,8 +8,12 @@ class Mpe2(Package): version('1.3.0', '67bf0c7b2e573df3ba0d2059a96c2f7b') + patch('mpe2.patch') + depends_on("mpi") + provides("mpe") + def install(self, spec, prefix): configure("--prefix=" + prefix, "--x-includes=/usr/X11R6/include", -- cgit v1.2.3-70-g09d2 From f9149b6cb63416af2f952c71db8750450f30cbc1 Mon Sep 17 00:00:00 2001 From: Bob Robey Date: Sat, 25 Oct 2014 21:59:01 -0600 Subject: Fixing errors in depends_on and updating version for ImageMagick --- var/spack/packages/ImageMagick/package.py | 16 ++++++++-------- var/spack/packages/automake/package.py | 2 +- var/spack/packages/libtiff/package.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/var/spack/packages/ImageMagick/package.py b/var/spack/packages/ImageMagick/package.py index fc1ee56bbd..39c733e0df 100644 --- a/var/spack/packages/ImageMagick/package.py +++ b/var/spack/packages/ImageMagick/package.py @@ -3,16 +3,16 @@ from spack import * class Imagemagick(Package): """ImageMagick is a image processing library""" homepage = "http://www.imagemagic.org" - url = "http://www.imagemagick.org/download/ImageMagick-6.8.9-8.tar.gz" + url = "http://www.imagemagick.org/download/ImageMagick-6.8.9-9.tar.gz" - version('6.8.9-8', '74aa203286bfb8aaadd320f787eea64e') + version('6.8.9-9', 'e63fed3e3550851328352c708f800676') - depends_on(libtool) - depends_on(jpeg) - depends_on(libpng) - depends_on(freetype) - depends_on(fontconfig) - depends_on(libtiff) + depends_on('libtool') + depends_on('jpeg') + depends_on('libpng') + depends_on('freetype') + depends_on('fontconfig') +# depends_on('libtiff') def install(self, spec, prefix): configure("--prefix=%s" % prefix) diff --git a/var/spack/packages/automake/package.py b/var/spack/packages/automake/package.py index 73c01afdd6..9115822730 100644 --- a/var/spack/packages/automake/package.py +++ b/var/spack/packages/automake/package.py @@ -7,7 +7,7 @@ class Automake(Package): version('1.14.1', 'd052a3e884631b9c7892f2efce542d75') - depends_on(autoconf) + depends_on('autoconf') def install(self, spec, prefix): configure("--prefix=%s" % prefix) diff --git a/var/spack/packages/libtiff/package.py b/var/spack/packages/libtiff/package.py index 0de544ad92..ec54cf7adf 100644 --- a/var/spack/packages/libtiff/package.py +++ b/var/spack/packages/libtiff/package.py @@ -1,6 +1,6 @@ from spack import * -class libtiff(Package): +class Libtiff(Package): """libtiff graphics format library""" homepage = "http://www.remotesensing.org/libtiff/" url = "http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz" -- cgit v1.2.3-70-g09d2 From 525344aa85199d6ceb6a25af4b454a5096ae369e Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 00:55:25 -0700 Subject: Make info command show VCS URLs properly. --- lib/spack/spack/cmd/info.py | 32 +++++++++++++++++--------------- lib/spack/spack/fetch_strategy.py | 19 +++++++++++++++---- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index bb147b30f5..a1c35269be 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -26,6 +26,7 @@ import re import textwrap from llnl.util.tty.colify import colify import spack +import spack.fetch_strategy as fs description = "Get detailed information on a particular package" @@ -34,40 +35,41 @@ def setup_parser(subparser): def info(parser, args): - package = spack.db.get(args.name) - print "Package: ", package.name - print "Homepage: ", package.homepage + pkg = spack.db.get(args.name) + print "Package: ", pkg.name + print "Homepage: ", pkg.homepage print - print "Safe versions: " + print "Versions: " - if not package.versions: + if not pkg.versions: print("None.") else: - maxlen = max(len(str(v)) for v in package.versions) + maxlen = max(len(str(v)) for v in pkg.versions) fmt = "%%-%ss" % maxlen - for v in reversed(sorted(package.versions)): - print " " + (fmt % v) + " " + package.url_for_version(v) + for v in reversed(sorted(pkg.versions)): + f = fs.for_package_version(pkg, v) + print " " + (fmt % v) + " " + str(f) print print "Dependencies:" - if package.dependencies: - colify(package.dependencies, indent=4) + if pkg.dependencies: + colify(pkg.dependencies, indent=4) else: print " None" print - print "Virtual packages: " - if package.provided: - for spec, when in package.provided.items(): + print "Virtual pkgs: " + if pkg.provided: + for spec, when in pkg.provided.items(): print " %s provides %s" % (when, spec) else: print " None" print print "Description:" - if package.__doc__: - doc = re.sub(r'\s+', ' ', package.__doc__) + if pkg.__doc__: + doc = re.sub(r'\s+', ' ', pkg.__doc__) lines = textwrap.wrap(doc, 72) for line in lines: print " " + line diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index f79051c500..779cd76bae 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -240,7 +240,7 @@ class URLFetchStrategy(FetchStrategy): if self.url: return self.url else: - return "URLFetchStrategy" + return "[no url]" class VCSFetchStrategy(FetchStrategy): @@ -293,7 +293,7 @@ class VCSFetchStrategy(FetchStrategy): def __str__(self): - return self.url + return "VCS: %s" % self.url def __repr__(self): @@ -396,6 +396,10 @@ class GitFetchStrategy(VCSFetchStrategy): self.git('clean', '-f') + def __str__(self): + return "[git] %s" % self.url + + class SvnFetchStrategy(VCSFetchStrategy): """Fetch strategy that gets source code from a subversion repository. Use like this in a package: @@ -469,6 +473,11 @@ class SvnFetchStrategy(VCSFetchStrategy): self.svn('revert', '.', '-R') + def __str__(self): + return "[svn] %s" % self.url + + + class HgFetchStrategy(VCSFetchStrategy): """Fetch strategy that gets source code from a Mercurial repository. Use like this in a package: @@ -543,6 +552,10 @@ class HgFetchStrategy(VCSFetchStrategy): self.stage.chdir_to_source() + def __str__(self): + return "[hg] %s" % self.url + + def from_url(url): """Given a URL, find an appropriate fetch strategy for it. Currently just gives you a URLFetchStrategy that uses curl. @@ -630,5 +643,3 @@ class NoStageError(FetchError): def __init__(self, method): super(NoStageError, self).__init__( "Must call FetchStrategy.set_stage() before calling %s" % method.__name__) - - -- cgit v1.2.3-70-g09d2 From d41d6ed863decfa91720c8f71a2aca1a2c59ace7 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 00:55:38 -0700 Subject: Updated packaging docs. --- lib/spack/docs/packaging_guide.rst | 1558 +++++++++++++++++++++++++----------- lib/spack/spack/package.py | 4 +- 2 files changed, 1077 insertions(+), 485 deletions(-) diff --git a/lib/spack/docs/packaging_guide.rst b/lib/spack/docs/packaging_guide.rst index 439e9f8f63..1f95e56d2a 100644 --- a/lib/spack/docs/packaging_guide.rst +++ b/lib/spack/docs/packaging_guide.rst @@ -4,67 +4,60 @@ Packaging Guide ===================== This guide is intended for developers or administrators who want to -*package* their software so that Spack can install it. We assume that -you have at least some familiarty with Python, and that you've read -the :ref:`basic usage guide `, especially the part -about :ref:`specs `. +package software so that Spack can install it. It assumes that you +have at least some familiarty with Python, and that you've read the +:ref:`basic usage guide `, especially the part about +:ref:`specs `. There are two key parts of Spack: #. **Specs**: expressions for describing builds of software, and - #. **Packages**: Python modules that build software according to a - spec. + #. **Packages**: Python modules that describe how to build + software according to a spec. -Package files allow a developer to encapsulate build logic for -different versions, compilers, and platforms in one place. Specs -allow a user to describe a *particular* build in a way that a package -author can understand. +Specs allow a user to describe a *particular* build in a way that a +package author can understand. Packages allow a developer to +encapsulate the logic build logic for different versions, compilers, +options, platforms, and dependency combinations in one place. Packages in Spack are written in pure Python, so you can do anything in Spack that you can do in Python. Python was chosen as the -implementation language for two reasons. First, Python is getting to -be ubiquitous in the HPC community due to its use in numerical codes. +implementation language for two reasons. First, Python is becoming +ubiquitous in the HPC community due to its use in numerical codes. Second, it's a modern language and has many powerful features to help make package writing easy. -Creating Packages +Creating & Editing Packages ---------------------------------- -Spack tries to make it *very* easy to create packages. The ``spack -create`` command lets you generate a boilerplate package template from -a tarball URL. In most cases, you'll only need to run this once, then -slightly modify the boilerplate to get your package working. - -If ``spack create`` does not work for you, you can always use ``spack -edit``. This section of the guide goes through the parts of a package, -and then tells you how to make your own. If you're impatient, jump -ahead to :ref:`spack-create`. - - .. _spack-create: ``spack create`` ~~~~~~~~~~~~~~~~~~~~~ -The ``spack create`` command takes the tedium out of making packages. -It generates boilerplate code for you, so that you can focus on -getting your package build working. +The ``spack create`` command generates boilerplate package template +from a URL pointing to a tarball or other software archive. In most +cases, you'll only need to run this once, then slightly modify the +boilerplate to get your package working. -All you need is the URL to a tarball you want to package: +All you need is the URL to a tarball (other archive formats are ok +too) you want to package: .. code-block:: sh $ spack create http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz When you run this, Spack looks at the tarball URL and tries to figure -out the name of the package to be created. It will also try to -determine out what version strings look like for this package. Once -that is done, it tries to find *additional* versions by spidering the -package's webpage. Spack then prompts you to tell it how many -versions you want to download and checksum. +out the name of the package to be created. It also tries to determine +out what version strings look like for this package. Using this +information, it tries to find *additional* versions by spidering the +package's webpage. If it finds multiple versions, Spack prompts you +to tell it how many versions you want to download and checksum. .. code-block:: sh + $ spack create http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz + ==> This looks like a URL for cmake version 2.8.12.1. ==> Creating template for package cmake ==> Found 18 versions of cmake. 2.8.12.1 http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz @@ -87,7 +80,7 @@ Spack will automatically download the number of tarballs you specify Note that you don't need to do everything up front. If your package is large, you can always choose to download just one tarball for now, then run :ref:`spack checksum ` later if you end up -wanting more. Let's say you chose to download 3 tarballs: +wanting more. Let's say you choose to download 3 tarballs: .. code-block:: sh @@ -130,9 +123,12 @@ Now Spack generates boilerplate code and opens the new homepage = "http://www.example.com" url = "http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz" - versions = { '2.8.12.1' : '9d38cd4e2c94c3cea97d0e2924814acc', - '2.8.12' : '105bc6d21cc2e9b6aff901e43c53afea', - '2.8.11.2' : '6f5d7b8e7534a5d9e1a7664ba63cf882', } + version('2.8.12.1', '9d38cd4e2c94c3cea97d0e2924814acc') + version('2.8.12', '105bc6d21cc2e9b6aff901e43c53afea') + version('2.8.11.2', '6f5d7b8e7534a5d9e1a7664ba63cf882') + + # FIXME: Add dependencies if this package requires them. + # depends_on("foo") def install(self, spec, prefix): # FIXME: Modify the configure line to suit your build system here. @@ -145,42 +141,85 @@ Now Spack generates boilerplate code and opens the new The tedious stuff (creating the class, checksumming archives) has been done for you. -All the things you still need to change are marked with ``FIXME`` -labels. The first ``FIXME`` refers to the commented instructions at -the top of the file. You can delete these after reading them. The -rest of them are as follows: +.. note:: + + If ``spack create`` fails to download or to detect the package + version, you can use ``spack edit -f`` to generate simpler + boilerplate. See the next section for more on this. + +In the generated package, the download ``url`` attribute is already +set. All the things you still need to change are marked with +``FIXME`` labels. The first ``FIXME`` refers to the commented +instructions at the top of the file. You can delete these +instructions after reading them. The rest of them are as follows: + + #. Add a description. + + Immediately inside the package class is a *docstring* in + triple-quotes (``"""``). It's used to generate the description + shown when users run ``spack info``. + + #. Change the ``homepage`` to a useful URL. + + The ``homepage`` is displayed when users run ``spack info`` so + that they can learn about packages. + + #. Add ``depends_on()`` calls for the package's dependencies. + + ``depends_on`` tells Spack that other packages need to be built + and installed before this one. See `dependencies_`. - #. Add a description in your package's docstring. - #. Change the homepage to a useful URL (not ``example.com``). #. Get the ``install()`` method working. + The ``install()`` method implements the logic to build a + package. The code should look familiar; it is designed to look + like a shell script. Specifics will differ depending on the package, + and :ref:`implementing the install method ` is + covered in detail later. + +Before going into details, we'll cover a few more basics. + +.. _spack-edit: ``spack edit`` ~~~~~~~~~~~~~~~~~~~~ -Once you've created a package, you can go back and edit it using -``spack edit``. For example, this: +One of the easiest ways to learn to write packages is to look at +existing ones. You can edit a package file by name with the ``spack +edit`` command: .. code-block:: sh - spack edit libelf + spack edit cmake + +So, if you used ``spack create`` to create a package, then saved and +closed the resulting file, you can get back to it with ``spack edit``. +The ``cmake`` package actually lives in +``$SPACK_ROOT/var/spack/packages/cmake/package.py``, but this provides +a much simpler shortcut and saves you the trouble of typing the full +path. + -will open ``$SPACK_ROOT/var/spack/packages/libelf/package.py`` in -``$EDITOR``. If you try to edit a package that doesn't exist, Spack -will recommend using ``spack create``: +``spack edit -f`` +~~~~~~~~~~~~~~~~~~~~ +If you try to edit a package that doesn't exist, Spack will recommend +using ``spack create``: .. code-block:: sh $ spack edit foo ==> Error: No package 'foo'. Use spack create, or supply -f/--force to edit a new file. -And, finally, if you *really* want to skip all the automatic stuff -that ``spack create`` does for you, then you can run ``spack edit --f/--force``: +As the output advises, You can use ``spack edit -f/--force`` to force +the creation of a new, *very* simple boilerplate package: + +.. code-block:: sh $ spack edit -f foo -Which will generate a minimal package structure for you to fill in: +Unlike ``spack create``, which tries to infer names and versions, and +which actually downloads the tarball and checksums it for you, ``spack +edit -f`` will substitute dummy values for you to fill in yourself: .. code-block:: python :linenos: @@ -193,24 +232,195 @@ Which will generate a minimal package structure for you to fill in: homepage = "http://www.example.com" url = "http://www.example.com/foo-1.0.tar.gz" - versions = { '1.0' : '0123456789abcdef0123456789abcdef' } + version('1.0', '0123456789abcdef0123456789abcdef') def install(self, spec, prefix): configure("--prefix=" + prefix) make() make("install") -This is useful when, e.g., Spack cannot figure out the name and +This is useful when ``spack create`` cannot figure out the name and version of your package from the archive URL. +Naming & Directory Structure +-------------------------------------- + +This section describes how packages need to be named, and where they +live in Spack's directory structure. In general, `spack-create`_ and +`spack-edit`_ handle creating package files for you, so you can skip +most of the details here. + +``var/spack/packages`` +~~~~~~~~~~~~~~~~~~~~~~~ + +A Spack installation directory is structured like a standard UNIX +install prefix (``bin``, ``lib``, ``include``, ``var``, ``opt``, +etc.). Most of the code for Spack lives in ``$SPACK_ROOT/lib/spack``. +Packages themselves live in ``$SPACK_ROOT/var/spack/packages``. + +If you ``cd`` to that directory, you will see directories for each +package: + +.. command-output:: cd $SPACK_ROOT/var/spack/packages; ls -CF + :shell: + +Each directory contains a file called ``package.py``, which is where +all the python code for the package goes. For example, the ``libelf`` +package lives in:: + + $SPACK_ROOT/var/spack/packages/libelf/package.py + +Alongside the ``package.py`` file, a package may contain extra +directories or files (like patches) that it needs to build. + + +Package Names +~~~~~~~~~~~~~~~~~~ + +Packages are named after the directory containing ``package.py``. So, +``libelf``'s ``package.py`` lives in a directory called ``libelf``. +The ``package.py`` file contains a class called ``Libelf``, which +extends Spack's ``Package`` class. This is what makes it a Spack +package: + +``var/spack/packages/libelf/package.py`` + +.. code-block:: python + :linenos: + + from spack import * + + class Libelf(Package): + """ ... description ... """ + homepage = ... + url = ... + version(...) + depends_on(...) + + def install(): + ... + +The **directory name** (``libelf``) is what users need to provide on +the command line. e.g., if you type any of these: + +.. code-block:: sh + + $ spack install libelf + $ spack install libelf@0.8.13 + +Spack sees the package name in the spec and looks for +``libelf/package.py`` in ``var/spack/packages``. Likewise, if you say +``spack install docbook-xml``, then Spack looks for +``docbook-xml/package.py``. + +Spack uses the directory name as the package name in order to give +packagers more freedom in naming their packages. Package names can +contain letters, numbers, dashes, and underscores. Using a Python +identifier (e.g., a class name or a module name) would make it +difficult to support these options. So, you can name a package +``3proxy`` or ``_foo`` and Spack won't care. It just needs to see +that name in the package spec. + +Package class names +~~~~~~~~~~~~~~~~~~~~~~~ + +Spack loads ``package.py`` files dynamically, and it needs to find a +special class name in the file for the load to succeed. The **class +name** (``Libelf`` in our example) is formed by converting words +separated by `-` or ``_`` in the file name to camel case. If the name +starts with a number, we prefix the class name with ``_``. Here are +some examples: + +================= ================= + Module Name Class Name +================= ================= + ``foo_bar`` ``FooBar`` + ``docbook-xml`` ``DocbookXml`` + ``FooBar`` ``Foobar`` + ``3proxy`` ``_3proxy`` +================= ================= + +In general, you won't have to remember this naming convention because +`spack-create`_ and `spack-edit`_ will generate boilerplate for you, +and you can just fill in the blanks. + + +Adding new versions +------------------------ + +The most straightforward way to add new versions to your package is to +add a line like this in the package class: + +.. code-block:: python + :linenos: + + class Foo(Package): + url = 'http://example.com/foo-1.0.tar.gz' + version('8.2.1', '4136d7b4c04df68b686570afa26988ac') + ... + +Version URLs +~~~~~~~~~~~~~~~~~ + +By default, each version's URL is extrapolated from the ``url`` field +in the package. For example, Spack is smart enough to download +version ``8.2.1.`` of the ``Foo`` package above from +``http://example.com/foo-8.2.1.tar.gz``. + +If spack *cannot* extrapolate the URL from the ``url`` field, or if +the package doesn't have a ``url`` field, you can add a URL explicitly +for a particular version: + +.. code-block:: python + + version('8.2.1', '4136d7b4c04df68b686570afa26988ac', + url='http://example.com/foo-8.2.1-special-version.tar.gz') + +For the URL above, you might have to add an explicit URL because the +version can't simply be substituted in the original ``url`` to +construct the new one for ``8.2.1``. + +Wehn you supply a custom URL for a version, Spack uses that URL +*verbatim* when fetching the version, and will *not* perform +extrapolation. + +Checksums +~~~~~~~~~~~~~~~~~ + +Spack uses a checksum to ensure that the downloaded package version is +not corrupted or compromised. This is especially important when +fetching from insecure sources, like unencrypted http. By default, a +package will *not* be installed if it doesn't pass a checksum test +(though users can overried this with ``spack install --no-checksum``). + +Spack can currently support checksums using the MD5, SHA-1, SHA-224, +SHA-256, SHA-384, and SHA-512 algorithms. + +``spack md5`` +^^^^^^^^^^^^^^^^^^^^^^ + +If you have a single file to checksum, you can use the ``spack md5`` +command to do it. Here's how you might download an archive and get a +checksum for it: + +.. code-block:: sh + + $ curl -O http://exmaple.com/foo-8.2.1.tar.gz' + $ spack md5 foo-8.2.1.tar.gz + 4136d7b4c04df68b686570afa26988ac foo-8.2.1.tar.gz + +Doing this for lots of files, or whenever a new package version is +released, is tedious. See ``spack checksum`` below for an automated +version of this process. + .. _spack-checksum: ``spack checksum`` -~~~~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^^^^ -If you've already created a package and you want to add more version -checksums to it, this is automated with ``spack checksum``. Here's an +If you want to add new versions to a package you've already created, +this is automated with the ``spack checksum`` command. Here's an example for ``libelf``: .. code-block:: sh @@ -231,232 +441,456 @@ example for ``libelf``: How many would you like to checksum? (default is 5, q to abort) -This does the same thing that ``spack create`` did, it just allows you -to go back and create more checksums for an existing package. It -fetches the tarballs you ask for and prints out a dict ready to copy -and paste into your package file: +This does the same thing that ``spack create`` does, but it allows you +to go back and add new vesrions easily as you need them (e.g., as +they're released). It fetches the tarballs you ask for and prints out +a list of ``version`` commands ready to copy/paste into your package +file: .. code-block:: sh ==> Checksummed new versions of libelf: - { - '0.8.13' : '4136d7b4c04df68b686570afa26988ac', - '0.8.12' : 'e21f8273d9f5f6d43a59878dc274fec7', - '0.8.11' : 'e931910b6d100f6caa32239849947fbf', - '0.8.10' : '9db4d36c283d9790d8fa7df1f4d7b4d9', - } + version('0.8.13', '4136d7b4c04df68b686570afa26988ac') + version('0.8.12', 'e21f8273d9f5f6d43a59878dc274fec7') + version('0.8.11', 'e931910b6d100f6caa32239849947fbf') + version('0.8.10', '9db4d36c283d9790d8fa7df1f4d7b4d9') + +By default, Spack will search for new tarball downloads by scraping +the parent directory of the tarball you gave it. So, if your tarball +is at ``http://example.com/downloads/foo-1.0.tar.gz``, Spack will look +in ``http://example.com/downloads/`` for links to additional versions. +If you need to search another path for download links, see the +reference documentation on `attribute_list_url`_ and +`attributee_list_depth`_. + +.. note:: + + * This command assumes that Spack can extrapolate new URLs from an + existing URL in the package, and that Spack can find similar URLs + on a webpage. If that's not possible, you'll need to manually add + ``version`` calls yourself. + + * For ``spack checksum`` to work, Spack needs to be able to + ``import`` your pacakge in Python. That means it can't have any + syntax errors, or the ``import`` will fail. Use this once you've + got your package in working order. + + +.. _vcs-fetch: + +Fetching from VCS Repositories +-------------------------------------- + +For some packages, source code is hosted in a Version Control System +(VCS) repository rather than as a tarball. Packages can be set up to +fetch from a repository instead of a tarball. Currently, Spack +supports fetching with `Git `_, `Mercurial (hg) +`_, and `Subversion (SVN) `_. + +To fetch a package from a source repository, you add a ``version()`` +call to your package with parameters indicating the repository URL and +any branch, tag, or revision to fetch. See below for the paramters +you'll need for each VCS system. + +Repositories and versions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The package author is responsible for coming up with a sensible name +for each version. For example, if you're fetching from a tag like +``v1.0``, you might call that ``1.0``. If you're fetching a nameless +git commit or an older subversion revision, you might give the commit +an intuitive name, like ``dev`` for a development version, or +``some-fancy-new-feature`` if you want to be more specific. + +In general, it's recommended to fetch tags or particular +commits/revisions, NOT branches or the repository mainline, as +branches move forward over time and you aren't guaranteed to get the +same thing every time you fetch a particular version. Life isn't +simple, though, so this is not strictly enforced. + +In some future release, Spack may support extrapolating repository +versions as it does for tarball URLs, but currently this is not +supported. + +.. _git-fetch: + +Git +~~~~~~~~~~~~~~~~~~~~ -You should be able to add these checksums directly to the versions -field in your package. +Git fetching is enabled with the following parameters to ``version``: -Note that for ``spack checksum`` to work, Spack needs to be able to -``import`` your pacakge in Python. That means it can't have any -syntax errors, or the ``import`` will fail. Use this once you've got -your package in working order. + * ``git``: URL of the git repository. + * ``tag``: name of a tag to fetch. + * ``branch``: name of a branch to fetch. + * ``commit``: SHA hash (or prefix) of a commit to fetch. +Only one of ``tag``, ``branch``, or ``commit`` can be used at a time. +Default branch + To fetch a repository's default branch: -Package Files ---------------------------- + .. code-block:: python -It's probably easiest to learn about packages by looking at an -example. Let's take a look at the ``libelf`` package: + class Example(Package): + ... + version('dev', git='https://github.com/example-project/example.git') -.. literalinclude:: ../../../var/spack/packages/libelf/package.py - :lines: 25- - :linenos: + This is not recommended, as the contents of the default branch + change over time. -Directory Structure -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Tags + To fetch from a particular tag, use the ``tag`` parameter along with + ``git``: -A Spack installation directory is structured like a standard UNIX -install prefix (``bin``, ``lib``, ``include``, ``var``, ``opt``, -etc.). Most of the code for Spack lives in ``$SPACK_ROOT/lib/spack``. -Packages themselves live in ``$SPACK_ROOT/var/spack/packages``. + .. code-block:: python -If you ``cd`` to that directory, you will see directories for each -package: + version('1.0.1', git='https://github.com/example-project/example.git', + tag='v1.0.1') -.. command-output:: cd $SPACK_ROOT/var/spack/packages; ls - :shell: - :ellipsis: 10 +Branches + To fetch a particular branch, use ``branch`` instead: + + .. code-block:: python + + version('experimental', git='https://github.com/example-project/example.git', + branch='experimental') + + This is not recommended, as the contents of branches change over + time. + +Commits + Finally, to fetch a particular commit, use ``commit``: + + .. code-block:: python + + version('2014-10-08', git='https://github.com/example-project/example.git', + commit='9d38cd4e2c94c3cea97d0e2924814acc') + + This doesn't have to be a full hash; You can abbreviate it as you'd + expect with git: + + .. code-block:: python + + version('2014-10-08', git='https://github.com/example-project/example.git', + commit='9d38cd') + + It may be useful to provide a saner version for commits like this, + e.g. you might use the date as the version, as done above. Or you + could just use the abbreviated commit hash. It's up to the package + author to decide what makes the most sense. + +Installing +^^^^^^^^^^^^^^ + +You can fetch and install any of the versions above as you'd expect, +by using ``@`` in a spec: + +.. code-block:: sh -Each of these directories contains a file called ``package.py``. This -file is where all the python code for a package goes. For example, -the ``libelf`` package looks like this:: + spack install example@2014-10-08 + +Git and other VCS versions will show up in the list of versions when +a user runs ``spack info ``. + + +.. _hg-fetch: + +Mercurial +~~~~~~~~~~~~~~~~~~~~~~~~~ + +Fetching with mercurial works much like `git `_, but you +use the ``hg`` parameter. + +Default + Add the ``hg`` parameter with no ``revision``: + + .. code-block:: python + + version('hg-head', hg='https://jay.grs.rwth-aachen.de/hg/example') + + Note that this is not recommended; try to fetch a particular + revision instead. + +Revisions + Add ``hg`` and ``revision``parameters: + + .. code-block:: python + + version('1.0', hg='https://jay.grs.rwth-aachen.de/hg/example', + revision='v1.0') + + Unlike ``git``, which has special parameters for different types of + revisions, you can use ``revision`` for branches, tags, and commits + when you fetch with Mercurial. + +As wtih git, you can fetch these versions using the ``spack install +example@`` command-line syntax. + +.. _svn-fetch: + +Subversion +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To fetch with subversion, use the ``svn`` and ``revision`` parameters: + +Head + Simply add an ``svn`` parameter to ``version``: + + .. code-block:: python + + version('svn-head', svn='https://outreach.scidac.gov/svn/libmonitor/trunk') + + This is not recommended, as the head will move forward over time. + +Revisions + To fetch a particular revision, add a ``revision`` to the + version call: + + .. code-block:: python + + version('svn-head', svn='https://outreach.scidac.gov/svn/libmonitor/trunk', + revision=128) + +Subversion branches are handled as part of the directory structure, so +you can check out a branch or tag by changing the ``url``. + +.. _patching: + +Patches +------------------------------------------ + +Depending on the host architecture, package version, known bugs, or +other issues, you may need to patch your software to get it to build +correctly. Like many other package systems, spack allows you to store +patches alongside your package files and apply them to source code +after it's downloaded. + +``patch`` +~~~~~~~~~~~~~~~~~~~~~ + +You can specify patches in your package file with the ``patch()`` +function. ``patch`` looks like this: + +.. code-block:: python + + class Mvapich2(Package): + ... + patch('ad_lustre_rwcontig_open_source.patch', when='@1.9:') + +The first argument can be either a URL or a filename. It specifies a +patch file that should be applied to your source. If the patch you +supply is a filename, then the patch needs to live within the spack +source tree. For example, the patch above lives in a directory +structure like this:: $SPACK_ROOT/var/spack/packages/ - libelf/ + mvapich2/ package.py + ad_lustre_rwcontig_open_source.patch -Alongside the ``package.py`` file, a package may contain extra files (like -patches) that it needs to build. +If you supply a URL instead of a filename, the patch will be fetched +from the URL and then applied to your source code. +.. warning:: -Package Names -~~~~~~~~~~~~~~~~~~ + It is generally better to use a filename rather than a URL for your + patch. Patches fetched from URLs are not currently checksummed, + and adding checksums for them is tedious for the package builder. + File patches go into the spack repository, which gives you git's + integrity guarantees. URL patches may be removed in a future spack + version. -Packages are named after the directory containing ``package.py``. So, -``libelf``'s ``package.py`` lives in a directory called ``libelf``. -The ``package.py`` file contains a class called ``Libelf``, which -extends Spack's ``Package`` class. This is what makes it a Spack -package. The **directory name** is what users need to provide on the -command line. e.g., if you type any of these: +``patch`` can take two options keyword arguments. They are: -.. code-block:: sh +``when`` + If supplied, this is a spec that tells spack when to apply + the patch. If the installed package spec matches this spec, the + patch will be applied. In our example above, the patch is applied + when mvapich is at version ``1.9`` or higher. - $ spack install libelf - $ spack install libelf@0.8.13 +``level`` + This tells spack how to run the ``patch`` command. By default, + the level is 1 and spack runs ``patch -p1``. If level is 2, + spack will run ``patch -p2``, and so on. -Spack sees the package name in the spec and looks for -``libelf/package.py`` in ``var/spack/packages``. Likewise, if you say -``spack install docbook-xml``, then Spack looks for -``docbook-xml/package.py``. + A lot of people are confused by level, so here's a primer. If you + look in your patch file, you may see something like this: -We use the directory name to packagers more freedom when naming their -packages. Package names can contain letters, numbers, dashes, and -underscores. You can name a package ``3proxy`` or ``_foo`` and Spack -lwon't care -- it just needs to see that name in the package spec. -These aren't valid Python module names, but we allow them in Spack and -import ``package.py`` file dynamically. + .. code-block:: diff + :linenos: -Package class names -~~~~~~~~~~~~~~~~~~~~~~~ + --- a/src/mpi/romio/adio/ad_lustre/ad_lustre_rwcontig.c 2013-12-10 12:05:44.806417000 -0800 + +++ b/src/mpi/romio/adio/ad_lustre/ad_lustre_rwcontig.c 2013-12-10 11:53:03.295622000 -0800 + @@ -8,7 +8,7 @@ + * Copyright (C) 2008 Sun Microsystems, Lustre group + */ -The **class name** (``Libelf`` in our example) is formed by converting -words separated by `-` or ``_`` in the file name to camel case. If -the name starts with a number, we prefix the class name with -``_``. Here are some examples: + -#define _XOPEN_SOURCE 600 + +//#define _XOPEN_SOURCE 600 + #include + #include + #include "ad_lustre.h" -================= ================= - Module Name Class Name -================= ================= - ``foo_bar`` ``FooBar`` - ``docbook-xml`` ``DocbookXml`` - ``FooBar`` ``Foobar`` - ``3proxy`` ``_3proxy`` -================= ================= + Lines 1-2 show paths with synthetic ``a/`` and ``b/`` prefixes. These + are placeholders for the two ``mvapich2`` source directories that + ``diff`` compared when it created the patch file. This is git's + default behavior when creating patch files, but other programs may + behave differently. -The class name is needed by Spack to properly import a package, but -not for much else. In general, you won't have to remember this naming -convention because ``spack create`` will generate a boilerplate class -for you, and you can just fill in the blanks. + ``-p1`` strips off the first level of the prefix in both paths, + allowing the patch to be applied from the root of an expanded mvapich2 + archive. If you set level to ``2``, it would strip off ``src``, and + so on. -.. _metadata: + It's generally easier to just structure your patch file so that it + applies cleanly with ``-p1``, but if you're using a patch you didn't + create yourself, ``level`` can be handy. -Package metadata --------------------- -Under the class declaration is a *docstring* (as Python calls it) -enclosed in triple-quotes (``"""``). Spack uses the docstring to -generate the description of the package that is shown when you run -``spack info``. If you don't provide a description, Spack will just -print "None" for the description. +Finding Package Downloads +---------------------------- -In addition to the package description, there are a few fields you'll -need to fill out. They are as follows: +We've already seen the ``homepage`` and ``url`` package attributes: -``homepage`` (required) - This is the URL where you can learn about the package and get - information. It is displayed to users when they run ``spack info``. +.. code-block:: python + :linenos: -``url`` (required) - This is the URL where you can download a distribution tarball of - the pacakge's source code. + from spack import * -``versions`` (optional) - This is a `dictionary - `_ - mapping versions to MD5 hashes. Spack uses the hashes to checksum - archives when it downloads a particular version. + class Mpich(Package): + """MPICH is a high performance and widely portable implementation of + the Message Passing Interface (MPI) standard.""" + homepage = "http://www.mpich.org" + url = "http://www.mpich.org/static/downloads/3.0.4/mpich-3.0.4.tar.gz" -``parallel`` (optional) Whether make should be parallel by default. - By default, this is ``True``, and package authors need to call - ``make(parallel=False)`` to override. If you set this to ``False`` - at the package level then each call to ``make`` will be sequential - by default, and users will have to call ``make(parallel=True)`` to - override it. +These are class-level attributes used by Spack to show users +information about the package, and to determine where to download its +source code. -``versions`` is optional but strongly recommended. Spack will warn -usrs if they try to install a version (e.g., ``libelf@0.8.10`` for -which there is not a checksum available. They can force it to -download the new version and install, but it's better to provide -checksums so users don't have to install from an unchecked archive. +Spack uses the tarball URL to extrapolate where to find other tarballs +of the same package (e.g. in `spack-checksum`_, but this does not +always work. This section covers ways you can tell Spack to find +tarballs elsewhere. +.. _attribute_list_url: -Install method -~~~~~~~~~~~~~~~~~~~~~~~ +``list_url`` +~~~~~~~~~~~~~~~~~~~~~ -The last element of the ``libelf`` package is its ``install()`` -method. This is where the real work of installation happens, and -it's the main part of the package you'll need to customize for each -piece of software. +When spack tries to find available versions of packages (e.g. with +`spack-checksum`_), it spiders the parent directory of the tarball in +the ``url`` attribute. For example, for libelf, the url is: -.. literalinclude:: ../../../var/spack/packages/libelf/package.py - :start-after: 0.8.12 +.. code-block:: python + + url = "http://www.mr511.de/software/libelf-0.8.13.tar.gz" + +Spack spiders ``http://www.mr511.de/software/`` to find similar +tarball links and ultimately to make a list of available versions of +``libelf``. + +For many packages, the tarball's parent directory may be unlistable, +or it may not contain any links to source code archives. In fact, +many times additional package downloads aren't even available in the +same directory as the download URL. + +For these, you can specify a separate ``list_url`` indicating the page +to search for tarballs. For example, ``libdwarf`` has the homepage as +the ``list_url``, because that is where links to old versions are: + +.. code-block:: python :linenos: -``install`` takes a ``spec``: a description of how the package should -be built, and a ``prefix``: the path to the directory where the -software should be installed. + class Libdwarf(Package): + homepage = "http://www.prevanders.net/dwarf.html" + url = "http://www.prevanders.net/libdwarf-20130729.tar.gz" + list_url = homepage -:ref:`Writing the install method ` is documented in -detail later, but in general, the ``install()`` method should look -familiar. ``libelf`` uses autotools, so the package first calls -``configure``, passing the prefix and some other package-specific -arguments. It then calls ``make`` and ``make install``. +.. _attribute_list_depth: -Spack provides wrapper functions for ``configure`` and ``make`` so -that you can call them in a similar way to how you'd call a shell -comamnd. In reality, these are Python functions. Spack provides -these functions to make writing packages more natural. See the section -on :ref:`shell wrappers `. +``list_depth`` +~~~~~~~~~~~~~~~~~~~~~ + +``libdwarf`` and many other packages have a listing of available +verisons on a single webpage, but not all do. For example, ``mpich`` +has a tarball URL that looks like this: + + url = "http://www.mpich.org/static/downloads/3.0.4/mpich-3.0.4.tar.gz" + +But its downloads are in many different subdirectories of +``http://www.mpich.org/static/downloads/``. So, we need to add a +``list_url`` *and* a ``list_depth`` attribute: + +.. code-block:: python + :linenos: + + class Mpich(Package): + homepage = "http://www.mpich.org" + url = "http://www.mpich.org/static/downloads/3.0.4/mpich-3.0.4.tar.gz" + list_url = "http://www.mpich.org/static/downloads/" + list_depth = 2 + +By default, Spack only looks at the top-level page available at +``list_url``. ``list_depth`` tells it to follow up to 2 levels of +links from the top-level page. Note that here, this implies two +levels of subdirectories, as the ``mpich`` website is structured much +like a filesystem. But ``list_depth`` really refers to link depth +when spidering the page. + +.. _attribute_parallel: + +Parallel Builds +------------------ + +By default, Spack will invoke ``make()`` with a ``-j `` +argument, so that builds run in parallel. It figures out how many +jobs to run by determining how many cores are on the host machine. +Specifically, it uses the number of CPUs reported by Python's +`multiprocessing.cpu_count() +`_. + +If a package does not build properly in parallel, you can override +this setting by adding ``parallel = False`` to your package. For +example, OpenSSL's build does not work in parallel, so its package +looks like this: +.. code-block:: python + :emphasize-lines: 8 + :linenos: -Optional Package Attributes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + class Openssl(Package): + homepage = "http://www.openssl.org" + url = "http://www.openssl.org/source/openssl-1.0.1h.tar.gz" -In addition to ``homepage``, ``url``, and ``versions``, there are some -other useful attributes you can add to your package file. + version('1.0.1h', '8d6d684a9430d5cc98a62a5d8fbda8cf') + depends_on("zlib") -``list_url`` -^^^^^^^^^^^^^^^^^^ + parallel = False -When spack tries to find available versions of packages (e.g. in -``spack checksum``), by default it looks in the parent directory of -the tarball in the package's ``url``. For example, for libelf, the -url is: +Similarly, you can disable parallel builds only for specific make +commands, as ``libdwarf`` does: -.. literalinclude:: ../../../var/spack/packages/libelf/package.py - :start-after: homepage - :end-before: versions +.. code-block:: python + :emphasize-lines: 9, 12 + :linenos: -Spack will try to fetch the URL ``http://www.mr511.de/software/``, -scrape the page, and use any links that look like the tarball URL to -find other available versions. For many packages, the tarball's -parent directory may be unlistable, or it may not contain any links to -source code archives. For these, you can specify a separate -``list_url`` indicating the page to search for tarballs. For example, -``libdwarf`` has the homepage as the ``list_url``: + class Libelf(Package): + ... -.. literalinclude:: ../../../var/spack/packages/libdwarf/package.py - :start-after: Libdwarf - :end-before: versions + def install(self, spec, prefix): + configure("--prefix=" + prefix, + "--enable-shared", + "--disable-dependency-tracking", + "--disable-debug") + make() -``list_depth`` -^^^^^^^^^^^^^^^^^^^^ - -Some packages may not have a listing of available verisons on a single -page. For these, you can specify a ``list_depth`` indicating that -Spack should follow links from the ``list_url`` up to a particular -depth. Spack will follow links and search each page reachable from -the ``list_url`` for tarball links. For example, ``mpich`` archives -are stored in a directory tree of versions, so the package looks like -this: + # The mkdir commands in libelf's install can fail in parallel + make("install", parallel=False) -.. literalinclude:: ../../../var/spack/packages/mpich/package.py - :start-after: homepage - :end-before: versions +The first make will run in parallel here, but the second will not. If +you set ``parallel`` to ``False`` at the package level, then each call +to ``make()`` will be sequential by default, but packagers can call +``make(parallel=True)`` to override it. .. _dependencies: @@ -464,26 +898,36 @@ this: Dependencies ------------------------------ -We've now covered how to build a simple package, but what if one -package relies on another package to build? How do you express that -in a package file? And how do you refer to the other package in the -build script for your own package? +We've covered how to build a simple package, but what if one package +relies on another package to build? How do you express that in a +package file? And how do you refer to the other package in the build +script for your own package? Spack makes this relatively easy. Let's take a look at the ``libdwarf`` package to see how it's done: -.. literalinclude:: ../../../var/spack/packages/libdwarf/package.py +.. code-block:: python + :emphasize-lines: 9 :linenos: - :start-after: dwarf_dirs - :end-before: def clean - :emphasize-lines: 10 - :append: ... -``depends_on`` + class Libdwarf(Package): + homepage = "http://www.prevanders.net/dwarf.html" + url = "http://www.prevanders.net/libdwarf-20130729.tar.gz" + list_url = homepage + + version('20130729', '4cc5e48693f7b93b7aa0261e63c0e21d') + ... + + depends_on("libelf") + + def install(self, spec, prefix): + ... + +``depends_on()`` ~~~~~~~~~~~~~~~~~~~~~ -The ``depends_on('libelf')`` call on line 10 tells Spack that it needs -to build and install the ``libelf`` package before it builds +The highlighted ``depends_on('libelf')`` call tells Spack that it +needs to build and install the ``libelf`` package before it builds ``libdwarf``. This means that in your ``install()`` method, you are guaranteed that ``libelf`` has been built and installed successfully, so you can rely on it for your libdwarf build. @@ -492,28 +936,37 @@ Dependency specs ~~~~~~~~~~~~~~~~~~~~~~ ``depends_on`` doesn't just take the name of another package. It -actually takes a full spec. This means that you can restrict the -versions or other configuration options of ``libelf`` that -``libdwarf`` will build with. Here's an example. Suppose that in the -``libdwarf`` package you wrote: +takes a full spec. This means that you can restrict the versions or +other configuration options of ``libelf`` that ``libdwarf`` will build +with. Here's an example. Suppose that in the ``libdwarf`` package +you write: .. code-block:: python depends_on("libelf@0.8:") -Now ``libdwarf`` will only ever build with ``libelf`` version ``0.8`` -or higher. If some versions of ``libelf`` are installed but they are -all older than this, then Spack will build a new version of ``libelf`` -that satisfies the spec's version constraint, and it will build -``libdwarf`` with that one. You could just as easily provide a -version range (e.g., ``0.8.2:0.8.4``) or a variant constraint -(e.g.. ``+debug``) to control how dependencies should be built. +Now ``libdwarf`` will require a version of ``libelf`` version ``0.8`` +or higher in order to build. If some versions of ``libelf`` are +installed but they are all older than this, then Spack will build a +new version of ``libelf`` that satisfies the spec's version +constraint, and it will build ``libdwarf`` with that one. You could +just as easily provide a version range: + +.. code-block:: python + + depends_on("libelf@0.8.2:0.8.4:") + +Or a requirement for a particular variant: -Note that both users and package authors can use the same spec syntax -to refer to different package configurations. Users use the spec -syntax on the command line to find installed packages or to install -packages with particular constraints, and package authors can use it -to describe relationships between packages. +.. code-block:: python + + depends_on("libelf@0.8+debug") + +Both users *and* package authors can use the same spec syntax to refer +to different package configurations. Users use the spec syntax on the +command line to find installed packages or to install packages with +particular constraints, and package authors can use specs to describe +relationships between packages. .. _virtual-dependencies: @@ -523,39 +976,48 @@ Virtual dependencies In some cases, more than one package can satisfy another package's dependency. One way this can happen is if a pacakge depends on a particular *interface*, but there are multiple *implementations* of -the interface, and the package could be built with either. A *very* -common interface in HPC is the `Message Passing Interface (MPI) +the interface, and the package could be built with any of them. A +*very* common interface in HPC is the `Message Passing Interface (MPI) `_, which is used in many large-scale parallel applications. MPI has several different implementations (e.g., `MPICH `_, `OpenMPI `_, and `MVAPICH `_) and scientific -applicaitons can be built with any one of these. Complicating -matters, MPI does not have a standardized ABI, so a package built with -one implementation cannot be relinked with another implementation. +applications can be built with any one of them. Complicating matters, +MPI does not have a standardized ABI, so a package built with one +implementation cannot simply be relinked with another implementation. Many pacakage managers handle interfaces like this by requiring many -similar pacakge files, e.g., ``foo``, ``foo-mvapich``, ``foo-mpich``, +similar package files, e.g., ``foo``, ``foo-mvapich``, ``foo-mpich``, but Spack avoids this explosion of package files by providing support for *virtual dependencies*. - ``provides`` ~~~~~~~~~~~~~~~~~~~~~ -In Spack, ``mpi`` is a *virtual package*. A package can depend on it -just like any other package, by supplying a ``depends_on`` call in the -package definition. In ``mpileaks``, this looks like so: +In Spack, ``mpi`` is handled as a *virtual package*. A package like +``mpileaks`` can depend on it just like any other package, by +supplying a ``depends_on`` call in the package definition. For example: + +.. code-block:: python + :linenos: + :emphasize-lines: 7 + + class Mpileaks(Package): + homepage = "https://github.com/hpc/mpileaks" + url = "https://github.com/hpc/mpileaks/releases/download/v1.0/mpileaks-1.0.tar.gz" -.. literalinclude:: ../../../var/spack/packages/mpileaks/package.py - :start-after: url - :end-before: install + version('1.0', '8838c574b39202a57d7c2d68692718aa') -Here, ``callpath`` is an actual pacakge, but there is no package file -for ``mpi``, so we say it is a *virtual* package. The syntax of -``depends_on``, however, is the same for both.. If we look inside the -package file of an MPI implementation, say MPICH, we'll see something -like this: + depends_on("mpi") + depends_on("adept-utils") + depends_on("callpath") + +Here, ``callpath`` and ``adept-utils`` are concrete pacakges, but +there is no actual package file for ``mpi``, so we say it is a +*virtual* package. The syntax of ``depends_on``, is the same for +both. If we look inside the package file of an MPI implementation, +say MPICH, we'll see something like this: .. code-block:: python @@ -564,24 +1026,30 @@ like this: ... The ``provides("mpi")`` call tells Spack that the ``mpich`` package -can be substituted whenever a package says it depends on ``mpi``. +can be used to satisfy the dependency of any package that +``depends_on('mpi')``. + +Versioned Interfaces +~~~~~~~~~~~~~~~~~~~~~~ -Just as you can pass a spec to ``depends_on``, you can pass a spec to -``provides`` to add constraints. This allows Spack to support the +Just as you can pass a spec to ``depends_on``, so can you pass a spec +to ``provides`` to add constraints. This allows Spack to support the notion of *versioned interfaces*. The MPI standard has gone through -many revisions, each with new functions added. Some packages may -require a recent implementation that supports MPI-3 fuctions, but some -MPI versions may only provide up to MPI-2. You can indicate this by -adding a version constraint to the spec passed to ``provides``: +many revisions, each with new functions added, and each revision of +the standard has a version number. Some packages may require a recent +implementation that supports MPI-3 fuctions, but some MPI versions may +only provide up to MPI-2. Others may need MPI 2.1 or higher. You can +indicate this by adding a version constraint to the spec passed to +``provides``: .. code-block:: python provides("mpi@:2") -Suppose that the above restriction is in the ``mpich2`` package. This -says that ``mpich2`` provides MPI support *up to* version 2, but if a -package ``depends_on("mpi@3")``, then Spack will *not* build with ``mpich2`` -for the MPI implementation. +Suppose that the above ``provides`` call is in the ``mpich2`` package. +This says that ``mpich2`` provides MPI support *up to* version 2, but +if a package ``depends_on("mpi@3")``, then Spack will *not* build that +package with ``mpich2``. ``provides when`` ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -589,28 +1057,34 @@ for the MPI implementation. The same package may provide different versions of an interface depending on *its* version. Above, we simplified the ``provides`` call in ``mpich`` to make the explanation easier. In reality, this is -how ``mpich`` declares the virtual packages it provides: +how ``mpich`` calls ``provides``: .. code-block:: python provides('mpi@:3', when='@3:') provides('mpi@:1', when='@1:') -The ``when`` argument to ``provides`` (a `keyword argument -`_ -for those not familiar with Python) allows you to specify optional -constraints on the *calling* package. The calling package will only -provide the declared virtual spec when *it* matches the constraints in -the when clause. Here, when ``mpich`` is at version 3 or higher, it -provides MPI up to version 3. When ``mpich`` is at version 1 or higher, -it provides the MPI virtual pacakge at version 1. - -The ``when`` qualifier will ensure that Spack selects a suitably high -version of ``mpich`` to match another package that ``depends_on`` a -particular version of MPI. It will also prevent a user from building -with too low a version of ``mpich``. For example, suppose the package -``foo`` declares that it ``depends_on('mpi@2')``, and a user invokes -``spack install`` like this: +The ``when`` argument to ``provides`` allows you to specify optional +constraints on the *providing* package, or the *provider*. The +provider only provides the declared virtual spec when *it* matches +the constraints in the when clause. Here, when ``mpich`` is at +version 3 or higher, it provides MPI up to version 3. When ``mpich`` +is at version 1 or higher, it provides the MPI virtual pacakge at +version 1. + +The ``when`` qualifier ensures that Spack selects a suitably high +version of ``mpich`` to satisfy some other package that ``depends_on`` +a particular version of MPI. It will also prevent a user from +building with too low a version of ``mpich``. For example, suppose +the package ``foo`` declares this: + +.. code-block:: python + + class Foo(Package): + ... + depends_on('mpi@2') + +Suppose a user invokes ``spack install`` like this: .. code-block:: sh @@ -657,6 +1131,18 @@ DAG, based on the constraints above:: ^libelf@0.8.11 ^mpi + +.. graphviz:: + + digraph { + mpileaks -> mpi + mpileaks -> "callpath@1.0+debug" -> mpi + "callpath@1.0+debug" -> dyninst + dyninst -> libdwarf -> "libelf@0.8.11" + dyninst -> "libelf@0.8.11" + } + + This diagram shows a spec DAG output as a tree, where successive levels of indentation represent a depends-on relationship. In the above DAG, we can see some packages annotated with their constraints, @@ -675,12 +1161,22 @@ the user runs ``spack install`` and the time the ``install()`` method is called. The concretized version of the spec above might look like this:: - mpileaks@2.3%gcc@4.7.3=macosx_10.8_x86_64 - ^callpath@1.0%gcc@4.7.3+debug=macosx_10.8_x86_64 - ^dyninst@8.1.2%gcc@4.7.3=macosx_10.8_x86_64 - ^libdwarf@20130729%gcc@4.7.3=macosx_10.8_x86_64 - ^libelf@0.8.11%gcc@4.7.3=macosx_10.8_x86_64 - ^mpich@3.0.4%gcc@4.7.3=macosx_10.8_x86_64 + mpileaks@2.3%gcc@4.7.3=linux-ppc64 + ^callpath@1.0%gcc@4.7.3+debug=linux-ppc64 + ^dyninst@8.1.2%gcc@4.7.3=linux-ppc64 + ^libdwarf@20130729%gcc@4.7.3=linux-ppc64 + ^libelf@0.8.11%gcc@4.7.3=linux-ppc64 + ^mpich@3.0.4%gcc@4.7.3=linux-ppc64 + +.. graphviz:: + + digraph { + "mpileaks@2.3\n%gcc@4.7.3\n=linux-ppc64" -> "mpich@3.0.4\n%gcc@4.7.3\n=linux-ppc64" + "mpileaks@2.3\n%gcc@4.7.3\n=linux-ppc64" -> "callpath@1.0\n%gcc@4.7.3+debug\n=linux-ppc64" -> "mpich@3.0.4\n%gcc@4.7.3\n=linux-ppc64" + "callpath@1.0\n%gcc@4.7.3+debug\n=linux-ppc64" -> "dyninst@8.1.2\n%gcc@4.7.3\n=linux-ppc64" + "dyninst@8.1.2\n%gcc@4.7.3\n=linux-ppc64" -> "libdwarf@20130729\n%gcc@4.7.3\n=linux-ppc64" -> "libelf@0.8.11\n%gcc@4.7.3\n=linux-ppc64" + "dyninst@8.1.2\n%gcc@4.7.3\n=linux-ppc64" -> "libelf@0.8.11\n%gcc@4.7.3\n=linux-ppc64" + } Here, all versions, compilers, and platforms are filled in, and there is a single version (no version ranges) for each package. All @@ -707,186 +1203,39 @@ running ``spack spec``. For example: ^libdwarf ^libelf - dyninst@8.0.1%gcc@4.7.3=macosx_10.8_x86_64 - ^libdwarf@20130729%gcc@4.7.3=macosx_10.8_x86_64 - ^libelf@0.8.13%gcc@4.7.3=macosx_10.8_x86_64 - - -.. _install-environment: - -Install environment --------------------------- - -In general, you should not have to do much differently in your install -method than you would when installing a pacakge on the command line. -Spack tries to set environment variables and modify compiler calls so -that it *appears* to the build system that you're building with a -standard system install of everything. Obviously that's not going to -cover *all* build systems, but it should make it easy to port packages -that use standard build systems to Spack. - -There are a couple of things that Spack does that help with this: - - -Compiler interceptors -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Spack intercepts the compiler calls that your build makes. If your -build invokes ``cc``, then Spack intercepts the ``cc`` call with its -own wrapper script, and it inserts ``-I``, ``-L``, and ``-Wl,-rpath`` -options for all dependencies before invoking the actual compiler. - -An example of this would be the ``libdwarf`` build, which has one -dependency: ``libelf``. Every call to ``cc`` in the ``libdwarf`` -build will have ``-I$LIBELF_PREFIX/include``, -``-L$LIBELF_PREFIX/lib``, and ``-Wl,-rpath=$LIBELF_PREFIX/lib`` -inserted on the command line. This is done transparently to the -project's build system, which will just think it's using a system -where ``libelf`` is readily available. Because of this, you **do -not** have to insert extra ``-I``, ``-L``, etc. on the command line. - -An exmaple of this is the ``libdwarf`` package. You'll notice that it -never mentions ``libelf`` outside of the ``depends_on('libelf')`` -call, but it still manages to find its dependency library and build. -This is due to Spack's compiler interceptors. - - - -Environment variables -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Spack sets a number of standard environment variables so that build -systems use its compiler wrappers for their builds. The standard -enviroment variables are: - - ======================= ============================= - Variable Purpose - ======================= ============================= - ``CC`` C compiler - ``CXX`` C++ compiler - ``F77`` Fortran 77 compiler - ``FC`` Fortran 90 and above compiler - ``CMAKE_PREFIX_PATH`` Path to dependency prefixes for CMake - ======================= ============================= - -All of these are standard variables respected by most build systems, -so if your project uses something like ``autotools`` or ``CMake``, -then it should pick them up automatically when you run ``configure`` -or ``cmake`` in your ``install()`` function. Many traditional builds -using GNU Make and BSD make also respect these variables, so they may -work with these systems, as well. + dyninst@8.0.1%gcc@4.7.3=linux-ppc64 + ^libdwarf@20130729%gcc@4.7.3=linux-ppc64 + ^libelf@0.8.13%gcc@4.7.3=linux-ppc64 -If your build systm does *not* pick these variables up from the -environment automatically, then you can simply pass them on the -command line or use a patch as part of your build process to get the -correct compilers into the project's build system. +This is useful when you want to know exactly what Spack will do when +you ask for a particular spec. -Forked process -~~~~~~~~~~~~~~~~~~~~~ - -To give packages free reign over how they install things, how they -modify the environemnt, and how they use Spack's internal APIs, we -fork a new process each time we invoke ``install()``. This allows -packages to have their own completely sandboxed build environment, -without impacting other jobs that the main Spack process runs. - -.. _patching: +.. _install-method: -Patches +Implementing the ``install`` method ------------------------------------------ -Depending on the host architecture, package version, known bugs, or -other issues, you may need to patch your software to get it to build -correctly. Like many other package systems, spack allows you to store -patches alongside your package files and apply them to source code -after it's downloaded. - -``patch`` -~~~~~~~~~~~~~~~~~~~~~ - -You can specify patches in your package file with the ``patch()`` -function. ``patch`` looks like this: - -.. code-block:: python - - class Mvapich2(Package): - ... - patch('ad_lustre_rwcontig_open_source.patch', when='@1.9:') - -The first argument can be either a URL or a filename. It specifies a -patch file that should be applied to your source. If the patch you -supply is a filename, then the patch needs to live within the spack -source tree. For example, the patch above lives in a directory -structure like this:: - - $SPACK_ROOT/var/spack/packages/ - mvapich2/ - package.py - ad_lustre_rwcontig_open_source.patch - -If you supply a URL instead of a filename, the patch will be fetched -from the URL and then applied to your source code. - -.. warning:: - - It is generally better to use a filename rather than a URL for your - patch. Patches fetched from URLs are not currently checksummed, - and adding checksums for them is tedious for the package builder. - File patches go into the spack repository, which gives you git's - integrity guarantees. URL patches may be removed in a future spack - version. - -``patch`` can take two options keyword arguments. They are: - -``when`` - If supplied, this is a spec that tells spack when to apply - the patch. If the installed package spec matches this spec, the - patch will be applied. In our example above, the patch is applied - when mvapich is at version ``1.9`` or higher. - -``level`` - This tells spack how to run the ``patch`` command. By default, - the level is 1 and spack runs ``patch -p1``. If level is 2, - spack will run ``patch -p2``, and so on. - -A lot of people are confused by level, so here's a primer. If you -look in your patch file, you may see something like this: - -.. code-block:: diff - - --- a/src/mpi/romio/adio/ad_lustre/ad_lustre_rwcontig.c 2013-12-10 12:05:44.806417000 -0800 - +++ b/src/mpi/romio/adio/ad_lustre/ad_lustre_rwcontig.c 2013-12-10 11:53:03.295622000 -0800 - @@ -8,7 +8,7 @@ - * Copyright (C) 2008 Sun Microsystems, Lustre group - */ - - -#define _XOPEN_SOURCE 600 - +//#define _XOPEN_SOURCE 600 - #include - #include - #include "ad_lustre.h" +The last element of a package is its ``install()`` method. This is +where the real work of installation happens, and it's the main part of +the package you'll need to customize for each piece of software. -The first two lines show paths with synthetic ``a/`` and ``b/`` -prefixes. These are placeholders for the two ``mvapich2`` source -directories that ``diff`` compared when it created the patch file. -This is git's default behavior when creating patch files, but other -programs may behave differently. +.. literalinclude:: ../../../var/spack/packages/libelf/package.py + :start-after: 0.8.12 + :linenos: -``-p1`` strips off the first level of the prefix in both paths, -allowing the patch to be applied from the root of an expanded mvapich2 -archive. If you set level to ``2``, it would strip off ``src``, and -so on. +``install`` takes a ``spec``: a description of how the package should +be built, and a ``prefix``: the path to the directory where the +software should be installed. -It's generally easier to just structure your patch file so that it -applies cleanly with ``-p1``, but if you're using a URL to a patch you -didn't create yourself, ``level`` can be handy. +Spack provides wrapper functions for ``configure`` and ``make`` so +that you can call them in a similar way to how you'd call a shell +comamnd. In reality, these are Python functions. Spack provides +these functions to make writing packages more natural. See the section +on :ref:`shell wrappers `. -.. _install-method: -Implementing the ``install`` method ------------------------------------------- Now that the metadata is out of the way, we can move on to the ``install()`` method. When a user runs ``spack install``, Spack @@ -935,6 +1284,153 @@ on the version, compiler, dependencies, etc. that your package is built with. These parameters give you access to this type of information. +.. _install-environment: + +The Install environment +-------------------------- + +In general, you should not have to do much differently in your install +method than you would when installing a pacakge on the command line. +In fact, you may need to do *less* than you would on the command line. + +Spack tries to set environment variables and modify compiler calls so +that it *appears* to the build system that you're building with a +standard system install of everything. Obviously that's not going to +cover *all* build systems, but it should make it easy to port packages +to Spack if they use a standard build system. Usually with autotools +or cmake, building and installing is easy. With builds that use +custom Makefiles, you may need to add logic to modify the makefiles. + +The remainder of the section covers the way Spack's build environment +works. + +Environment variables +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Spack sets a number of standard environment variables that serve two +purposes: + + #. Make build systems use Spack's compiler wrappers for their builds. + #. Allow build systems to find dependencies more easily + +The Compiler enviroment variables that Spack sets are: + + ============ =============================== + Variable Purpose + ============ =============================== + ``CC`` C compiler + ``CXX`` C++ compiler + ``F77`` Fortran 77 compiler + ``FC`` Fortran 90 and above compiler + ============ =============================== + +All of these are standard variables respected by most build systems. +If your project uses ``autotools`` or ``CMake``, then it should pick +them up automatically when you run ``configure`` or ``cmake`` in the +``install()`` function. Many traditional builds using GNU Make and +BSD make also respect these variables, so they may work with these +systems. + +If your build system does *not* automatically pick these variables up +from the environment, then you can simply pass them on the command +line or use a patch as part of your build process to get the correct +compilers into the project's build system. There are also some file +editing commands you can use -- these are described later in +`filtering-files`_. + +In addition to the compiler variables, these variables are set before +entering ``install()`` so that packages can locate dependencies +easily: + + ======================= ============================= + ``PATH`` Set to point to ``/bin`` directories of dpeendencies + ``CMAKE_PREFIX_PATH`` Path to dependency prefixes for CMake + ``PKG_CONFIG_PATH`` Path to any pkgconfig directories for dependencies + ======================= ============================= + +``PATH`` is set up to point to dependencies ``/bin`` directories so +that you can use tools installed by dependency packages at build time. +For example, ``$MPICH_ROOT/bin/mpicc`` is frequently used by dependencies of +``mpich``. + +``CMAKE_PREFIX_PATH`` contains a colon-separated list of prefixes +where ``cmake`` will search for dependency libraries and headers. +This causes all standard CMake find commands to look in the paths of +your dependencies, so you *do not* have to manually specify arguments +like ``-D DEPENDENCY_DIR=/path/to/dependency`` to ``cmake``. More on +this is `in the CMake documentation `_. + +``PKG_CONFIG_PATH`` is for packages that attempt to discover +dependencies using the GNU ``pkg-config`` tool. It is similar to +``CMAKE_PREFIX_PATH`` in that it allows a build to automatically +discover its dependencies. + + +Compiler interceptors +~~~~~~~~~~~~~~~~~~~~~~~~~ + +As mentioned, ``CC``, ``CXX``, ``F77``, and ``FC`` are set to point to +Spack's compiler wrappers. These are simply called ``cc``, ``c++``, +``f77``, and ``f90``, and they live in ``$SPACK_ROOT/lib/spack/env``. + +``$SPACK_ROOT/lib/spack/env`` is added first in the ``PATH`` +environment variable when ``install()`` runs so that system compilers +are not picked up instead. + +All of these compiler wrappers point to a single compiler wrapper +script that figures out which *real* compiler it should be building +with. This comes either from spec `concretization +`_ or from a user explicitly asking for a +particular compiler using, e.g., ``%intel`` on the command line. + +In addition to invoking the right compiler, the compiler wrappers add +flags to the compile line so that dependencies can be easily found. +These flags are added for each dependency, if they exist: + +Compile-time library search paths + * ``-L$dep_prefix/lib`` + * ``-L$dep_prefix/lib64`` +Runtime library search paths (RPATHs) + * ``-Wl,-rpath=$dep_prefix/lib`` + * ``-Wl,-rpath=$dep_prefix/lib64`` +Include search paths + * ``-I$dep_prefix/include`` + +An example of this would be the ``libdwarf`` build, which has one +dependency: ``libelf``. Every call to ``cc`` in the ``libdwarf`` +build will have ``-I$LIBELF_PREFIX/include``, +``-L$LIBELF_PREFIX/lib``, and ``-Wl,-rpath=$LIBELF_PREFIX/lib`` +inserted on the command line. This is done transparently to the +project's build system, which will just think it's using a system +where ``libelf`` is readily available. Because of this, you **do +not** have to insert extra ``-I``, ``-L``, etc. on the command line. + +Another useful consequence of this is that you often do *not* have to +add extra parameters on the ``configure`` line to get autotools to +find dependencies. The ``libdwarf`` install method just calls +configure like this: + +.. code-block:: python + + configure("--prefix=" + prefix) + +Because of the ``-L`` and ``-I`` arguments, configure will +successfully find ``libdwarf.h`` and ``libdwarf.so``, without the +packager having to provide ``--with-libdwarf=/path/to/libdwarf`` on +the command line. + +Forking ``install()`` +~~~~~~~~~~~~~~~~~~~~~ + +To give packagers free reign over their install environemnt, Spack +forks a new process each time it invokes a package's ``install()`` +method. This allows packages to have their own completely sandboxed +build environment, without impacting other jobs that the main Spack +process runs. Packages are free to change the environment or to +modify Spack internals, because each ``install()`` call has its own +dedicated process. + + .. _prefix-objects: Prefix objects @@ -1236,7 +1732,7 @@ build system. .. _pacakge-lifecycle: -The package build process +Useful Packaging Commands --------------------------------- When you are building packages, you will likely not get things @@ -1250,7 +1746,7 @@ want to clean up the temporary directory, or if the package isn't downloading properly, you might want to run *only* the ``fetch`` stage of the build. -A typical package development cycle might look like this: +A typical package workflow might look like this: .. code-block:: sh @@ -1328,13 +1824,109 @@ recover disk space if temporary files from interrupted or failed installs accumulate in the staging area. -Dirty Installs -~~~~~~~~~~~~~~~~~~~ +Keeping the stage directory on success +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ By default, ``spack install`` will delete the staging area once a -pacakge has been successfully built and installed, *or* if an error -occurs during the build. Use ``spack install --dirty`` or ``spack -install -d`` to leave the build directory intact. This allows you to -inspect the build directory and potentially fix the build. You can -use ``purge`` or ``clean`` later to get rid of the unwanted temporary -files. +pacakge has been successfully built and installed. Use +``--keep-stage`` to leave the build directory intact: + +.. code-block:: sh + + spack install --keep-stage + +This allows you to inspect the build directory and potentially debug +the build. You can use ``purge`` or ``clean`` later to get rid of the +unwanted temporary files. + + +Keeping the install prefix on failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +By default, ``spack install`` will delete any partially constructed +install prefix if anything fails during ``install()``. If you want to +keep the prefix anyway (e.g. to diagnose a bug), you can use +``--keep-prefix``: + +.. code-block:: sh + + spack install --keep-prefix + +Note that this may confuse Spack into thinking that the package has +been installed properly, so you may need to use ``spack uninstall -f`` +to get rid of the install prefix before you build again: + +.. code-block:: sh + + spack uninstall -f + + +Interactive Shell Support +-------------------------- + +Spack provides some limited shell support to make life easier for +packagers. You can enable these commands by sourcing a setup file in +the ``/share/spack`` directory. For ``bash`` or ``ksh``, run:: + + . $SPACK_ROOT/share/spack/setup-env.sh + +For ``csh`` and ``tcsh`` run: + + setenv SPACK_ROOT /path/to/spack + source $SPACK_ROOT/share/spack/setup-env.csh + +``spack cd`` will then be available. + + +``spack cd`` +~~~~~~~~~~~~~~~~~ + +``spack cd`` allows you to quickly cd to pertinent directories in Spack. +Suppose you've staged a package but you want to modify it before you +build it: + +.. code-block:: sh + + $ spack stage libelf + ==> Trying to fetch from http://www.mr511.de/software/libelf-0.8.13.tar.gz + ######################################################################## 100.0% + ==> Staging archive: /Users/gamblin2/src/spack/var/spack/stage/libelf@0.8.13%gcc@4.8.3=linux-ppc64/libelf-0.8.13.tar.gz + ==> Created stage in /Users/gamblin2/src/spack/var/spack/stage/libelf@0.8.13%gcc@4.8.3=linux-ppc64. + $ spack cd libelf + $ pwd + /Users/gamblin2/src/spack/var/spack/stage/libelf@0.8.13%gcc@4.8.3=linux-ppc64/libelf-0.8.13 + +``spack cd`` here changed he current working directory to the +directory containing theexpanded ``libelf`` source code. There are a +number of other places you can cd to in the spack directory hierarchy: + +.. command-output:: spack cd -h + +Some of these change directory into package-specific locations (stage +directory, install directory, package directory) and others change to +core spack locations. For example, ``spack cd -m`` will take you to +the main python source directory of your spack install. + + +``spack location`` +~~~~~~~~~~~~~~~~~~~~~~ + +``spack location`` is the same as ``spack cd`` but it does not require +shell support. It simply prints out the path you ask for, rather than +cd'ing to it. In bash, this:: + + cd $(spack location -b ) + +is the same as:: + + spack cd -b + +``spack location`` is intended for use in scripts or makefiles that +need to know where packages are installed. e.g., in a makefile you +might write: + +.. code-block:: makefile + + DWARF_PREFIX = $(spack location -i libdwarf) + CXXFLAGS += -I$DWARF_PREFIX/include + CXXFLAGS += -L$DWARF_PREFIX/lib diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index f1a16fdea1..160f84f9df 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -115,13 +115,13 @@ class Package(object): 2. The class name, "Cmake". This is formed by converting `-` or ``_`` in the module name to camel case. If the name starts with - a number, we prefix the class name with ``Num_``. Examples: + a number, we prefix the class name with ``_``. Examples: Module Name Class Name foo_bar FooBar docbook-xml DocbookXml FooBar Foobar - 3proxy Num_3proxy + 3proxy _3proxy The class name is what spack looks for when it loads a package module. -- cgit v1.2.3-70-g09d2 From 4bf6930416689794b2a07b56983d5bca10177b09 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 01:31:53 -0700 Subject: Docs for modules & dotkits. --- lib/spack/docs/basic_usage.rst | 167 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index 71f3da8610..d1235b12f8 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -657,3 +657,170 @@ add a version specifier to the spec: Notice that the package versions that provide insufficient MPI versions are now filtered out. + +.. _shell-support: + +Interactive Shell Support +------------------------------- + +Spack provides some limited shell support to make it easier to use the +packages it provides. You can enable shell support by sourcing some +files in the ``/share/spack`` directory. + +For ``bash`` or ``ksh``, run:: + + . $SPACK_ROOT/share/spack/setup-env.sh + +For ``csh`` and ``tcsh`` run: + + setenv SPACK_ROOT /path/to/spack + source $SPACK_ROOT/share/spack/setup-env.csh + +You can put the above code in your ``.bashrc`` or ``.cshrc``, and +Spack's shell support will be available on the command line. + + +Environment Modules +------------------------------- + +.. note:: + + Environment module support is currently experimental and should not + be considered a stable feature of Spack. In particular, the + interface and/or generated module names may change in future + versions. + +When you install a package with Spack, it automatically generates an +environment module that lets you add the package to your environment. + +Currently, Spack supports the generation of `TCL Modules +`_ and `Dotkit +`_. Generated +module files for each of these systems can be found in these +directories: + + * ``$SPACK_ROOT/share/spack/modules`` + * ``$SPACK_ROOT/share/spack/dotkit`` + +The directories are automatically added to your ``MODULEPATH`` and +``DK_NODE`` environment variables when you enable Spack's `shell +support `_. + +Using Modules & Dotkits +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you have shell support enabled you should be able to run either +``module avail`` or ``use -l spack`` to see what modules/dotkits have +been installed. Here is sample output of those programs, showing lots +of installed packages. + + .. code-block:: sh + + $ module avail + + ------- /g/g21/gamblin2/src/spack/share/spack/modules/chaos_5_x86_64_ib -------- + adept-utils@1.0%gcc@4.4.7-5adef8da libelf@0.8.13%gcc@4.4.7 + automaded@1.0%gcc@4.4.7-d9691bb0 libelf@0.8.13%intel@15.0.0 + boost@1.55.0%gcc@4.4.7 mpc@1.0.2%gcc@4.4.7-559607f5 + callpath@1.0.1%gcc@4.4.7-5dce4318 mpfr@3.1.2%gcc@4.4.7 + dyninst@8.1.2%gcc@4.4.7-b040c20e mpich@3.0.4%gcc@4.4.7 + gcc@4.9.1%gcc@4.4.7-93ab98c5 mpich@3.0.4%gcc@4.9.0 + gmp@6.0.0a%gcc@4.4.7 mrnet@4.1.0%gcc@4.4.7-72b7881d + graphlib@2.0.0%gcc@4.4.7 netgauge@2.4.6%gcc@4.9.0-27912b7b + launchmon@1.0.1%gcc@4.4.7 stat@2.1.0%gcc@4.4.7-51101207 + libNBC@1.1.1%gcc@4.9.0-27912b7b sundials@2.5.0%gcc@4.9.0-27912b7b + libdwarf@20130729%gcc@4.4.7-b52fac98 + + .. code-block:: sh + + $ use -l spack + + spack ---------- + adept-utils@1.0%gcc@4.4.7-5adef8da - adept-utils @1.0 + automaded@1.0%gcc@4.4.7-d9691bb0 - automaded @1.0 + boost@1.55.0%gcc@4.4.7 - boost @1.55.0 + callpath@1.0.1%gcc@4.4.7-5dce4318 - callpath @1.0.1 + dyninst@8.1.2%gcc@4.4.7-b040c20e - dyninst @8.1.2 + gmp@6.0.0a%gcc@4.4.7 - gmp @6.0.0a + libNBC@1.1.1%gcc@4.9.0-27912b7b - libNBC @1.1.1 + libdwarf@20130729%gcc@4.4.7-b52fac98 - libdwarf @20130729 + libelf@0.8.13%gcc@4.4.7 - libelf @0.8.13 + libelf@0.8.13%intel@15.0.0 - libelf @0.8.13 + mpc@1.0.2%gcc@4.4.7-559607f5 - mpc @1.0.2 + mpfr@3.1.2%gcc@4.4.7 - mpfr @3.1.2 + mpich@3.0.4%gcc@4.4.7 - mpich @3.0.4 + mpich@3.0.4%gcc@4.9.0 - mpich @3.0.4 + netgauge@2.4.6%gcc@4.9.0-27912b7b - netgauge @2.4.6 + sundials@2.5.0%gcc@4.9.0-27912b7b - sundials @2.5.0 + +The names here should look familiar, they're the same ones from +``spack find``. You *can* use the names here directly. For example, +you could type either of these: + +.. code-block:: sh + + use callpath@1.0.1%gcc@4.4.7-5dce4318 + module load callpath@1.0.1%gcc@4.4.7-5dce4318 + +And they would work fine. However, that is not particularly pretty, +easy to remember, or easy to type. + +Luckily, Spack has its own interface for using modules and dotkits. +You can use the same spec syntax you're used to: + +Modules: + * ``spack load `` + * ``spack unload `` +Dotkit: + * ``spack use `` + * ``spack unuse `` + +And you can use the same shortened names you use everywhere else in +Spack. For example: + +.. code-block:: sh + + $ spack install mpich %gcc@4.4.7 + # ... wait for install ... + $ spack use mpich%gcc@4.4.7 + Prepending: mpich@3.0.4%gcc@4.4.7 (ok) + $ which mpicc + ~/src/spack/opt/chaos_5_x86_64_ib/gcc@4.4.7/mpich@3.0.4/bin/mpicc + +Or, similarly with modules: + $ spack load mpich %gcc@4.4.7 + +The generated files will add appropriate directories to you ``PATH``, +``MANPATH``, and ``LD_LIBRARY_PATH`` to assist you and other programs +with finding the libraries you've installed. + +You can unuse/unload packages similarly. + +These commands are only available if you have enabled Spack's shell +support, but they allow you to use Spack's abbreviated names for +packages to get them into your environment. + +Ambiguous module names +~~~~~~~~~~~~~~~~~~~~~~~~ + +If a spec used with load/unload or use/unuse is ambiguous (i.e. more +than one installed package matches it), then Spack will warn you: + +.. code-block:: sh + + $ spack load libelf + ==> Error: Multiple matches for spec libelf. Choose one: + libelf@0.8.13%gcc@4.4.7=chaos_5_x86_64_ib + libelf@0.8.13%intel@15.0.0=chaos_5_x86_64_ib + +You can either type the ``spack load`` command again with a fully +qualified argument, or you can add just enough extra constraints to +identify one package. For example, above, the key differentiator is +that one ``libelf`` is built with the Intel compiler, while the other +used ``gcc``. You could therefore just type: + +.. code-block:: sh + + $ spack load libelf %intel + +To identify just the one built with the Intel compiler. -- cgit v1.2.3-70-g09d2 From 4ecc7e1c93ec6f5300f424e5f2bedfc8f5daa3cc Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 14:42:48 -0700 Subject: Document file filtering functions. --- lib/spack/docs/basic_usage.rst | 38 +++---- lib/spack/docs/packaging_guide.rst | 199 ++++++++++++++++++++++++++++++++++--- lib/spack/llnl/util/filesystem.py | 2 + 3 files changed, 206 insertions(+), 33 deletions(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index d1235b12f8..ddf7109a40 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -10,25 +10,6 @@ Only a small subset of commands are needed for typical usage. This section covers a small set of subcommands that should cover most general use cases for Spack. -Getting Help ------------------------ - -``spack help`` -~~~~~~~~~~~~~~~~~~~~~~ - -The ``help`` subcommand will print out out a list of all of -``spack``'s options and subcommands: - -.. command-output:: spack help - -Adding an argument, e.g. ``spack help ``, will print out -usage information for a particular subcommand: - -.. command-output:: spack help install - -Alternately, you can use ``spack -h`` in place of ``spack help``, or -``spack -h`` to get help on a particular subcommand. - Listing available packages ------------------------------ @@ -824,3 +805,22 @@ used ``gcc``. You could therefore just type: $ spack load libelf %intel To identify just the one built with the Intel compiler. + +Getting Help +----------------------- + +``spack help`` +~~~~~~~~~~~~~~~~~~~~~~ + +If you don't find what you need here, the ``help`` subcommand will +print out out a list of *all* of ``spack``'s options and subcommands: + +.. command-output:: spack help + +Adding an argument, e.g. ``spack help ``, will print out +usage information for a particular subcommand: + +.. command-output:: spack help install + +Alternately, you can use ``spack -h`` in place of ``spack help``, or +``spack -h`` to get help on a particular subcommand. diff --git a/lib/spack/docs/packaging_guide.rst b/lib/spack/docs/packaging_guide.rst index 1f95e56d2a..ec2ca4d099 100644 --- a/lib/spack/docs/packaging_guide.rst +++ b/lib/spack/docs/packaging_guide.rst @@ -768,9 +768,9 @@ information about the package, and to determine where to download its source code. Spack uses the tarball URL to extrapolate where to find other tarballs -of the same package (e.g. in `spack-checksum`_, but this does not -always work. This section covers ways you can tell Spack to find -tarballs elsewhere. +of the same package (e.g. in `spack checksum `_, but +this does not always work. This section covers ways you can tell +Spack to find tarballs elsewhere. .. _attribute_list_url: @@ -778,8 +778,9 @@ tarballs elsewhere. ~~~~~~~~~~~~~~~~~~~~~ When spack tries to find available versions of packages (e.g. with -`spack-checksum`_), it spiders the parent directory of the tarball in -the ``url`` attribute. For example, for libelf, the url is: +`spack checksum `_), it spiders the parent directory +of the tarball in the ``url`` attribute. For example, for libelf, the +url is: .. code-block:: python @@ -1335,8 +1336,8 @@ If your build system does *not* automatically pick these variables up from the environment, then you can simply pass them on the command line or use a patch as part of your build process to get the correct compilers into the project's build system. There are also some file -editing commands you can use -- these are described later in -`filtering-files`_. +editing commands you can use -- these are described later in the +`section on file manipulation `_. In addition to the compiler variables, these variables are set before entering ``install()`` so that packages can locate dependencies @@ -1466,9 +1467,28 @@ yourself, e.g.: Most of the standard UNIX directory names are attributes on the -``prefix`` object. See :py:class:`spack.prefix.Prefix` for a full -list. - +``prefix`` object. Here is a full list: + + ========================= ================================================ + Prefix Attribute Location + ========================= ================================================ + ``prefix.bin`` ``$prefix/bin`` + ``prefix.sbin`` ``$prefix/sbin`` + ``prefix.etc`` ``$prefix/etc`` + ``prefix.include`` ``$prefix/include`` + ``prefix.lib`` ``$prefix/lib`` + ``prefix.lib64`` ``$prefix/lib64`` + ``prefix.libexec`` ``$prefix/libexec`` + ``prefix.share`` ``$prefix/share`` + ``prefix.doc`` ``$prefix/doc`` + ``prefix.info`` ``$prefix/info`` + + ``prefix.man`` ``$prefix/man`` + ``prefix.man[1-8]`` ``$prefix/man/man[1-8]`` + + ``prefix.share_man`` ``$prefix/share/man`` + ``prefix.share_man[1-8]`` ``$prefix/share/man[1-8]`` + ========================= ================================================ .. _spec-objects: @@ -1678,11 +1698,10 @@ method (the one without the ``@when`` decorator) will be called. the way decorators work. - .. _shell-wrappers: -Shell command wrappers -------------------------- +Shell command functions +---------------------------- Recall the install method from ``libelf``: @@ -1730,9 +1749,161 @@ to the ``make`` wrapper to disable parallel make. In the ``libelf`` package, this allows us to avoid race conditions in the library's build system. + +.. _file-manipulation: + +File manipulation functions +------------------------------ + +Many builds are not perfect. If a build lacks an install target, or if +it does not use systems like CMake or autotools, which have standard +ways of setting compilers and options, you may need to edit files or +install some files yourself to get them working with Spack. + +You can do this with standard Python code, and Python has rich +libraries with functions for file manipulation and filtering. Spack +also provides a number of convenience functions of its own to make +your life even easier. These functions are described in this section. + +All of the functions in this section can be included by simply +running: + +.. code-block:: python + + from spack import * + +This is already part of the boilerplate for packages created with +``spack create`` or ``spack edit``. + + +Filtering functions +~~~~~~~~~~~~~~~~~~~~~~ + +:py:func:`filter_file(regex, repl, *filenames, **kwargs) ` + Works like ``sed`` but with Python regular expression syntax. Takes + a regular expression, a replacement, and a set of files. ``repl`` + can be a raw string or a callable function. If it is a raw string, + it can contain ``\1``, ``\2``, etc. to refer to capture groups in + the regular expression. If it is a callable, it is passed the + Python ``MatchObject`` and should return a suitable replacement + string for the particular match. + + Examples: + + #. Replacing ``#!/usr/bin/perl`` with ``#!/usr/bin/env perl`` in ``bib2xhtml``: + + .. code-block:: python + + filter_file(r'#!/usr/bin/perl', + '#!/usr/bin/env perl', join_path(prefix.bin, 'bib2xhtml')) + + #. Switching the compilers used by ``mpich``'s MPI wrapper scripts from + ``cc``, etc. to the compilers used by the Spack build: + + .. code-block:: python + + filter_file('CC="cc"', 'CC="%s"' % self.compiler.cc, + join_path(prefix.bin, 'mpicc')) + + filter_file('CXX="c++"', 'CXX="%s"' % self.compiler.cxx, + join_path(prefix.bin, 'mpicxx')) + +:py:func:`change_sed_delimiter(old_delim, new_delim, *filenames) ` + Some packages, like TAU, have a build system that can't install + into directories with, e.g. '@' in the name, because they use + hard-coded ``sed`` commands in their build. + + ``change_sed_delimiter`` finds all ``sed`` search/replace commands + and change the delimiter. e.g., if the file contains commands + that look like ``s///``, you can use this to change them to + ``s@@@``. + + Example of changing ``s///`` to ``s@@@`` in TAU: + + .. code-block:: python + + change_sed_delimiter('@', ';', 'configure') + change_sed_delimiter('@', ';', 'utils/FixMakefile') + change_sed_delimiter('@', ';', 'utils/FixMakefile.sed.default') + + +File functions +~~~~~~~~~~~~~~~~~~~~~~ + +:py:func:`ancestor(dir, n=1) ` + Get the n\ :sup:`th` ancestor of the directory ``dir``. + +:py:func:`can_access(path) ` + True if we can read and write to the file at ``path``. Same as + native python ``os.access(file_name, os.R_OK|os.W_OK)``. + +:py:func:`install(src, dest) ` + Install a file to a particular location. For example, install a + header into the ``include`` directory under the install ``prefix``: + + .. code-block:: python + + install('my-header.h', join_path(prefix.include)) + +:py:func:`join_path(prefix, *args) ` Like + ``os.path.join``, this joins paths using the OS path separator. + However, this version allows an arbitrary number of arguments, so + you can string together many path components. + +:py:func:`mkdirp(*paths) ` + Create each of the directories in ``paths``, creating any parent + directories if they do not exist. + +:py:func:`working_dir(dirname, kwargs) ` + This is a Python `Context Manager + `_ that makes it + easier to work with subdirectories in builds. You use this with the + Python ``with`` statement to change into a working directory, and + when the with block is done, you change back to the original + directory. Think of it as a safe ``pushd`` / ``popd`` combination, + where ``popd`` is guaranteed to be called at the end, even if + exceptions are thrown. + + Example usage: + + #. The ``libdwarf`` build first runs ``configure`` and ``make`` in a + subdirectory called ``libdwarf``. It then implements the + installation code itself. This is natural with ``working_dir``: + + .. code-block:: python + + with working_dir('libdwarf'): + configure("--prefix=" + prefix, "--enable-shared") + make() + install('libdwarf.a', prefix.lib) + + #. Many CMake builds require that you build "out of source", that + is, in a subdirectory. You can handle creating and ``cd``'ing to + the subdirectory like the LLVM package does: + + .. code-block:: python + + with working_dir('spack-build', create=True): + cmake('..', + '-DLLVM_REQUIRES_RTTI=1', + '-DPYTHON_EXECUTABLE=/usr/bin/python', + '-DPYTHON_INCLUDE_DIR=/usr/include/python2.6', + '-DPYTHON_LIBRARY=/usr/lib64/libpython2.6.so', + *std_cmake_args) + make() + make("install") + + The ``create=True`` keyword argument causes the command to create + the directory if it does not exist. + + +:py:func:`touch(path) ` + Create an empty file at ``path``. + + .. _pacakge-lifecycle: -Useful Packaging Commands +Package Workflow Commands --------------------------------- When you are building packages, you will likely not get things diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index a70111b915..dc722297ec 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -144,6 +144,7 @@ def expand_user(path): def mkdirp(*paths): + """Creates a directory, as well as parent directories if needed.""" for path in paths: if not os.path.exists(path): os.makedirs(path) @@ -163,6 +164,7 @@ def working_dir(dirname, **kwargs): def touch(path): + """Creates an empty file at the specified path.""" with closing(open(path, 'a')) as file: os.utime(path, None) -- cgit v1.2.3-70-g09d2 From 4d8a47800a7613802003392012abfcaa4b29113e Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 19:05:48 -0700 Subject: Add docs on spack module refresh. --- lib/spack/docs/basic_usage.rst | 137 +++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 45 deletions(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index ddf7109a40..0a0c2c678c 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -308,19 +308,19 @@ completely remove the directory in which the package was installed. spack uninstall mpich If there are still installed packages that depend on the package to be -uninstalled, spack will issue a warning. In general, it is safer to -remove dependent packages *before* removing their dependencies. Not -doing so risks breaking packages on your system. To remove a package -without regard for its dependencies, run ``spack uninstall -f -`` to override the warning. +uninstalled, spack will refuse to uninstall. If you know what you're +doing, you can override this with ``spack uninstall -f ``. +However, running this risks breaking other installed packages. In +general, it is safer to remove dependent packages *before* removing +their dependencies. A line like ``spack uninstall mpich`` may be ambiguous, if multiple ``mpich`` configurations are installed. For example, if both ``mpich@3.0.2`` and ``mpich@3.1`` are installed, it could refer to either one, and Spack cannot determine which one to uninstall. Spack -will ask you to provide a version number to remove any ambiguity. For -example, ``spack uninstall mpich@3.1`` is unambiguous in the -above scenario. +will ask you to provide a version number to remove the ambiguity. For +example, ``spack uninstall mpich@3.1`` is unambiguous in the above +scenario. .. _sec-specs: @@ -641,35 +641,41 @@ versions are now filtered out. .. _shell-support: -Interactive Shell Support +Environment Modules ------------------------------- -Spack provides some limited shell support to make it easier to use the -packages it provides. You can enable shell support by sourcing some -files in the ``/share/spack`` directory. +.. note:: -For ``bash`` or ``ksh``, run:: + Environment module support is currently experimental and should not + be considered a stable feature of Spack. In particular, the + interface and/or generated module names may change in future + versions. + +Spack provides some limited integration with environment module +systems to make it easier to use the packages it provides. + +You can enable shell support by sourcing some files in the +``/share/spack`` directory. + +For ``bash`` or ``ksh``, run: + +.. code-block:: sh - . $SPACK_ROOT/share/spack/setup-env.sh + . $SPACK_ROOT/share/spack/setup-env.sh For ``csh`` and ``tcsh`` run: - setenv SPACK_ROOT /path/to/spack - source $SPACK_ROOT/share/spack/setup-env.csh +.. code-block:: csh + + setenv SPACK_ROOT /path/to/spack + source $SPACK_ROOT/share/spack/setup-env.csh You can put the above code in your ``.bashrc`` or ``.cshrc``, and Spack's shell support will be available on the command line. -Environment Modules ------------------------------- -.. note:: - - Environment module support is currently experimental and should not - be considered a stable feature of Spack. In particular, the - interface and/or generated module names may change in future - versions. When you install a package with Spack, it automatically generates an environment module that lets you add the package to your environment. @@ -736,50 +742,63 @@ of installed packages. The names here should look familiar, they're the same ones from ``spack find``. You *can* use the names here directly. For example, -you could type either of these: +you could type either of these commands to load the callpath module +(assuming dotkit and modules are installed): .. code-block:: sh use callpath@1.0.1%gcc@4.4.7-5dce4318 - module load callpath@1.0.1%gcc@4.4.7-5dce4318 -And they would work fine. However, that is not particularly pretty, -easy to remember, or easy to type. +.. code-block:: sh + + module load callpath@1.0.1%gcc@4.4.7-5dce4318 -Luckily, Spack has its own interface for using modules and dotkits. -You can use the same spec syntax you're used to: +Neither of these is particularly pretty, easy to remember, or +easy to type. Luckily, Spack has its own interface for using modules +and dotkits. You can use the same spec syntax you're used to: -Modules: - * ``spack load `` - * ``spack unload `` -Dotkit: - * ``spack use `` - * ``spack unuse `` + ========================= ========================== + Modules Dotkit + ========================= ========================== + ``spack load `` ``spack use `` + ``spack unload `` ``spack unuse `` + ========================= ========================== And you can use the same shortened names you use everywhere else in -Spack. For example: +Spack. For example, this will add the ``mpich`` package built with +``gcc`` to your path: .. code-block:: sh $ spack install mpich %gcc@4.4.7 + # ... wait for install ... - $ spack use mpich%gcc@4.4.7 + + $ spack use mpich %gcc@4.4.7 Prepending: mpich@3.0.4%gcc@4.4.7 (ok) $ which mpicc ~/src/spack/opt/chaos_5_x86_64_ib/gcc@4.4.7/mpich@3.0.4/bin/mpicc -Or, similarly with modules: +Or, similarly with modules, you could type: + +.. code-block:: sh + $ spack load mpich %gcc@4.4.7 -The generated files will add appropriate directories to you ``PATH``, -``MANPATH``, and ``LD_LIBRARY_PATH`` to assist you and other programs -with finding the libraries you've installed. +These commands will add appropriate directories to your ``PATH``, +``MANPATH``, and ``LD_LIBRARY_PATH``. When you no longer want to use +a package, you can type unload or unuse similarly: -You can unuse/unload packages similarly. +.. code-block:: sh + + $ spack unload mpich %gcc@4.4.7 # modules + $ spack unuse mpich %gcc@4.4.7 # dotkit -These commands are only available if you have enabled Spack's shell -support, but they allow you to use Spack's abbreviated names for -packages to get them into your environment. +.. note:: + + These ``use``, ``unuse``, ``load``, and ``unload`` subcommands are + only available if you have enabled Spack's shell support *and* you + have dotkit or modules installed on your machine. Ambiguous module names ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -806,6 +825,34 @@ used ``gcc``. You could therefore just type: To identify just the one built with the Intel compiler. + +Regenerating Module files +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Module and dotkit files are generated when packages are installed, and +are placed in the following directories under the Spack root: + + * ``$SPACK_ROOT/share/spack/modules`` + * ``$SPACK_ROOT/share/spack/dotkit`` + +Sometimes you may need to regenerate the modules files. For example, +if newer, fancier module support is added to Spack at some later date, +you may want to regenerate all the modules to take advantage of these +new features. + +``spack module refresh`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Running ``spack module refresh`` will remove the +``share/spack/modules`` and ``share/spack/dotkit`` directories, then +regenerate all module and dotkit files from scratch: + +.. code-block:: sh + + $ spack module refresh + ==> Regenerating tcl module files. + ==> Regenerating dotkit module files. + Getting Help ----------------------- -- cgit v1.2.3-70-g09d2 From d98beeec31ad218c5b807774d42a447199005512 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 19:59:19 -0700 Subject: Remove ambiguous test case in url_extrapolate. --- lib/spack/spack/test/url_extrapolate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/test/url_extrapolate.py b/lib/spack/spack/test/url_extrapolate.py index 514d119deb..c30ff1f009 100644 --- a/lib/spack/spack/test/url_extrapolate.py +++ b/lib/spack/spack/test/url_extrapolate.py @@ -58,8 +58,9 @@ class UrlExtrapolateTest(MockPackagesTest): # 8.2 matches both the release8.2 component and the DyninstAPI-8.2 component. # Extrapolation should replace both with the new version. - self.assertEqual( - d.url_for_version('8.2.3'), 'http://www.paradyn.org/release8.2.3/DyninstAPI-8.2.3.tgz') + # TODO: figure out a consistent policy for this. + # self.assertEqual( + # d.url_for_version('8.2.3'), 'http://www.paradyn.org/release8.2.3/DyninstAPI-8.2.3.tgz') def test_with_package(self): -- cgit v1.2.3-70-g09d2 From 1c4948e1b0cbcaa6d367152e21c6df7d53ebb945 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 20:02:24 -0700 Subject: Fix long-standing multimethod test error. - New inclusive version ranges from git-fetching branch enable a fix. - Can now write :1 to include 1.3, 1.4, etc. - couldn't do this before so provides() was weird. --- lib/spack/spack/test/multimethod.py | 8 ++++---- var/spack/mock_packages/mpich/package.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/spack/spack/test/multimethod.py b/lib/spack/spack/test/multimethod.py index d773113426..cd5d9e625e 100644 --- a/lib/spack/spack/test/multimethod.py +++ b/lib/spack/spack/test/multimethod.py @@ -73,11 +73,11 @@ class MultiMethodTest(MockPackagesTest): def test_undefined_mpi_version(self): - # This currently fails because provides() doesn't do - # the right thing undefined version ranges. - # TODO: fix this. pkg = spack.db.get('multimethod^mpich@0.4') - self.assertEqual(pkg.mpi_version(), 0) + self.assertEqual(pkg.mpi_version(), 1) + + pkg = spack.db.get('multimethod^mpich@1.4') + self.assertEqual(pkg.mpi_version(), 1) def test_default_works(self): diff --git a/var/spack/mock_packages/mpich/package.py b/var/spack/mock_packages/mpich/package.py index e86c1a68ac..75a939a892 100644 --- a/var/spack/mock_packages/mpich/package.py +++ b/var/spack/mock_packages/mpich/package.py @@ -37,7 +37,7 @@ class Mpich(Package): version('3.0', 'foobarbaz') provides('mpi@:3', when='@3:') - provides('mpi@:1', when='@1:') + provides('mpi@:1', when='@:1') def install(self, spec, prefix): pass -- cgit v1.2.3-70-g09d2 From 75e6e794fbb79ca452e13f874edc7cfd2f10041f Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 21:32:31 -0700 Subject: Fix bug with extension() for sourceforge URLs. --- lib/spack/spack/util/compression.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index a67576bd50..b4db266fd3 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -23,6 +23,7 @@ # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import re +import os from itertools import product from spack.util.executable import which @@ -60,6 +61,11 @@ def strip_extension(path): def extension(path): """Get the archive extension for a path.""" + + # Strip sourceforge suffix. + if re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path): + path = os.path.dirname(path) + for type in ALLOWED_ARCHIVE_TYPES: suffix = r'\.%s$' % type if re.search(suffix, path): -- cgit v1.2.3-70-g09d2 From 5a5f5cb0189cf5d106e1aa4af5fca96308ffa9c4 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 21:33:51 -0700 Subject: Add Bob Robey to README credits. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0e59fb00df..7a13dba2a8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ people: * Matt Legendre * Greg Lee * Adam Moody + * Bob Robey Release ---------------- -- cgit v1.2.3-70-g09d2 From ee528bc426c458b1dd774ae49fb7205eadcab7dd Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 27 Oct 2014 22:40:04 -0700 Subject: Docs for spack list with glob. --- lib/spack/docs/basic_usage.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst index 0a0c2c678c..196b7077f9 100644 --- a/lib/spack/docs/basic_usage.rst +++ b/lib/spack/docs/basic_usage.rst @@ -25,7 +25,12 @@ Spack can install: .. command-output:: spack list -The packages are listed by name in alphabetical order. +The packages are listed by name in alphabetical order. You can also +do wildcard searches using ``*``: + +.. command-output:: spack list m* + +.. command-output:: spack list *util* ``spack info`` -- cgit v1.2.3-70-g09d2