Merge pull request #958 from trws/golang-new

Golang new
This commit is contained in:
Todd Gamblin 2016-05-17 05:56:06 -07:00
commit 1774c7a7b3
8 changed files with 433 additions and 179 deletions

View File

@ -57,7 +57,6 @@
from spack.util.compression import decompressor_for, extension from spack.util.compression import decompressor_for, extension
import spack.util.pattern as pattern import spack.util.pattern as pattern
"""List of all fetch strategies, created by FetchStrategy metaclass.""" """List of all fetch strategies, created by FetchStrategy metaclass."""
all_strategies = [] all_strategies = []
@ -82,13 +81,16 @@ class FetchStrategy(object):
class __metaclass__(type): class __metaclass__(type):
"""This metaclass registers all fetch strategies in a list.""" """This metaclass registers all fetch strategies in a list."""
def __init__(cls, name, bases, dict): def __init__(cls, name, bases, dict):
type.__init__(cls, name, bases, dict) type.__init__(cls, name, bases, dict)
if cls.enabled: all_strategies.append(cls) if cls.enabled:
all_strategies.append(cls)
def __init__(self): def __init__(self):
# The stage is initialized late, so that fetch strategies can be constructed # The stage is initialized late, so that fetch strategies can be
# at package construction time. This is where things will be fetched. # constructed at package construction time. This is where things
# will be fetched.
self.stage = None self.stage = None
def set_stage(self, stage): def set_stage(self, stage):
@ -97,15 +99,20 @@ def set_stage(self, stage):
self.stage = stage self.stage = stage
# Subclasses need to implement these methods # Subclasses need to implement these methods
def fetch(self): pass # Return True on success, False on fail. def fetch(self):
pass # Return True on success, False on fail.
def check(self): pass # Do checksum. def check(self):
pass # Do checksum.
def expand(self): pass # Expand archive. def expand(self):
pass # Expand archive.
def reset(self): pass # Revert to freshly downloaded state. def reset(self):
pass # Revert to freshly downloaded state.
def archive(self, destination): pass # Used to create tarball for mirror. def archive(self, destination):
pass # Used to create tarball for mirror.
def __str__(self): # Should be human readable URL. def __str__(self): # Should be human readable URL.
return "FetchStrategy.__str___" return "FetchStrategy.__str___"
@ -139,10 +146,12 @@ def __init__(self, url=None, digest=None, **kwargs):
# If URL or digest are provided in the kwargs, then prefer # If URL or digest are provided in the kwargs, then prefer
# those values. # those values.
self.url = kwargs.get('url', None) self.url = kwargs.get('url', None)
if not self.url: self.url = url if not self.url:
self.url = url
self.digest = kwargs.get('md5', None) self.digest = kwargs.get('md5', None)
if not self.digest: self.digest = digest if not self.digest:
self.digest = digest
self.expand_archive = kwargs.get('expand', True) self.expand_archive = kwargs.get('expand', True)
@ -167,16 +176,20 @@ def fetch(self):
tty.msg("Trying to fetch from %s" % self.url) tty.msg("Trying to fetch from %s" % self.url)
if partial_file: if partial_file:
save_args = ['-C', '-', # continue partial downloads save_args = ['-C',
'-o', partial_file] # use a .part file '-', # continue partial downloads
'-o',
partial_file] # use a .part file
else: else:
save_args = ['-O'] save_args = ['-O']
curl_args = save_args + [ curl_args = save_args + [
'-f', # fail on >400 errors '-f', # fail on >400 errors
'-D', '-', # print out HTML headers '-D',
'-L', # resolve 3xx redirects '-', # print out HTML headers
self.url, ] '-L', # resolve 3xx redirects
self.url,
]
if sys.stdout.isatty(): if sys.stdout.isatty():
curl_args.append('-#') # status bar when using a tty curl_args.append('-#') # status bar when using a tty
@ -184,8 +197,7 @@ def fetch(self):
curl_args.append('-sS') # just errors when not. curl_args.append('-sS') # just errors when not.
# Run curl but grab the mime type from the http headers # Run curl but grab the mime type from the http headers
headers = spack.curl( headers = spack.curl(*curl_args, output=str, fail_on_error=False)
*curl_args, output=str, fail_on_error=False)
if spack.curl.returncode != 0: if spack.curl.returncode != 0:
# clean up archive on failure. # clean up archive on failure.
@ -198,33 +210,36 @@ def fetch(self):
if spack.curl.returncode == 22: if spack.curl.returncode == 22:
# This is a 404. Curl will print the error. # This is a 404. Curl will print the error.
raise FailedDownloadError( raise FailedDownloadError(
self.url, "URL %s was not found!" % self.url) self.url, "URL %s was not found!" % self.url)
elif spack.curl.returncode == 60: elif spack.curl.returncode == 60:
# This is a certificate error. Suggest spack -k # This is a certificate error. Suggest spack -k
raise FailedDownloadError( raise FailedDownloadError(
self.url, self.url,
"Curl was unable to fetch due to invalid certificate. " "Curl was unable to fetch due to invalid certificate. "
"This is either an attack, or your cluster's SSL configuration " "This is either an attack, or your cluster's SSL "
"is bad. If you believe your SSL configuration is bad, you " "configuration is bad. If you believe your SSL "
"can try running spack -k, which will not check SSL certificates." "configuration is bad, you can try running spack -k, "
"Use this at your own risk.") "which will not check SSL certificates."
"Use this at your own risk.")
else: else:
# This is some other curl error. Curl will print the # This is some other curl error. Curl will print the
# error, but print a spack message too # error, but print a spack message too
raise FailedDownloadError( raise FailedDownloadError(
self.url, "Curl failed with error %d" % spack.curl.returncode) self.url,
"Curl failed with error %d" % spack.curl.returncode)
# Check if we somehow got an HTML file rather than the archive we # 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 # asked for. We only look at the last content type, to handle
# redirects properly. # redirects properly.
content_types = re.findall(r'Content-Type:[^\r\n]+', headers) content_types = re.findall(r'Content-Type:[^\r\n]+', headers)
if content_types and 'text/html' in content_types[-1]: if content_types and 'text/html' in content_types[-1]:
tty.warn("The contents of " + self.archive_file + " look like HTML.", tty.warn(
"The checksum will likely be bad. If it is, you can use", "The contents of " + self.archive_file + " look like HTML.",
"'spack clean <package>' to remove the bad archive, then fix", "The checksum will likely be bad. If it is, you can use",
"your internet gateway issue and install again.") "'spack clean <package>' to remove the bad archive, then fix",
"your internet gateway issue and install again.")
if save_file: if save_file:
os.rename(partial_file, save_file) os.rename(partial_file, save_file)
@ -247,14 +262,16 @@ def expand(self):
self.stage.chdir() self.stage.chdir()
if not self.archive_file: if not self.archive_file:
raise NoArchiveFileError("URLFetchStrategy couldn't find archive file", raise NoArchiveFileError(
"Failed on expand() for URL %s" % self.url) "URLFetchStrategy couldn't find archive file",
"Failed on expand() for URL %s" % self.url)
decompress = decompressor_for(self.archive_file) decompress = decompressor_for(self.archive_file)
# Expand all tarballs in their own directory to contain # Expand all tarballs in their own directory to contain
# exploding tarballs. # exploding tarballs.
tarball_container = os.path.join(self.stage.path, "spack-expanded-archive") tarball_container = os.path.join(self.stage.path,
"spack-expanded-archive")
mkdirp(tarball_container) mkdirp(tarball_container)
os.chdir(tarball_container) os.chdir(tarball_container)
decompress(self.archive_file) decompress(self.archive_file)
@ -295,20 +312,25 @@ def check(self):
"""Check the downloaded archive against a checksum digest. """Check the downloaded archive against a checksum digest.
No-op if this stage checks code out of a repository.""" No-op if this stage checks code out of a repository."""
if not self.digest: if not self.digest:
raise NoDigestError("Attempt to check URLFetchStrategy with no digest.") raise NoDigestError(
"Attempt to check URLFetchStrategy with no digest.")
checker = crypto.Checker(self.digest) checker = crypto.Checker(self.digest)
if not checker.check(self.archive_file): if not checker.check(self.archive_file):
raise ChecksumError( raise ChecksumError(
"%s checksum failed for %s" % (checker.hash_name, self.archive_file), "%s checksum failed for %s" %
"Expected %s but got %s" % (self.digest, checker.sum)) (checker.hash_name, self.archive_file),
"Expected %s but got %s" % (self.digest, checker.sum))
@_needs_stage @_needs_stage
def reset(self): def reset(self):
"""Removes the source path if it exists, then re-expands the archive.""" """
Removes the source path if it exists, then re-expands the archive.
"""
if not self.archive_file: if not self.archive_file:
raise NoArchiveFileError("Tried to reset URLFetchStrategy before fetching", raise NoArchiveFileError(
"Failed on reset() for URL %s" % self.url) "Tried to reset URLFetchStrategy before fetching",
"Failed on reset() for URL %s" % self.url)
# Remove everythigng but the archive from the stage # Remove everythigng but the archive from the stage
for filename in os.listdir(self.stage.path): for filename in os.listdir(self.stage.path):
@ -337,14 +359,16 @@ def __init__(self, name, *rev_types, **kwargs):
# Set a URL based on the type of fetch strategy. # Set a URL based on the type of fetch strategy.
self.url = kwargs.get(name, None) self.url = kwargs.get(name, None)
if not self.url: raise ValueError( if not self.url:
raise ValueError(
"%s requires %s argument." % (self.__class__, name)) "%s requires %s argument." % (self.__class__, name))
# Ensure that there's only one of the rev_types # 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( raise FetchStrategyError(
"Supply only one of %s to fetch with %s" % ( "Supply only one of %s to fetch with %s" % (
comma_or(rev_types), name)) comma_or(rev_types), name
))
# Set attributes for each rev type. # Set attributes for each rev type.
for rt in rev_types: for rt in rev_types:
@ -382,32 +406,93 @@ def __repr__(self):
return "%s<%s>" % (self.__class__, self.url) return "%s<%s>" % (self.__class__, self.url)
class GitFetchStrategy(VCSFetchStrategy): class GoFetchStrategy(VCSFetchStrategy):
"""Fetch strategy that gets source code from a git repository. """
Use like this in a package: Fetch strategy that employs the `go get` infrastructure
Use like this in a package:
version('name', git='https://github.com/project/repo.git') version('name',
go='github.com/monochromegane/the_platinum_searcher/...')
Optionally, you can provide a branch, or commit to check out, e.g.: Go get does not natively support versions, they can be faked with git
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 enabled = True
required_attributes = ('git',) required_attributes = ('go', )
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next
# call to __init__
forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None)
super(GoFetchStrategy, self).__init__('go', **forwarded_args)
self._go = None
@property
def go_version(self):
vstring = self.go('version', output=str).split(' ')[2]
return Version(vstring)
@property
def go(self):
if not self._go:
self._go = which('go', required=True)
return self._go
@_needs_stage
def fetch(self):
self.stage.chdir()
tty.msg("Trying to get go resource:", self.url)
try:
os.mkdir('go')
except OSError:
pass
env = dict(os.environ)
env['GOPATH'] = os.path.join(os.getcwd(), 'go')
self.go('get', '-v', '-d', self.url, env=env)
def archive(self, destination):
super(GoFetchStrategy, self).archive(destination, exclude='.git')
@_needs_stage
def reset(self):
self.stage.chdir_to_source()
self.go('clean')
def __str__(self):
return "[go] %s" % self.url
class GitFetchStrategy(VCSFetchStrategy):
"""
Fetch strategy that gets source code from a git repository.
Use like this in a package:
version('name', git='https://github.com/project/repo.git')
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):
# Discards the keywords in kwargs that may conflict with the next call
# to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
super(GitFetchStrategy, self).__init__( super(GitFetchStrategy, self).__init__(
'git', 'tag', 'branch', 'commit', **forwarded_args) 'git', 'tag', 'branch', 'commit', **forwarded_args)
self._git = None self._git = None
@property @property
@ -515,12 +600,13 @@ class SvnFetchStrategy(VCSFetchStrategy):
required_attributes = ['svn'] required_attributes = ['svn']
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next call
# to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
super(SvnFetchStrategy, self).__init__( super(SvnFetchStrategy, self).__init__(
'svn', 'revision', **forwarded_args) 'svn', 'revision', **forwarded_args)
self._svn = None self._svn = None
if self.revision is not None: if self.revision is not None:
self.revision = str(self.revision) self.revision = str(self.revision)
@ -576,32 +662,35 @@ def __str__(self):
class HgFetchStrategy(VCSFetchStrategy): class HgFetchStrategy(VCSFetchStrategy):
"""Fetch strategy that gets source code from a Mercurial repository. """
Use like this in a package: 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') version('name', hg='https://jay.grs.rwth-aachen.de/hg/lwm2')
Optionally, you can provide a branch, or revision to check out, e.g.: 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') version('torus',
hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus')
You can use the optional 'revision' attribute to check out a You can use the optional 'revision' attribute to check out a
branch, tag, or particular revision in hg. To prevent branch, tag, or particular revision in hg. To prevent
non-reproducible builds, using a moving target like a branch is non-reproducible builds, using a moving target like a branch is
discouraged. discouraged.
* ``revision``: Particular revision, branch, or tag. * ``revision``: Particular revision, branch, or tag.
""" """
enabled = True enabled = True
required_attributes = ['hg'] required_attributes = ['hg']
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next call
# to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
super(HgFetchStrategy, self).__init__( super(HgFetchStrategy, self).__init__(
'hg', 'revision', **forwarded_args) 'hg', 'revision', **forwarded_args)
self._hg = None self._hg = None
@property @property
@ -675,7 +764,8 @@ def from_kwargs(**kwargs):
return fetcher(**kwargs) return fetcher(**kwargs)
# Raise an error in case we can't instantiate any known strategy # Raise an error in case we can't instantiate any known strategy
message = "Cannot instantiate any FetchStrategy" message = "Cannot instantiate any FetchStrategy"
long_message = message + " from the given arguments : {arguments}".format(srguments=kwargs) long_message = message + " from the given arguments : {arguments}".format(
srguments=kwargs)
raise FetchError(message, long_message) raise FetchError(message, long_message)
@ -687,7 +777,7 @@ def for_package_version(pkg, version):
"""Determine a fetch strategy based on the arguments supplied to """Determine a fetch strategy based on the arguments supplied to
version() in the package description.""" version() in the package description."""
# If it's not a known version, extrapolate one. # If it's not a known version, extrapolate one.
if not version in pkg.versions: if version not in pkg.versions:
url = pkg.url_for_version(version) url = pkg.url_for_version(version)
if not url: if not url:
raise InvalidArgsError(pkg, version) raise InvalidArgsError(pkg, version)
@ -725,7 +815,7 @@ class FailedDownloadError(FetchError):
def __init__(self, url, msg=""): def __init__(self, url, msg=""):
super(FailedDownloadError, self).__init__( super(FailedDownloadError, self).__init__(
"Failed to fetch file from URL: %s" % url, msg) "Failed to fetch file from URL: %s" % url, msg)
self.url = url self.url = url
@ -741,7 +831,8 @@ def __init__(self, msg, long_msg=None):
class InvalidArgsError(FetchError): class InvalidArgsError(FetchError):
def __init__(self, pkg, version): def __init__(self, pkg, version):
msg = "Could not construct a fetch strategy for package %s at version %s" msg = ("Could not construct a fetch strategy for package %s at "
"version %s")
msg %= (pkg.name, version) msg %= (pkg.name, version)
super(InvalidArgsError, self).__init__(msg) super(InvalidArgsError, self).__init__(msg)
@ -758,4 +849,5 @@ class NoStageError(FetchError):
def __init__(self, method): def __init__(self, method):
super(NoStageError, self).__init__( super(NoStageError, self).__init__(
"Must call FetchStrategy.set_stage() before calling %s" % method.__name__) "Must call FetchStrategy.set_stage() before calling %s" %
method.__name__)

View File

@ -22,10 +22,8 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
__all__ = ['Executable', 'which', 'ProcessError']
import os import os
import sys
import re import re
import subprocess import subprocess
import inspect import inspect
@ -34,9 +32,12 @@
import spack import spack
import spack.error import spack.error
__all__ = ['Executable', 'which', 'ProcessError']
class Executable(object): class Executable(object):
"""Class representing a program that can be run on the command line.""" """Class representing a program that can be run on the command line."""
def __init__(self, name): def __init__(self, name):
self.exe = name.split(' ') self.exe = name.split(' ')
self.returncode = None self.returncode = None
@ -44,16 +45,13 @@ def __init__(self, name):
if not self.exe: if not self.exe:
raise ProcessError("Cannot construct executable for '%s'" % name) raise ProcessError("Cannot construct executable for '%s'" % name)
def add_default_arg(self, arg): def add_default_arg(self, arg):
self.exe.append(arg) self.exe.append(arg)
@property @property
def command(self): def command(self):
return ' '.join(self.exe) return ' '.join(self.exe)
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
"""Run this executable in a subprocess. """Run this executable in a subprocess.
@ -105,6 +103,8 @@ def __call__(self, *args, **kwargs):
fail_on_error = kwargs.pop("fail_on_error", True) fail_on_error = kwargs.pop("fail_on_error", True)
ignore_errors = kwargs.pop("ignore_errors", ()) ignore_errors = kwargs.pop("ignore_errors", ())
env = kwargs.get('env', None)
# TODO: This is deprecated. Remove in a future version. # TODO: This is deprecated. Remove in a future version.
return_output = kwargs.pop("return_output", False) return_output = kwargs.pop("return_output", False)
@ -114,8 +114,8 @@ def __call__(self, *args, **kwargs):
else: else:
output = kwargs.pop("output", None) output = kwargs.pop("output", None)
error = kwargs.pop("error", None) error = kwargs.pop("error", None)
input = kwargs.pop("input", None) input = kwargs.pop("input", None)
if input is str: if input is str:
raise ValueError("Cannot use `str` as input stream.") raise ValueError("Cannot use `str` as input stream.")
@ -126,85 +126,90 @@ def streamify(arg, mode):
return subprocess.PIPE, False return subprocess.PIPE, False
else: else:
return arg, False return arg, False
ostream, close_ostream = streamify(output, 'w') ostream, close_ostream = streamify(output, 'w')
estream, close_estream = streamify(error, 'w') estream, close_estream = streamify(error, 'w')
istream, close_istream = streamify(input, 'r') istream, close_istream = streamify(input, 'r')
# if they just want to ignore one error code, make it a tuple. # if they just want to ignore one error code, make it a tuple.
if isinstance(ignore_errors, int): if isinstance(ignore_errors, int):
ignore_errors = (ignore_errors,) ignore_errors = (ignore_errors, )
quoted_args = [arg for arg in args if re.search(r'^"|^\'|"$|\'$', arg)] quoted_args = [arg for arg in args if re.search(r'^"|^\'|"$|\'$', arg)]
if quoted_args: if quoted_args:
tty.warn("Quotes in command arguments can confuse scripts like configure.", tty.warn(
"The following arguments may cause problems when executed:", "Quotes in command arguments can confuse scripts like"
str("\n".join([" "+arg for arg in quoted_args])), " configure.",
"Quotes aren't needed because spack doesn't use a shell.", "The following arguments may cause problems when executed:",
"Consider removing them") str("\n".join([" " + arg for arg in quoted_args])),
"Quotes aren't needed because spack doesn't use a shell.",
"Consider removing them")
cmd = self.exe + list(args) cmd = self.exe + list(args)
cmd_line = "'%s'" % "' '".join(map(lambda arg: arg.replace("'", "'\"'\"'"), cmd)) cmd_line = "'%s'" % "' '".join(
map(lambda arg: arg.replace("'", "'\"'\"'"), cmd))
tty.debug(cmd_line) tty.debug(cmd_line)
try: try:
proc = subprocess.Popen( proc = subprocess.Popen(
cmd, stdin=istream, stderr=estream, stdout=ostream) cmd,
stdin=istream,
stderr=estream,
stdout=ostream,
env=env)
out, err = proc.communicate() out, err = proc.communicate()
rc = self.returncode = proc.returncode rc = self.returncode = proc.returncode
if fail_on_error and rc != 0 and (rc not in ignore_errors): if fail_on_error and rc != 0 and (rc not in ignore_errors):
raise ProcessError("Command exited with status %d:" raise ProcessError("Command exited with status %d:" %
% proc.returncode, cmd_line) proc.returncode, cmd_line)
if output is str or error is str: if output is str or error is str:
result = '' result = ''
if output is str: result += out if output is str:
if error is str: result += err result += out
if error is str:
result += err
return result return result
except OSError, e: except OSError, e:
raise ProcessError( raise ProcessError(
"%s: %s" % (self.exe[0], e.strerror), "%s: %s" % (self.exe[0], e.strerror), "Command: " + cmd_line)
"Command: " + cmd_line)
except subprocess.CalledProcessError, e: except subprocess.CalledProcessError, e:
if fail_on_error: if fail_on_error:
raise ProcessError( raise ProcessError(
str(e), str(e), "\nExit status %d when invoking command: %s" %
"\nExit status %d when invoking command: %s" (proc.returncode, cmd_line))
% (proc.returncode, cmd_line))
finally: finally:
if close_ostream: output.close() if close_ostream:
if close_estream: error.close() output.close()
if close_istream: input.close() if close_estream:
error.close()
if close_istream:
input.close()
def __eq__(self, other): def __eq__(self, other):
return self.exe == other.exe return self.exe == other.exe
def __neq__(self, other): def __neq__(self, other):
return not (self == other) return not (self == other)
def __hash__(self): def __hash__(self):
return hash((type(self),) + tuple(self.exe)) return hash((type(self), ) + tuple(self.exe))
def __repr__(self): def __repr__(self):
return "<exe: %s>" % self.exe return "<exe: %s>" % self.exe
def __str__(self): def __str__(self):
return ' '.join(self.exe) return ' '.join(self.exe)
def which(name, **kwargs): def which(name, **kwargs):
"""Finds an executable in the path like command-line which.""" """Finds an executable in the path like command-line which."""
path = kwargs.get('path', os.environ.get('PATH', '').split(os.pathsep)) path = kwargs.get('path', os.environ.get('PATH', '').split(os.pathsep))
required = kwargs.get('required', False) required = kwargs.get('required', False)
if not path: if not path:
@ -233,14 +238,16 @@ def __init__(self, msg, long_message=None):
@property @property
def long_message(self): def long_message(self):
msg = self._long_message msg = self._long_message
if msg: msg += "\n\n" if msg:
msg += "\n\n"
if self.build_log: if self.build_log:
msg += "See build log for details:\n" msg += "See build log for details:\n"
msg += " %s" % self.build_log msg += " %s" % self.build_log
if self.package_context: if self.package_context:
if msg: msg += "\n\n" if msg:
msg += "\n\n"
msg += '\n'.join(self.package_context) msg += '\n'.join(self.package_context)
return msg return msg
@ -267,7 +274,7 @@ def _get_package_context():
frame = f[0] frame = f[0]
# Find a frame with 'self' in the local variables. # Find a frame with 'self' in the local variables.
if not 'self' in frame.f_locals: if 'self' not in frame.f_locals:
continue continue
# Look only at a frame in a subclass of spack.Package # Look only at a frame in a subclass of spack.Package
@ -280,9 +287,8 @@ def _get_package_context():
# Build a message showing where in install we failed. # Build a message showing where in install we failed.
lines.append("%s:%d, in %s:" % ( lines.append("%s:%d, in %s:" % (
inspect.getfile(frame.f_code), inspect.getfile(frame.f_code), frame.f_lineno, frame.f_code.co_name
frame.f_lineno, ))
frame.f_code.co_name))
sourcelines, start = inspect.getsourcelines(frame) sourcelines, start = inspect.getsourcelines(frame)
for i, line in enumerate(sourcelines): for i, line in enumerate(sourcelines):

View File

@ -24,15 +24,18 @@
############################################################################## ##############################################################################
from spack import * from spack import *
class Flex(Package): class Flex(Package):
"""Flex is a tool for generating scanners.""" """Flex is a tool for generating scanners."""
homepage = "http://flex.sourceforge.net/" homepage = "http://flex.sourceforge.net/"
url = "http://download.sourceforge.net/flex/flex-2.5.39.tar.gz" url = "http://download.sourceforge.net/flex/flex-2.5.39.tar.gz"
version('2.6.0', '5724bcffed4ebe39e9b55a9be80859ec') version('2.6.0', '5724bcffed4ebe39e9b55a9be80859ec')
version('2.5.39', 'e133e9ead8ec0a58d81166b461244fde') version('2.5.39', 'e133e9ead8ec0a58d81166b461244fde')
depends_on("bison")
def install(self, spec, prefix): def install(self, spec, prefix):
configure("--prefix=%s" % prefix) configure("--prefix=%s" % prefix)

View File

@ -1,33 +1,9 @@
##############################################################################
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/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 Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, 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 Lesser 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 * from spack import *
from contextlib import closing from contextlib import closing
from glob import glob from glob import glob
import sys import sys
import os
class Gcc(Package): class Gcc(Package):
"""The GNU Compiler Collection includes front ends for C, C++, """The GNU Compiler Collection includes front ends for C, C++,
@ -50,10 +26,12 @@ class Gcc(Package):
version('4.6.4', 'b407a3d1480c11667f293bfb1f17d1a4') version('4.6.4', 'b407a3d1480c11667f293bfb1f17d1a4')
version('4.5.4', '27e459c2566b8209ab064570e1b378f7') version('4.5.4', '27e459c2566b8209ab064570e1b378f7')
variant('binutils', default=sys.platform != 'darwin', variant('binutils',
description="Build via binutils") default=sys.platform != 'darwin',
variant('gold', default=sys.platform != 'darwin', description="Build via binutils")
description="Build the gold linker plugin for ld-based LTO") variant('gold',
default=sys.platform != 'darwin',
description="Build the gold linker plugin for ld-based LTO")
depends_on("mpfr") depends_on("mpfr")
depends_on("gmp") depends_on("gmp")
@ -63,16 +41,18 @@ class Gcc(Package):
depends_on("binutils~libiberty+gold", when='+binutils +gold') depends_on("binutils~libiberty+gold", when='+binutils +gold')
# TODO: integrate these libraries. # TODO: integrate these libraries.
#depends_on("ppl") # depends_on("ppl")
#depends_on("cloog") # depends_on("cloog")
if sys.platform == 'darwin': if sys.platform == 'darwin':
patch('darwin/gcc-4.9.patch1', when='@4.9.3') patch('darwin/gcc-4.9.patch1', when='@4.9.3')
patch('darwin/gcc-4.9.patch2', when='@4.9.3') patch('darwin/gcc-4.9.patch2', when='@4.9.3')
else:
provides('golang', when='@4.7.1:')
def install(self, spec, prefix): def install(self, spec, prefix):
# libjava/configure needs a minor fix to install into spack paths. # libjava/configure needs a minor fix to install into spack paths.
filter_file(r"'@.*@'", "'@[[:alnum:]]*@'", 'libjava/configure', filter_file(r"'@.*@'", "'@[[:alnum:]]*@'", 'libjava/configure',
string=True) string=True)
enabled_languages = set(('c', 'c++', 'fortran', 'java', 'objc')) enabled_languages = set(('c', 'c++', 'fortran', 'java', 'objc'))
@ -80,62 +60,59 @@ def install(self, spec, prefix):
enabled_languages.add('go') enabled_languages.add('go')
# Generic options to compile GCC # Generic options to compile GCC
options = ["--prefix=%s" % prefix, options = ["--prefix=%s" % prefix, "--libdir=%s/lib64" % prefix,
"--libdir=%s/lib64" % prefix,
"--disable-multilib", "--disable-multilib",
"--enable-languages=" + ','.join(enabled_languages), "--enable-languages=" + ','.join(enabled_languages),
"--with-mpc=%s" % spec['mpc'].prefix, "--with-mpc=%s" % spec['mpc'].prefix, "--with-mpfr=%s" %
"--with-mpfr=%s" % spec['mpfr'].prefix, spec['mpfr'].prefix, "--with-gmp=%s" % spec['gmp'].prefix,
"--with-gmp=%s" % spec['gmp'].prefix, "--enable-lto", "--with-quad"]
"--enable-lto",
"--with-quad"]
# Binutils # Binutils
if spec.satisfies('+binutils'): if spec.satisfies('+binutils'):
static_bootstrap_flags = "-static-libstdc++ -static-libgcc" static_bootstrap_flags = "-static-libstdc++ -static-libgcc"
binutils_options = ["--with-sysroot=/", binutils_options = [
"--with-stage1-ldflags=%s %s" % "--with-sysroot=/", "--with-stage1-ldflags=%s %s" %
(self.rpath_args, static_bootstrap_flags), (self.rpath_args, static_bootstrap_flags),
"--with-boot-ldflags=%s %s" % "--with-boot-ldflags=%s %s" %
(self.rpath_args, static_bootstrap_flags), (self.rpath_args, static_bootstrap_flags), "--with-gnu-ld",
"--with-gnu-ld", "--with-ld=%s/bin/ld" % spec['binutils'].prefix,
"--with-ld=%s/bin/ld" % spec['binutils'].prefix, "--with-gnu-as",
"--with-gnu-as", "--with-as=%s/bin/as" % spec['binutils'].prefix
"--with-as=%s/bin/as" % spec['binutils'].prefix] ]
options.extend(binutils_options) options.extend(binutils_options)
# Isl # Isl
if 'isl' in spec: if 'isl' in spec:
isl_options = ["--with-isl=%s" % spec['isl'].prefix] isl_options = ["--with-isl=%s" % spec['isl'].prefix]
options.extend(isl_options) options.extend(isl_options)
if sys.platform == 'darwin' : if sys.platform == 'darwin':
darwin_options = [ "--with-build-config=bootstrap-debug" ] darwin_options = ["--with-build-config=bootstrap-debug"]
options.extend(darwin_options) options.extend(darwin_options)
build_dir = join_path(self.stage.path, 'spack-build') build_dir = join_path(self.stage.path, 'spack-build')
configure = Executable( join_path(self.stage.source_path, 'configure') ) configure = Executable(join_path(self.stage.source_path, 'configure'))
with working_dir(build_dir, create=True): with working_dir(build_dir, create=True):
# Rest of install is straightforward. # Rest of install is straightforward.
configure(*options) configure(*options)
if sys.platform == 'darwin' : make("bootstrap") if sys.platform == 'darwin':
else: make() make("bootstrap")
else:
make()
make("install") make("install")
self.write_rpath_specs() self.write_rpath_specs()
@property @property
def spec_dir(self): def spec_dir(self):
# e.g. lib64/gcc/x86_64-unknown-linux-gnu/4.9.2 # e.g. lib64/gcc/x86_64-unknown-linux-gnu/4.9.2
spec_dir = glob("%s/lib64/gcc/*/*" % self.prefix) spec_dir = glob("%s/lib64/gcc/*/*" % self.prefix)
return spec_dir[0] if spec_dir else None return spec_dir[0] if spec_dir else None
def write_rpath_specs(self): def write_rpath_specs(self):
"""Generate a spec file so the linker adds a rpath to the libs """Generate a spec file so the linker adds a rpath to the libs
the compiler used to build the executable.""" the compiler used to build the executable."""
if not self.spec_dir: if not self.spec_dir:
tty.warn("Could not install specs for %s." % tty.warn("Could not install specs for %s." %
self.spec.format('$_$@')) self.spec.format('$_$@'))
return return
gcc = Executable(join_path(self.prefix.bin, 'gcc')) gcc = Executable(join_path(self.prefix.bin, 'gcc'))
@ -146,5 +123,5 @@ def write_rpath_specs(self):
out.write(line + "\n") out.write(line + "\n")
if line.startswith("*link:"): if line.startswith("*link:"):
out.write("-rpath %s/lib:%s/lib64 \\\n" % out.write("-rpath %s/lib:%s/lib64 \\\n" %
(self.prefix, self.prefix)) (self.prefix, self.prefix))
set_install_permissions(specs_file) set_install_permissions(specs_file)

View File

@ -0,0 +1,51 @@
import os
import shutil
import glob
from spack import *
# THIS PACKAGE SHOULD NOT EXIST
# it exists to make up for the inability to:
# * use an external go compiler
# * have go depend on itself
# * have a sensible way to find gccgo without a dep on gcc
class GoBootstrap(Package):
"""Old C-bootstrapped go to bootstrap real go"""
homepage = "https://golang.org"
url = "https://go.googlesource.com/go"
extendable = True
# temporary fix until tags are pulled correctly
version('1.4.2', git='https://go.googlesource.com/go', tag='go1.4.2')
variant('test',
default=True,
description="Run tests as part of build, a good idea but quite"
" time consuming")
provides('golang@:1.4.2')
depends_on('git')
def install(self, spec, prefix):
bash = which('bash')
with working_dir('src'):
if '+test' in spec:
bash('all.bash')
else:
bash('make.bash')
try:
os.makedirs(prefix)
except OSError:
pass
for f in glob.glob('*'):
if os.path.isdir(f):
shutil.copytree(f, os.path.join(prefix, f))
else:
shutil.copy2(f, os.path.join(prefix, f))
def setup_environment(self, spack_env, run_env):
spack_env.set('GOROOT_FINAL', self.spec.prefix)

View File

@ -0,0 +1,80 @@
import os
import shutil
import glob
import llnl.util.tty as tty
from spack import *
class Go(Package):
"""The golang compiler and build environment"""
homepage = "https://golang.org"
url = "https://go.googlesource.com/go"
extendable = True
version('1.5.4', git='https://go.googlesource.com/go', tag='go1.5.4')
version('1.6.2', git='https://go.googlesource.com/go', tag='go1.6.2')
variant('test',
default=True,
description="Run tests as part of build, a good idea but quite"
" time consuming")
provides('golang')
# to-do, make non-c self-hosting compilers feasible without backflips
# should be a dep on external go compiler
depends_on('go-bootstrap')
depends_on('git')
def install(self, spec, prefix):
bash = which('bash')
with working_dir('src'):
if '+test' in spec:
bash('all.bash')
else:
bash('make.bash')
try:
os.makedirs(prefix)
except OSError:
pass
for f in glob.glob('*'):
if os.path.isdir(f):
shutil.copytree(f, os.path.join(prefix, f))
else:
shutil.copy2(f, os.path.join(prefix, f))
def setup_environment(self, spack_env, run_env):
spack_env.set('GOROOT_FINAL', self.spec.prefix)
spack_env.set('GOROOT_BOOTSTRAP', self.spec['go-bootstrap'].prefix)
def setup_dependent_package(self, module, ext_spec):
"""Called before go modules' install() methods.
In most cases, extensions will only need to set GOPATH and use go::
env = os.environ
env['GOPATH'] = self.source_path + ':' + env['GOPATH']
go('get', '<package>', env=env)
shutil.copytree('bin', os.path.join(prefix, '/bin'))
"""
# Add a go command/compiler for extensions
module.go = Executable(join_path(self.spec.prefix.bin, 'go'))
def setup_dependent_environment(self, spack_env, run_env, ext_spec):
if os.environ.get('GOROOT', False):
tty.warn('GOROOT is set, this is not recommended')
path_components = []
# Set GOPATH to include paths of dependencies
for d in ext_spec.traverse():
if d.package.extends(self.spec):
path_components.append(d.prefix)
# This *MUST* be first, this is where new code is installed
spack_env.set('GOPATH', ':'.join(path_components))
# Allow packages to find this when using module or dotkit
run_env.prepend_path('GOPATH', ':'.join(
[ext_spec.prefix] + path_components))

View File

@ -0,0 +1,24 @@
from spack import *
import os
class Hub(Package):
"""The github git wrapper"""
homepage = "https://github.com/github/hub"
url = "https://github.com/github/hub/archive/v2.2.3.tar.gz"
version('head', git='https://github.com/github/hub')
version('2.2.3', '6675992ddd16d186eac7ba4484d57f5b')
version('2.2.2', '7edc8f5b5d3c7c392ee191dd999596fc')
version('2.2.1', '889a31ee9d10ae9cb333480d8dbe881f')
version('2.2.0', 'eddce830a079b8480f104aa7496f46fe')
version('1.12.4', '4f2ebb14834c9981b04e40b0d1754717')
extends("go")
def install(self, spec, prefix):
env = os.environ
env['GOPATH'] = self.stage.source_path + ':' + env['GOPATH']
bash = which('bash')
bash(os.path.join('script', 'build'), '-o', os.path.join(prefix, 'bin',
'hub'))

View File

@ -0,0 +1,21 @@
from spack import *
import os
import shutil
class ThePlatinumSearcher(Package):
"""Fast parallel recursive grep alternative"""
homepage = "https://github.com/monochromegane/the_platinum_searcher"
url = "https://github.com/monochromegane/the_platinum_searcher"
package = 'github.com/monochromegane/the_platinum_searcher/...'
version('head', go=package)
extends("go")
def install(self, spec, prefix):
env = os.environ
env['GOPATH'] = self.stage.source_path + ':' + env['GOPATH']
go('install', self.package, env=env)
shutil.copytree('bin', os.path.join(prefix, 'bin'))