fetch_strategy: add a source_id to fetches

This will be included in the full hash of packages.
This commit is contained in:
Peter Scheibel 2018-02-06 10:45:41 -05:00 committed by Todd Gamblin
parent 6058cc1770
commit 39cb9d0397

View File

@ -141,6 +141,14 @@ def cachable(self):
bool: True if can cache, False otherwise. 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. def __str__(self): # Should be human readable URL.
return "FetchStrategy.__str___" return "FetchStrategy.__str___"
@ -160,6 +168,11 @@ class FetchStrategyComposite(object):
matches = FetchStrategy.matches matches = FetchStrategy.matches
set_stage = FetchStrategy.set_stage 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): class URLFetchStrategy(FetchStrategy):
"""FetchStrategy that pulls source code from a URL for an archive, """FetchStrategy that pulls source code from a URL for an archive,
@ -197,6 +210,9 @@ def curl(self):
self._curl = which('curl', required=True) self._curl = which('curl', required=True)
return self._curl return self._curl
def source_id(self):
return self.digest
@_needs_stage @_needs_stage
def fetch(self): def fetch(self):
if self.archive_file: if self.archive_file:
@ -602,6 +618,16 @@ def git(self):
def cachable(self): def cachable(self):
return bool(self.commit or self.tag) 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): def fetch(self):
if self.stage.source_path: if self.stage.source_path:
tty.msg("Already fetched %s" % self.stage.source_path) tty.msg("Already fetched %s" % self.stage.source_path)
@ -744,6 +770,18 @@ def svn(self):
def cachable(self): def cachable(self):
return bool(self.revision) 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 @_needs_stage
def fetch(self): def fetch(self):
if self.stage.source_path: if self.stage.source_path:
@ -839,6 +877,14 @@ def hg(self):
def cachable(self): def cachable(self):
return bool(self.revision) 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 @_needs_stage
def fetch(self): def fetch(self):
if self.stage.source_path: if self.stage.source_path: