Skip to content

Commit

Permalink
Restore BK slave-side step.
Browse files Browse the repository at this point in the history
Note that Buildbot was not released with this step missing, so no
compatibility concerns exist.

Fixes buildbot#2223.  Refs buildbot#891.  Refs buildbot#2198.
  • Loading branch information
djmitche committed Jun 24, 2012
1 parent 27055a7 commit ca6941b
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 4 deletions.
4 changes: 4 additions & 0 deletions MAINTAINERS.txt
Expand Up @@ -58,6 +58,10 @@ Git VC
M: Amber Yust <ayust@yelp.com> (irc:Aaeriele)
U: http://trac.buildbot.net/wiki/git

BitKeeper VC
S: Last-Rites
U: http://trac.buildbot.net/wiki/bk

Darcs VC
S: Orphaned
U: http://trac.buildbot.net/wiki/darcs
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/steps/source/__init__.py
Expand Up @@ -15,7 +15,7 @@

from buildbot.steps.source.base import Source
from buildbot.steps.source.oldsource import CVS, \
SVN, Git, Darcs, Repo, Bzr, Mercurial, P4, Monotone
SVN, Git, Darcs, Repo, Bzr, Mercurial, P4, Monotone, BK

_hush_pyflakes = [ Source, CVS, SVN, \
Git, Darcs, Repo, Bzr, Mercurial, P4, Monotone ]
Git, Darcs, Repo, Bzr, Mercurial, P4, Monotone, BK ]
73 changes: 73 additions & 0 deletions master/buildbot/steps/source/oldsource.py
Expand Up @@ -139,6 +139,79 @@ def start(self):
Source.start(self)



class BK(SlaveSource):
"""I perform BitKeeper checkout/update operations."""

name = 'bk'

renderables = [ 'bkurl', 'baseURL' ]

def __init__(self, bkurl=None, baseURL=None,
directory=None, extra_args=None, **kwargs):
"""
@type bkurl: string
@param bkurl: the URL which points to the BitKeeper server.
@type baseURL: string
@param baseURL: if branches are enabled, this is the base URL to
which a branch name will be appended. It should
probably end in a slash. Use exactly one of
C{bkurl} and C{baseURL}.
"""

self.bkurl = _ComputeRepositoryURL(bkurl)
self.baseURL = _ComputeRepositoryURL(baseURL)
self.extra_args = extra_args

Source.__init__(self, **kwargs)
self.addFactoryArguments(bkurl=bkurl,
baseURL=baseURL,
directory=directory,
extra_args=extra_args,
)

if bkurl and baseURL:
raise ValueError("you must use exactly one of bkurl and baseURL")


def computeSourceRevision(self, changes):
return changes.revision


def startVC(self, branch, revision, patch):

warnings = []
slavever = self.slaveVersion("bk")
if not slavever:
m = "slave does not have the 'bk' command"
raise BuildSlaveTooOldError(m)

if self.bkurl:
assert not branch # we need baseURL= to use branches
self.args['bkurl'] = self.bkurl
else:
self.args['bkurl'] = self.baseURL + branch
self.args['revision'] = revision
self.args['patch'] = patch
self.args['branch'] = branch
if self.extra_args is not None:
self.args['extra_args'] = self.extra_args

revstuff = []
revstuff.append("[branch]")
if revision is not None:
revstuff.append("r%s" % revision)
if patch is not None:
revstuff.append("[patch]")
self.description.extend(revstuff)
self.descriptionDone.extend(revstuff)

cmd = RemoteCommand("bk", self.args)
self.startCommand(cmd, warnings)



class CVS(SlaveSource):
"""I do CVS checkout/update operations.
Expand Down
4 changes: 4 additions & 0 deletions master/buildbot/test/regressions/test_oldpaths.py
Expand Up @@ -185,3 +185,7 @@ def test_steps_source_Monotone(self):
from buildbot.steps.source import Monotone
assert Monotone

def test_steps_source_BK(self):
from buildbot.steps.source import BK
assert BK

165 changes: 165 additions & 0 deletions master/contrib/bk_buildbot.py
@@ -0,0 +1,165 @@
#!/usr/local/bin/python
#
# BitKeeper hook script.
#
# svn_buildbot.py was used as a base for this file, if you find any bugs or
# errors please email me.
#
# Amar Takhar <amar@ntp.org>


'''
/path/to/bk_buildbot.py --repository "$REPOS" --revision "$REV" --branch \
"<branch>" --bbserver localhost --bbport 9989
'''

import commands
import sys
import os
import re
if sys.version_info < (2, 6):
import sets

# We have hackish "-d" handling here rather than in the Options
# subclass below because a common error will be to not have twisted in
# PYTHONPATH; we want to be able to print that error to the log if
# debug mode is on, so we set it up before the imports.

DEBUG = None

if '-d' in sys.argv:
i = sys.argv.index('-d')
DEBUG = sys.argv[i+1]
del sys.argv[i]
del sys.argv[i]

if DEBUG:
f = open(DEBUG, 'a')
sys.stderr = f
sys.stdout = f


from twisted.internet import defer, reactor
from twisted.python import usage
from twisted.spread import pb
from twisted.cred import credentials


class Options(usage.Options):
optParameters = [
['repository', 'r', None,
"The repository that was changed."],
['revision', 'v', None,
"The revision that we want to examine (default: latest)"],
['branch', 'b', None,
"Name of the branch to insert into the branch field. (REQUIRED)"],
['category', 'c', None,
"Schedular category."],
['bbserver', 's', 'localhost',
"The hostname of the server that buildbot is running on"],
['bbport', 'p', 8007,
"The port that buildbot is listening on"]
]
optFlags = [
['dryrun', 'n', "Do not actually send changes"],
]

def __init__(self):
usage.Options.__init__(self)

def postOptions(self):
if self['repository'] is None:
raise usage.error("You must pass --repository")

class ChangeSender:

def getChanges(self, opts):
"""Generate and stash a list of Change dictionaries, ready to be sent
to the buildmaster's PBChangeSource."""

# first we extract information about the files that were changed
repo = opts['repository']
print "Repo:", repo
rev_arg = ''
if opts['revision']:
rev_arg = '-r"%s"' % (opts['revision'], )
changed = commands.getoutput("bk changes -v %s -d':GFILE:\\n' '%s'" % (
rev_arg, repo)).split('\n')

# Remove the first line, it's an info message you can't remove (annoying)
del changed[0]

change_info = commands.getoutput("bk changes %s -d':USER:\\n$each(:C:){(:C:)\\n}' '%s'" % (
rev_arg, repo)).split('\n')

# Remove the first line, it's an info message you can't remove (annoying)
del change_info[0]

who = change_info.pop(0)
branch = opts['branch']
message = '\n'.join(change_info)
revision = opts.get('revision')

changes = {'who': who,
'branch': branch,
'files': changed,
'comments': message,
'revision': revision}

if opts.get('category'):
changes['category'] = opts.get('category')

return changes


def sendChanges(self, opts, changes):
pbcf = pb.PBClientFactory()
reactor.connectTCP(opts['bbserver'], int(opts['bbport']), pbcf)
d = pbcf.login(credentials.UsernamePassword('change', 'changepw'))
d.addCallback(self.sendAllChanges, changes)
return d

def sendAllChanges(self, remote, changes):
dl = remote.callRemote('addChange', changes)
return dl

def run(self):
opts = Options()
try:
opts.parseOptions()
if not opts['branch']:
print "You must supply a branch with -b or --branch."
sys.exit(1);

except usage.error, ue:
print opts
print "%s: %s" % (sys.argv[0], ue)
sys.exit()

changes = self.getChanges(opts)
if opts['dryrun']:
for k in changes.keys():
print "[%10s]: %s" % (k, changes[k])
print "*NOT* sending any changes"
return

d = self.sendChanges(opts, changes)

def quit(*why):
print "quitting! because", why
reactor.stop()

def failed(f):
print "FAILURE: %s" % f
reactor.stop()

d.addErrback(failed)
d.addCallback(quit, "SUCCESS")
reactor.callLater(60, quit, "TIMEOUT")

reactor.run()


if __name__ == '__main__':
s = ChangeSender()
s.run()
1 change: 1 addition & 0 deletions master/docs/developer/definitions.rst
Expand Up @@ -31,6 +31,7 @@ Mercurial changeset sha1 hash different repos
Darcs ? none [2] different repos
Bazaar ? ? ?
Perforce ? ? ?
BitKeeper changeset ? different repos
=========== =========== =========== ===================

* [1] note that CVS only tracks patches to individual files. Buildbot tries to
Expand Down
19 changes: 19 additions & 0 deletions master/docs/manual/cfg-buildsteps.rst
Expand Up @@ -1177,6 +1177,25 @@ introduced by a pending changeset.
Gerrit integration can be also triggered using forced build with ``gerrit_change``
property with value in format: ``change_number/patchset_number``.

.. bb:step:: BK (Slave-Side)
BitKeeper (Slave-Side)
++++++++++++++++++++++

The :bb:step:`BK <BK (Slave-Side)>` build step performs a `BitKeeper <http://www.bitkeeper.com/>`_
checkout or update.

The BitKeeper step takes the following arguments:

``repourl``
(required unless ``baseURL`` is provided): the URL at which the
BitKeeper source repository is available.

``baseURL``
(required unless ``repourl`` is provided): the base repository URL,
to which a branch name will be appended. It should probably end in a
slash.

.. bb:step:: Repo (Slave-Side)
Repo (Slave-Side)
Expand Down
2 changes: 0 additions & 2 deletions master/docs/release-notes.rst
Expand Up @@ -103,8 +103,6 @@ Slave
Deprecations, Removals, and Non-Compatible Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* BK support has been removed in this release - see :bb:bug:`2198`.

Features
~~~~~~~~

Expand Down

0 comments on commit ca6941b

Please sign in to comment.