[Pkg-bazaar-commits] r200 ./bzr-builddeb/people/jdw/dev: Support $UPSTREAM_VERSION in the export-upstream-revision config option.
James Westby
jw+debian at jameswestby.net
Mon Sep 17 20:46:33 UTC 2007
------------------------------------------------------------
revno: 200
committer: James Westby <jw+debian at jameswestby.net>
branch nick: dev
timestamp: Mon 2007-09-17 21:46:33 +0100
message:
Support $UPSTREAM_VERSION in the export-upstream-revision config option.
This is substituted with the upstream version the plugin is looking for, so
that it can be used to point to the correct tag.
modified:
__init__.py
config.py
debian/changelog
doc/user_manual/export_upstream.rst
tests/blackbox/test_builddeb.py
tests/test_config.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-09-17 19:39:24 +0000
+++ b/__init__.py 2007-09-17 20:46:33 +0000
@@ -186,12 +186,6 @@
if not merge:
merge = config.merge
- if export_upstream is None:
- export_upstream = config.export_upstream
-
- if export_upstream_revision is None:
- export_upstream_revision = config.export_upstream_revision
-
if merge:
info("Running in merge mode")
else:
@@ -243,6 +237,14 @@
(changelog, larstiq) = find_changelog(t, merge)
+ config.set_version(changelog.version)
+
+ if export_upstream is None:
+ export_upstream = config.export_upstream
+
+ if export_upstream_revision is None:
+ export_upstream_revision = config.export_upstream_revision
+
if build_dir is None:
build_dir = config.build_dir
if build_dir is None:
=== modified file 'config.py'
--- a/config.py 2007-09-16 20:06:53 +0000
+++ b/config.py 2007-09-17 20:46:33 +0000
@@ -18,10 +18,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-from StringIO import StringIO
-
-from bzrlib.config import ConfigObj, IniBasedConfig, TreeConfig
-from bzrlib import errors
+from bzrlib.config import ConfigObj, TreeConfig
from bzrlib.trace import mutter
@@ -33,7 +30,7 @@
section = 'BUILDDEB'
- def __init__(self, files, branch=None):
+ def __init__(self, files, branch=None, version=None):
"""
Creates a config to read from config files in a hierarchy.
@@ -64,14 +61,20 @@
userbuild
"""
self._config_files = []
+ self.version = version
assert(len(files) > 0)
for input in files:
- self._config_files.append((ConfigObj(input[0]), input[1]))
+ config = ConfigObj(input[0])
+ self._config_files.append((config, input[1]))
if branch is not None:
self._branch_config = TreeConfig(branch)
else:
self._branch_config = None
+ def set_version(self, version):
+ """Set the version used for substitution."""
+ self.version = version
+
def _get_opt(self, config, key, section=None):
"""Returns the value for key from config, of None if it is not defined in
the file"""
@@ -174,15 +177,23 @@
export_upstream = _opt_property('export-upstream',
"Get the upstream source from another branch")
- export_upstream_revision = _opt_property('export-upstream-revision',
- "The revision of the upstream branch to export.")
-
prepull_upstream = _bool_property('export-upstream-prepull',
"Pull the upstream branch before exporting it.")
prepull_upstream_stop = _bool_property('export-upstream-stop-on-trivial-pull',
"Stop the build if the upstream pull does nothing.")
+ def _get_export_upstream_revision(self):
+ rev = self._get_best_opt('export-upstream-revision')
+ if rev is not None and self.version is not None:
+ rev = rev.replace('$UPSTREAM_VERSION',
+ str(self.version.upstream_version))
+ return rev
+
+ export_upstream_revision = property(_get_export_upstream_revision, None,
+ None,
+ "The revision of the upstream branch to export.")
+
def _test():
import doctest
doctest.testmod()
=== modified file 'debian/changelog'
--- a/debian/changelog 2007-09-16 20:03:15 +0000
+++ b/debian/changelog 2007-09-17 20:46:33 +0000
@@ -23,8 +23,11 @@
handling.
* Add hook support for running arbitrary commands at pre-defined points
in the build.
+ * Support $UPSTREAM_VERSION in the export-upstream-revision configuration
+ option. This allows builddeb to find the correct upstream revision based
+ on tags with no user intervention. Thanks to Jelmer for the idea.
- -- James Westby <jw+debian at jameswestby.net> Sun, 16 Sep 2007 21:02:28 +0100
+ -- James Westby <jw+debian at jameswestby.net> Mon, 17 Sep 2007 21:45:10 +0100
bzr-builddeb (0.90) unstable; urgency=low
=== modified file 'doc/user_manual/export_upstream.rst'
--- a/doc/user_manual/export_upstream.rst 2007-09-15 13:06:13 +0000
+++ b/doc/user_manual/export_upstream.rst 2007-09-17 20:46:33 +0000
@@ -99,5 +99,27 @@
export the new revision of the upstream branch to create the upstream
tarball.
+In order to make this process easier in the future it is possible to use tags
+to automatically pick the correct upstream revision. To do this you (or
+upstream) need to tag the upstream releases with a consistent scheme that
+incorporates the release number in to it. For instance for the ``0.3``
+release of scruff you could run::
+
+ bzr tag scruff-0.3
+
+in the upstream branch. If you then set ``export-upstream-revision`` in the
+configuration file according to this tag scheme, using the special variable
+``$UPSTREAM_VERSION`` then the correct revision can be inferred::
+
+ export-upstream-revision = tag:scruff-$UPSTREAM_VERSION
+
+This means that when `bzr-builddeb` tries to build a package it will look for
+the tag by substituting in the upstream version it is looking for, for
+instance building version ``0.3-3`` will look for the tag ``scruff-0.3`` and
+find the tag we created previously.
+
+Note that this variable substitution only occurs from the configuration file,
+and does not work if this option is passed on the command line.
+
.. vim: set ft=rst tw=76 :
=== modified file 'tests/blackbox/test_builddeb.py'
--- a/tests/blackbox/test_builddeb.py 2007-09-16 18:11:30 +0000
+++ b/tests/blackbox/test_builddeb.py 2007-09-17 20:46:33 +0000
@@ -24,34 +24,15 @@
Version,
)
-from bzrlib.tests.blackbox import ExternalBase
-
-
-class TestBuilddeb(ExternalBase):
-
- package_name = 'test'
- package_version = Version('0.1')
+from tests import BuilddebTestCase
+
+
+class TestBuilddeb(BuilddebTestCase):
commited_file = 'commited_file'
uncommited_file = 'uncommited_file'
unadded_file = 'unadded_file'
- def make_changelog(self, version=None):
- if version is None:
- version = self.package_version
- c = Changelog()
- c.new_block()
- c.version = Version(version)
- c.package = self.package_name
- c.distributions = 'unstable'
- c.urgency = 'low'
- c.author = 'James Westby <jw+debian at jameswestby.net>'
- c.date = 'The, 3 Aug 2006 19:16:22 +0100'
- c.add_change('')
- c.add_change(' * test build')
- c.add_change('')
- return c
-
def make_unpacked_source(self):
"""Create an unpacked source tree in a branch. Return the working tree"""
tree = self.make_branch_and_tree('.')
@@ -59,18 +40,14 @@
source_files = ['debian/'] + [cl_file]
self.build_tree(source_files)
c = self.make_changelog()
- f = open(cl_file, 'wb')
- try:
- c.write_to_open_file(f)
- finally:
- f.close()
+ self.write_changelog(c, cl_file)
tree.add(source_files)
return tree
def build_dir(self):
return os.path.join('..', 'build-area',
self.package_name + '-' +
- str(self.package_version))
+ str(self.upstream_version))
def assertInBuildDir(self, files):
build_dir = self.build_dir()
@@ -100,7 +77,7 @@
self.build_tree([self.commited_file, self.uncommited_file,
self.unadded_file])
tree.add([self.commited_file])
- tree.commit("one")
+ tree.commit("one", rev_id='revid1')
tree.add([self.uncommited_file])
return tree
@@ -159,3 +136,25 @@
self.failUnlessExists('pre-export')
self.assertInBuildDir(['pre-build', 'post-build'])
+ def test_export_upstream_uses_variable_upstream_version(self):
+ """Check that $UPSTREAM_VERSION is supported in export upstream."""
+ tree = self.make_unpacked_source()
+ upstream = self.make_branch_and_tree('upstream')
+ self.build_tree(['upstream/a'])
+ upstream.add(['a'])
+ upstream.commit('one')
+ upstream.branch.tags.set_tag('test-0.1', upstream.branch.last_revision())
+ self.build_tree(['upstream/b'])
+ upstream.add(['b'])
+ upstream.commit('two')
+ os.mkdir('.bzr-builddeb/')
+ f = open('.bzr-builddeb/default.conf', 'wb')
+ try:
+ f.write('[BUILDDEB]\nmerge = True\nexport-upstream = upstream\n')
+ f.write('export-upstream-revision = tag:test-$UPSTREAM_VERSION\n')
+ finally:
+ f.close()
+ self.run_bzr('bd --dont-purge --builder true')
+ self.assertInBuildDir(['a'])
+ self.assertNotInBuildDir(['b'])
+
=== modified file 'tests/test_config.py'
--- a/tests/test_config.py 2007-06-17 21:49:14 +0000
+++ b/tests/test_config.py 2007-09-17 20:46:33 +0000
@@ -18,10 +18,12 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
+from debian_bundle.changelog import Version
+
+from bzrlib.tests import TestCaseWithTransport
+
from config import DebBuildConfig
-from bzrlib.tests import TestCaseWithTransport
-
class DebBuildConfigTests(TestCaseWithTransport):
@@ -37,6 +39,7 @@
f.write('build-dir = default build dir\n')
f.write('orig-dir = default orig dir\n')
f.write('result-dir = default result dir\n')
+ f.write('export-upstream-revision = tag:upstream-$UPSTREAM_VERSION\n')
finally:
f.close()
f = open('user.conf', 'wb')
@@ -56,8 +59,10 @@
finally:
f.close()
self.tree.add(['default.conf', 'user.conf'])
+ version = Version('0.1-1')
self.config = DebBuildConfig([('user.conf', True),
- ('default.conf', False)], branch=self.branch)
+ ('default.conf', False)], branch=self.branch,
+ version=version)
def test_secure_not_from_untrusted(self):
self.assertEqual(self.config.builder, 'valid builder')
@@ -76,4 +81,8 @@
self.assertEqual(self.config.merge, False)
self.assertEqual(self.config.source_builder, None)
+ def test_interpolation(self):
+ self.assertEqual(self.config.export_upstream_revision, 'tag:upstream-0.1')
+ self.config.set_version(Version('0.2'))
+ self.assertEqual(self.config.export_upstream_revision, 'tag:upstream-0.2')
More information about the Pkg-bazaar-commits
mailing list