Skip to content

Commit

Permalink
BuildStatus stores all sourcestamps. Interface is not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hborkhuis committed Apr 10, 2012
1 parent 34de9a6 commit 47be49a
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 28 deletions.
4 changes: 2 additions & 2 deletions master/buildbot/interfaces.py
Expand Up @@ -459,8 +459,8 @@ def getReason():
'forced', and 'periodic' are the most likely values. 'try' will be
added in the future."""

def getSourceStamp():
"""Return a SourceStamp object which can be used to re-create
def getSourceStamps():
"""Return a list of SourceStamp objects which can be used to re-create
the source tree that this build used.
This method will return None if the source information is no longer
Expand Down
6 changes: 2 additions & 4 deletions master/buildbot/process/build.py
Expand Up @@ -350,10 +350,8 @@ def setupBuild(self, expectations):
self.progress.setExpectationsFrom(expectations)

# we are now ready to set up our BuildStatus.
# at the moment that schedulers start to deliver sourcestamps per codebase
# buildstatus should support multiple sourcestamps.
# until now schedulers deliver exactly one sourcestamp
self.build_status.setSourceStamp(self.sources[0])
# pass all sourcestamps to the buildstatus
self.build_status.setSourceStamps(self.sources)
self.build_status.setReason(self.reason)
self.build_status.setBlamelist(self.blamelist())
self.build_status.setProgress(self.progress)
Expand Down
20 changes: 17 additions & 3 deletions master/buildbot/process/builder.py
Expand Up @@ -711,13 +711,27 @@ def rebuildBuild(self, bs, reason="<rebuild, no reason given>", extraProperties=
properties.updateFromProperties(extraProperties)

properties_dict = dict((k,(v,s)) for (k,v,s) in properties.asList())
ss = bs.getSourceStamp(absolute=True)
d = ss.getSourceStampSetId(self.master.master)
ssList = bs.getSourceStamps(absolute=True)
def add_sourcestamps(sourcestampsetid, sourcestamps):
dl = []
for ss in sourcestamps:
# add defered to the list
dl.append(ss.addSourceStampToDatabase(self.master.master, sourcestampsetid))
d = defer.gatherResults(dl)
def return_setid(dummy):
log.msg('dummy is %s' % dummy)
return sourcestampsetid
d.addCallback(return_setid)
return d

def add_buildset(sourcestampsetid):
return self.master.master.addBuildset(
builderNames=[self.original.name],
sourcestampsetid=sourcestampsetid, reason=reason, properties=properties_dict)
d.addCallback(add_buildset)
if ssList:
d = ssList[0].getSourceStampSetId(self.master.master)
d.addCallback(add_sourcestamps, ssList[1:])
d.addCallback(add_buildset)
return d

@defer.inlineCallbacks
Expand Down
11 changes: 8 additions & 3 deletions master/buildbot/sourcestamp.py
Expand Up @@ -280,11 +280,16 @@ def upgradeToVersion3(self):
self.codebase = ''
self.wasUpgraded = True

@util.deferredLocked('_getSourceStampSetId_lock')
def getSourceStampSetId(self, master):
"temporary; do not use widely!"
if self.sourcestampsetid:
return defer.succeed(self.sourcestampsetid)
else:
return self.addSourceStampToDatabase(master)


@util.deferredLocked('_getSourceStampSetId_lock')
def addSourceStampToDatabase(self, master, sourcestampsetid = None):
# add it to the DB
patch_body = None
patch_level = None
Expand All @@ -301,8 +306,8 @@ def getSourceStampSetId(self, master):
patch_author, patch_comment = self.patch_info

def get_setid():
if self.sourcestampsetid != None:
return defer.succeed( self.sourcestampsetid )
if sourcestampsetid != None:
return defer.succeed( sourcestampsetid )
else:
return master.db.sourcestampsets.addSourceStampSet()
return d
Expand Down
29 changes: 20 additions & 9 deletions master/buildbot/status/build.py
Expand Up @@ -28,10 +28,10 @@
class BuildStatus(styles.Versioned, properties.PropertiesMixin):
implements(interfaces.IBuildStatus, interfaces.IStatusEvent)

persistenceVersion = 3
persistenceVersion = 4
persistenceForgets = ( 'wasUpgraded', )

source = None
sources = None
reason = None
changes = []
blamelist = []
Expand Down Expand Up @@ -88,10 +88,12 @@ def getPreviousBuild(self):
return None
return self.builder.getBuild(self.number-1)

def getSourceStamp(self, absolute=False):
def getSourceStamps(self, absolute=False):
if not absolute or not self.properties.has_key('got_revision'):
return self.source
return self.source.getAbsoluteSourceStamp(self.properties['got_revision'])
return self.sources
# the got_revision must be stored per sourcestamp (or in the sourcestamp)
#return [ss.getAbsoluteSourceStamp(self.properties['got_revision']) for ss in self.sources]
return [ss.getAbsoluteSourceStamp(ss.revision) for ss in self.sources]

def getReason(self):
return self.reason
Expand Down Expand Up @@ -243,9 +245,11 @@ def addStepWithName(self, name):
def addTestResult(self, result):
self.testResults[result.getName()] = result

def setSourceStamp(self, sourceStamp):
self.source = sourceStamp
self.changes = self.source.changes
def setSourceStamps(self, sourceStamps):
self.sources = sourceStamps
self.changes = []
for source in self.sources:
self.changes.extend(source.changes)

def setReason(self, reason):
self.reason = reason
Expand Down Expand Up @@ -394,6 +398,12 @@ def upgradeToVersion3(self):
self.properties.update(propdict, "Upgrade from previous version")
self.wasUpgraded = True

def upgradeToVersion4(self):
# buildstatus contains list of sourcestamps, convert single to list
self.sources = [self.source]
del self.source
self.wasUpgraded = True

def checkLogfiles(self):
# check that all logfiles exist, and remove references to any that
# have been deleted (e.g., by purge())
Expand Down Expand Up @@ -427,7 +437,8 @@ def asDict(self):
# Constant
result['builderName'] = self.builder.name
result['number'] = self.getNumber()
result['sourceStamp'] = self.getSourceStamp().asDict()
# TODO: enable multiple sourcestamps to outside the buildstatus
result['sourceStamp'] = self.getSourceStamps()[0].asDict()
result['reason'] = self.getReason()
result['blame'] = self.getResponsibleUsers()

Expand Down
8 changes: 6 additions & 2 deletions master/buildbot/status/web/base.py
Expand Up @@ -334,7 +334,8 @@ def handle(data):
return data
d.addCallback(handle)
def ok(data):
request.write(data)
if data:
request.write(data)
try:
request.finish()
except RuntimeError:
Expand Down Expand Up @@ -444,7 +445,10 @@ def get_line_values(self, req, build, include_builder=True):
text = build.getText()
rev = str(build.getProperty("got_revision", "??"))
css_class = css_classes.get(results, "")
repo = build.getSourceStamp().repository
ss_list = build.getSourceStamps()
if ss_list:
# TODO: support multiple sourcestamps in web interface
repo = ss_list[0].repository

if type(text) == list:
text = " ".join(text)
Expand Down
5 changes: 4 additions & 1 deletion master/buildbot/status/web/build.py
Expand Up @@ -159,7 +159,10 @@ def content(self, req, cxt):
if b.getTestResults():
cxt['tests_link'] = req.childLink("tests")

ss = cxt['ss'] = b.getSourceStamp()
ssList = b.getSourceStamps()
if ssList:
# TODO: support multiple sourcestamps
ss = cxt['ss'] = ssList[0]

if ss.branch is None and ss.revision is None and ss.patch is None and not ss.changes:
cxt['most_recent_rev_build'] = True
Expand Down
12 changes: 8 additions & 4 deletions master/buildbot/status/web/grid.py
Expand Up @@ -103,7 +103,8 @@ def getRecentBuilds(self, builder, numBuilds, branch):
num = 0
while build and num < numBuilds:
start = build.getTimes()[0]
ss = build.getSourceStamp(absolute=True)
#TODO: support multiple sourcestamps
ss = build.getSourceStamps(absolute=True)[0]

okay_build = True

Expand Down Expand Up @@ -134,7 +135,8 @@ def getRecentSourcestamps(self, status, numBuilds, categories, branch):
if categories and builder.category not in categories:
continue
for build in self.getRecentBuilds(builder, numBuilds, branch):
ss = build.getSourceStamp(absolute=True)
#TODO: support multiple sourcestamps
ss = build.getSourceStamps(absolute=True)[0]
key= self.getSourceStampKey(ss)
start = build.getTimes()[0]
if key not in sourcestamps or sourcestamps[key][1] > start:
Expand Down Expand Up @@ -190,7 +192,8 @@ def content(self, request, cxt):
continue

for build in self.getRecentBuilds(builder, numBuilds, branch):
ss = build.getSourceStamp(absolute=True)
#TODO: support multiple sourcestamps
ss = build.getSourceStamps(absolute=True)[0]
key= self.getSourceStampKey(ss)
for i in range(len(stamps)):
if key == self.getSourceStampKey(stamps[i]) and builds[i] is None:
Expand Down Expand Up @@ -259,7 +262,8 @@ def content(self, request, cxt):
continue

for build in self.getRecentBuilds(builder, numBuilds, branch):
ss = build.getSourceStamp(absolute=True)
#TODO: support multiple sourcestamps
ss = build.getSourceStamps(absolute=True)[0]
key = self.getSourceStampKey(ss)
for i in range(len(stamps)):
if key == self.getSourceStampKey(stamps[i]) and builds[i] is None:
Expand Down

0 comments on commit 47be49a

Please sign in to comment.