Package buildbot :: Module sourcestamp
[frames] | no frames]

Source Code for Module buildbot.sourcestamp

 1  from zope.interface import implements 
 2  from buildbot import util, interfaces 
 3   
4 -class SourceStamp(util.ComparableMixin):
5 """This is a tuple of (branch, revision, patchspec, changes). 6 7 C{branch} is always valid, although it may be None to let the Source 8 step use its default branch. There are three possibilities for the 9 remaining elements: 10 - (revision=REV, patchspec=None, changes=None): build REV. If REV is 11 None, build the HEAD revision from the given branch. 12 - (revision=REV, patchspec=(LEVEL, DIFF), changes=None): checkout REV, 13 then apply a patch to the source, with C{patch -pPATCHLEVEL <DIFF}. 14 If REV is None, checkout HEAD and patch it. 15 - (revision=None, patchspec=None, changes=[CHANGES]): let the Source 16 step check out the latest revision indicated by the given Changes. 17 CHANGES is a tuple of L{buildbot.changes.changes.Change} instances, 18 and all must be on the same branch. 19 """ 20 21 # all four of these are publically visible attributes 22 branch = None 23 revision = None 24 patch = None 25 changes = () 26 27 compare_attrs = ('branch', 'revision', 'patch', 'changes') 28 29 implements(interfaces.ISourceStamp) 30
31 - def __init__(self, branch=None, revision=None, patch=None, 32 changes=None):
33 self.branch = branch 34 self.revision = revision 35 self.patch = patch 36 if changes: 37 self.changes = tuple(changes) 38 # set branch and revision to most recent change 39 self.branch = changes[-1].branch 40 self.revision = changes[-1].revision
41
42 - def canBeMergedWith(self, other):
43 if other.branch != self.branch: 44 return False # the builds are completely unrelated 45 46 if self.changes and other.changes: 47 # TODO: consider not merging these. It's a tradeoff between 48 # minimizing the number of builds and obtaining finer-grained 49 # results. 50 return True 51 elif self.changes and not other.changes: 52 return False # we're using changes, they aren't 53 elif not self.changes and other.changes: 54 return False # they're using changes, we aren't 55 56 if self.patch or other.patch: 57 return False # you can't merge patched builds with anything 58 if self.revision == other.revision: 59 # both builds are using the same specific revision, so they can 60 # be merged. It might be the case that revision==None, so they're 61 # both building HEAD. 62 return True 63 64 return False
65
66 - def mergeWith(self, others):
67 """Generate a SourceStamp for the merger of me and all the other 68 BuildRequests. This is called by a Build when it starts, to figure 69 out what its sourceStamp should be.""" 70 71 # either we're all building the same thing (changes==None), or we're 72 # all building changes (which can be merged) 73 changes = [] 74 changes.extend(self.changes) 75 for req in others: 76 assert self.canBeMergedWith(req) # should have been checked already 77 changes.extend(req.changes) 78 newsource = SourceStamp(branch=self.branch, 79 revision=self.revision, 80 patch=self.patch, 81 changes=changes) 82 return newsource
83
84 - def getAbsoluteSourceStamp(self, got_revision):
85 return SourceStamp(branch=self.branch, revision=got_revision, patch=self.patch)
86
87 - def getText(self):
88 # TODO: this won't work for VC's with huge 'revision' strings 89 if self.revision is None: 90 return [ "latest" ] 91 text = [ str(self.revision) ] 92 if self.branch: 93 text.append("in '%s'" % self.branch) 94 if self.patch: 95 text.append("[patch]") 96 return text
97