From 39cb9d039713e91b0d4a89f61b0d432ba313329f Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Tue, 6 Feb 2018 10:45:41 -0500 Subject: fetch_strategy: add a source_id to fetches This will be included in the full hash of packages. --- lib/spack/spack/fetch_strategy.py | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'lib') 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: -- cgit v1.2.3-70-g09d2