summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/fetch_strategy.py54
-rw-r--r--lib/spack/spack/util/executable.py4
2 files changed, 57 insertions, 1 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index e05cb13c1e..0144d26057 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -381,6 +381,60 @@ class VCSFetchStrategy(FetchStrategy):
def __repr__(self):
return "%s<%s>" % (self.__class__, self.url)
+class GoFetchStrategy(VCSFetchStrategy):
+ """Fetch strategy that employs the `go get` infrastructure
+ Use like this in a package:
+
+ version('name', go='github.com/monochromegane/the_platinum_searcher/...')
+
+ Go get does not natively support versions, they can be faked with git
+ """
+ enabled = True
+ required_attributes = ('go',)
+
+ 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.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.
diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py
index d2ccfde69b..0b91b6c360 100644
--- a/lib/spack/spack/util/executable.py
+++ b/lib/spack/spack/util/executable.py
@@ -105,6 +105,8 @@ class Executable(object):
fail_on_error = kwargs.pop("fail_on_error", True)
ignore_errors = kwargs.pop("ignore_errors", ())
+ env = kwargs.get('env', None)
+
# TODO: This is deprecated. Remove in a future version.
return_output = kwargs.pop("return_output", False)
@@ -149,7 +151,7 @@ class Executable(object):
try:
proc = subprocess.Popen(
- cmd, stdin=istream, stderr=estream, stdout=ostream)
+ cmd, stdin=istream, stderr=estream, stdout=ostream, env=env)
out, err = proc.communicate()
rc = self.returncode = proc.returncode