waterfall: fix DST calculation. Closes #137.
[buildbot.git] / buildbot / buildset.py
blob31abb2abbe39cb8f4c13aac21cab060b59d245fd
2 from buildbot.process import base
3 from buildbot.status import builder
6 class BuildSet:
7 """I represent a set of potential Builds, all of the same source tree,
8 across a specified list of Builders. I can represent a build of a
9 specific version of the source tree (named by source.branch and
10 source.revision), or a build of a certain set of Changes
11 (source.changes=list)."""
13 def __init__(self, builderNames, source, reason=None, bsid=None):
14 """
15 @param source: a L{buildbot.sourcestamp.SourceStamp}
16 """
17 self.builderNames = builderNames
18 self.source = source
19 self.reason = reason
20 self.stillHopeful = True
21 self.status = bss = builder.BuildSetStatus(source, reason,
22 builderNames, bsid)
24 def waitUntilSuccess(self):
25 return self.status.waitUntilSuccess()
26 def waitUntilFinished(self):
27 return self.status.waitUntilFinished()
29 def start(self, builders):
30 """This is called by the BuildMaster to actually create and submit
31 the BuildRequests."""
32 self.requests = []
33 reqs = []
35 # create the requests
36 for b in builders:
37 req = base.BuildRequest(self.reason, self.source, b.name)
38 reqs.append((b, req))
39 self.requests.append(req)
40 d = req.waitUntilFinished()
41 d.addCallback(self.requestFinished, req)
43 # tell our status about them
44 req_statuses = [req.status for req in self.requests]
45 self.status.setBuildRequestStatuses(req_statuses)
47 # now submit them
48 for b,req in reqs:
49 b.submitBuildRequest(req)
51 def requestFinished(self, buildstatus, req):
52 # TODO: this is where individual build status results are aggregated
53 # into a BuildSet-wide status. Consider making a rule that says one
54 # WARNINGS results in the overall status being WARNINGS too. The
55 # current rule is that any FAILURE means FAILURE, otherwise you get
56 # SUCCESS.
57 self.requests.remove(req)
58 results = buildstatus.getResults()
59 if results == builder.FAILURE:
60 self.status.setResults(results)
61 if self.stillHopeful:
62 # oh, cruel reality cuts deep. no joy for you. This is the
63 # first failure. This flunks the overall BuildSet, so we can
64 # notify success watchers that they aren't going to be happy.
65 self.stillHopeful = False
66 self.status.giveUpHope()
67 self.status.notifySuccessWatchers()
68 if not self.requests:
69 # that was the last build, so we can notify finished watchers. If
70 # we haven't failed by now, we can claim success.
71 if self.stillHopeful:
72 self.status.setResults(builder.SUCCESS)
73 self.status.notifySuccessWatchers()
74 self.status.notifyFinishedWatchers()