bzr-p4: Perforce foreign branches for Bazaar

John Arbash Meinel john at arbash-meinel.com
Mon Aug 4 14:06:55 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matt McClure wrote:
| On Tue, Jul 15, 2008 at 3:40 AM, Ian Clatworthy
| <ian.clatworthy at canonical.com> wrote:
|> Matt McClure wrote:
|>> Ian,
|>>
|>> Please do add me to the fastimport team.  I'm not certain how much
|>> I'll use it in the near term, but at least I'll be able to check it
|>> out some more.
|> Done.
|>
|>> I've started covering git-p4 with some tests.
|>> (http://mlm.webfactional.com/bzr-p4)
|
| I pushed a bunch of changes to http://mlm.webfactional.com/bzr-p4
| today, including NEWS and TODO files to summarize what's done and
| where I'm headed.

Would you be okay registering this as a project in Launchpad and having
it mirrored/hosted there? I'm happy to set up the project for you, as
I'm mostly interested in just getting your branch mirrored, in case
anything should happen to your net connectivity.

|
| My next two user stories are:
|
|     * As a developer, I want a way to easily run all tests.
|
|         Currently, I do 'python test_git_p4.py', followed by 'python
| test_dogfood.py', etc.  I don't have anything nearly as nice as 'bzr
| selftest'.
|
|     * As a developer, I want continuous integration, automatically
| triggered, for Windows and Cygwin test execution.
|
| How could I leverage Bazaar's test runner, or something similar to
| fulfill the first?

Bazaar has customized its unittest running quite a bit. If this is meant
to be a plugin for bzr, the fact that your "__init__.py" has
'test_suite()' defined is sufficient for "bzr selftest" to automatically
find and run all of the tests.

If you wanted to run *just* the plugin tests, you would then do:

bzr selftest -s bzrlib.plugins.p4

(or whatever that plugin is supposed to be named when installed.)

Then again, looking at your 'setup_env.*' stuff, it seems like your test
suite is not self contained. (You have to have a P4 server running at a
known location, etc. And presumably this means it will 'clobber' the
commit history on the server.)

I don't know enough about P4, but is it possible to start/stop a server
as part of running your tests? So that you can create a new instance,
run your tests in it, and then stop and delete that instance? I guess I
do see that you have a "P4D" class (presumably p4-daemon).

Anyway, the other alternative is to just use bzrlib.tests.run_suite(),
passing in your test suite.

Or you can crib some of the code from that and write your own.

|
| What resources are on Launchpad or elsewhere that I could use for
| continuous integration?
|
| Matt

I don't know of any hosting that currently provides CI for bazaar. I
know it has been discussed as part of Launchpad (similar to how the PPA,
etc is configured).

There are 2 ways I can think of to do so

1) Set up a PQM instance, which is in charge of your 'mainline'. This
works very well for the Bazaar project itself. ATM, setting up a PQM
instance is a bit difficult, but Daniel Watkins has been making great
strides in improving this.

2) Set up a pre-commit hook that runs the test suite before allowing the
commit to succeed. I would probably make this a "pre-branch-tip-changed"
hook, so that 'bzr push' doesn't circumvent the testing.

In general, it would be something like:

~ def check_test_suite_clean(params):
~   if not params.branch.base.endswith('trunk'):
	# You probably also want to check that this is a bzr-p4 branch
	return # This only runs on the mainline
~   # Create a temporary working directory to run the tests in
~   tempdir = tempfile.mkdtemp(prefix='bzr-p4-tests')
~   try:
~     create_checkout_and_run_tests(params, tempdir)
~   finally:
~     bzrlib.osutils.rmtree(tempdir)

~ def create_checkout_and_run_tests(params, tempdir)
~   checkout = params.branch.create_checkout(tempdir + '/checkout'
					    lightweight=True)
~   p = subprocess.Popen([tempdir + '/checkout/tests/test_bzr2p4.py'],
			stdout=subprocess.PIPE,
			stderr=subprocess.PIPE,
		       )
~   (stdout, stderr) = p.communicate()
~   if p.returncode != 0:
~     raise bzrlib.errors.TipChangeRejected('test suite not clean')

~ bzrlib.branch.Branch.hooks.install_named_hook(
	'pre_change_branch_tip', check_test_suite_clean
	'bzr-p4-test-suite')

You would then turn this into a bzr plugin and install it wherever you
will be updating the bzr-p4 mainline. I believe it will work even over
bzr+ssh. So if you configure it on your server, doing:

bzr push bzr+ssh://server/.../bzr-p4/trunk

Will cause the test suite to run on the server, and will reject your
push if the test suite does not pass cleanly. (It will also work if you
use a checkout and just run 'bzr commit'.)

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiW/u8ACgkQJdeBCYSNAAOVQwCeL3Awfs2JSY4qzQ7ygJh2uckW
StIAn0WnsO9JT11MKs2Dw2EAzJmWAkkh
=tz28
-----END PGP SIGNATURE-----



More information about the bazaar mailing list