summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2018-02-06 10:45:41 -0500
committerTodd Gamblin <tgamblin@llnl.gov>2018-03-20 00:29:54 -0700
commit39cb9d039713e91b0d4a89f61b0d432ba313329f (patch)
tree43bc75f2a68e9f50c78dd352a0d06b7bee88a716 /lib
parent6058cc177031ff8ce05a5a7b4c1df20b84d3226a (diff)
downloadspack-39cb9d039713e91b0d4a89f61b0d432ba313329f.tar.gz
spack-39cb9d039713e91b0d4a89f61b0d432ba313329f.tar.bz2
spack-39cb9d039713e91b0d4a89f61b0d432ba313329f.tar.xz
spack-39cb9d039713e91b0d4a89f61b0d432ba313329f.zip
fetch_strategy: add a source_id to fetches
This will be included in the full hash of packages.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/fetch_strategy.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 2cbe43cd1b..5c7b3aa395 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -141,6 +141,14 @@ class FetchStrategy(with_metaclass(FSMeta, object)):
bool: True if can cache, False otherwise.
"""
+ def source_id(self):
+ """A unique ID for the source.
+
+ The returned value is added to the content which determines the full
+ hash for a package using `str()`.
+ """
+ raise NotImplementedError
+
def __str__(self): # Should be human readable URL.
return "FetchStrategy.__str___"
@@ -160,6 +168,11 @@ class FetchStrategyComposite(object):
matches = FetchStrategy.matches
set_stage = FetchStrategy.set_stage
+ def source_id(self):
+ component_ids = tuple(i.source_id() for i in self)
+ if all(component_ids):
+ return component_ids
+
class URLFetchStrategy(FetchStrategy):
"""FetchStrategy that pulls source code from a URL for an archive,
@@ -197,6 +210,9 @@ class URLFetchStrategy(FetchStrategy):
self._curl = which('curl', required=True)
return self._curl
+ def source_id(self):
+ return self.digest
+
@_needs_stage
def fetch(self):
if self.archive_file:
@@ -602,6 +618,16 @@ class GitFetchStrategy(VCSFetchStrategy):
def cachable(self):
return bool(self.commit or self.tag)
+ def source_id(self):
+ return self.commit or self.tag
+
+ def get_source_id(self):
+ if not self.branch:
+ return
+ output = self.git('ls-remote', self.url, self.branch, output=str)
+ if output:
+ return output.split()[0]
+
def fetch(self):
if self.stage.source_path:
tty.msg("Already fetched %s" % self.stage.source_path)
@@ -744,6 +770,18 @@ class SvnFetchStrategy(VCSFetchStrategy):
def cachable(self):
return bool(self.revision)
+ def source_id(self):
+ return self.revision
+
+ def get_source_id(self):
+ output = self.svn('info', self.url, output=str)
+ if not output:
+ return None
+ lines = output.split('\n')
+ for line in lines:
+ if line.startswith('Revision:'):
+ return line.split()[-1]
+
@_needs_stage
def fetch(self):
if self.stage.source_path:
@@ -839,6 +877,14 @@ class HgFetchStrategy(VCSFetchStrategy):
def cachable(self):
return bool(self.revision)
+ def source_id(self):
+ return self.revision
+
+ def get_source_id(self):
+ output = self.hg('id', self.url, output=str)
+ if output:
+ return output.strip()
+
@_needs_stage
def fetch(self):
if self.stage.source_path: