Skip to content

Commit

Permalink
source steps changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hborkhuis committed Jan 23, 2012
1 parent e897235 commit d7d3bd6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
14 changes: 8 additions & 6 deletions master/buildbot/process/build.py
Expand Up @@ -93,21 +93,23 @@ def setSlaveEnvironment(self, env):

def getSourceStamp(self, repository=None):
if repository is None:
if len(self.sources) >=1:
if self.sources:
return self.sources[0]
else:
return None
for source in self.sources:
if source.repository == repository:
# The passed repository may also contains the location of the repository
# like https://github.com/buildbot/buildbot
# There is a hit if the source.repository is equal to the lastpart of the
# passed repository
if repository.endswith(source.repository):
return source
return None

def allChanges(self):
all_changes = []
for s in self.sources:
all_changes.extend(s.changes)
return all_changes

for c in s.changes:
yield c

def allFiles(self):
# return a list of all source files that were changed
Expand Down
47 changes: 25 additions & 22 deletions master/buildbot/process/buildrequest.py
Expand Up @@ -128,32 +128,38 @@ def _make_br(cls, brid, brdict, master):
sslist = wfd.getResult()
assert len(sslist) > 0, "Empty sourcestampset: db schema enforces set to exist but cannot enforce a non empty set"

# and turn it into a SourceStamp
# and turn it into a SourceStamps
buildrequest.sources = {}
for ssdict in sslist:
wfd = defer.waitForDeferred(
sourcestamp.SourceStamp.fromSsdict(master, ssdict))
yield wfd
source = wfd.getResult()
def store_source(source):
buildrequest.sources[source.repository] = source
if buildrequest.source == None:
buildrequest.source = source

dlist = []
for ssdict in sslist:
d = sourcestamp.SourceStamp.fromSsdict(master, ssdict)
d.addCallback(store_source)
dlist.append(d)

dl = defer.gatherResults(dlist)
wfd = defer.waitForDeferred(dl)
yield wfd
wfd.getResult()

if buildrequest.sources:
buildrequest.source = buildrequest.sources.values()[0]

yield buildrequest # return value

@staticmethod
def collect_repositories(repositories, sources):
def _collect_repositories(repositories, sources):
for s in sources.itervalues():
if s.repository not in repositories:
repositories.append(s.repository)

def canBeMergedWith(self, other):
can_be_merged_with = True

# get all repositories from both requests
all_repositories = []
BuildRequest.collect_repositories(all_repositories, self.sources)
BuildRequest.collect_repositories(all_repositories, other.sources)
BuildRequest._collect_repositories(all_repositories, self.sources)
BuildRequest._collect_repositories(all_repositories, other.sources)

# walk along the repositories
for repository in all_repositories:
Expand All @@ -164,20 +170,17 @@ def canBeMergedWith(self, other):
other_source = other.sources[repository]
# do both requests have sourcestamp for this repository?
if self_source is not None and other_source is not None:
can_be_merged_with = can_be_merged_with and \
self_source.canBeMergedWith(other_source)
if not can_be_merged_with:
break

return can_be_merged_with
if not self_source.canBeMergedWith(other_source):
return False
return True

def mergeSourceStampsWith(self, others):
""" Returns one merged sourcestamp for every repository """
# get all repositories from both requests
all_repositories = []
BuildRequest.collect_repositories(all_repositories, self.sources)
BuildRequest._collect_repositories(all_repositories, self.sources)
for other in others:
BuildRequest.collect_repositories(all_repositories, other.sources)
BuildRequest._collect_repositories(all_repositories, other.sources)

all_merged_sources = {}
# walk along the repositories
Expand All @@ -188,7 +191,7 @@ def mergeSourceStampsWith(self, others):
for other in others:
if repository in other.sources:
all_sources.append(other.sources[repository])
assert(len(all_sources)>0, "each repository should have atleast one sourcestamp")
assert len(all_sources)>0, "each repository should have atleast one sourcestamp"
all_merged_sources[repository] = all_sources[0].mergeWith(all_sources[1:])

return [source for source in all_merged_sources.itervalues()]
Expand Down
9 changes: 9 additions & 0 deletions master/buildbot/steps/source/mercurial.py
Expand Up @@ -275,6 +275,15 @@ def computeSourceRevision(self, changes):
"the most recent" % len(changes))
return changes[-1].revision

def getRepository(self):
""" Identify the unique repository for this step """
if self.branchType == 'dirname':
return self.baseURL
elif self.branchType == 'inrepo':
return self.repourl
else:
raise ValueError("Invalid branch type")

def _getCurrentBranch(self):
if self.branchType == 'dirname':
return defer.succeed(self.branch)
Expand Down
8 changes: 7 additions & 1 deletion master/buildbot/steps/source/oldsource.py
Expand Up @@ -262,7 +262,13 @@ def start(self):

# what source stamp would this build like to use?
id = self.getRepository()
s = self.build.getSourceStamp(id)
try:
s = self.build.getSourceStamp(id)
except KeyError:
log.msg("The source step cannot get the sourcestamp for repository '%s'" % id)
self.step_status.setText(["Cannot get sourcestamp for repository '%s'" % id])
self.addCompleteLog("log","Step failed in getting the correct sourcestamp for repository '%s' from build" % id)
return FAILURE
self.sourcestamp = s

# if branch is None, then use the Step's "default" branch
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/test/unit/test_process_buildrequest.py
Expand Up @@ -307,10 +307,10 @@ def check(_):
if source.repository == 'svn://d..':
source2 = source

self.assertFalse(source1 == None)
self.assertTrue(source1 != None)
self.assertEqual(source1.revision,'1800')

self.assertFalse(source2 == None)
self.assertTrue(source2 != None)
self.assertEqual(source2.revision,'2100')

self.assertEqual([c.number for c in source1.changes], [17])
Expand Down

0 comments on commit d7d3bd6

Please sign in to comment.