Rev 58: Support {debupstream} as a recipe substitution variable in http://people.canonical.com/~robertc/baz2.0/plugins/builder/bug469874
Robert Collins
robertc at robertcollins.net
Tue Nov 10 07:45:17 GMT 2009
At http://people.canonical.com/~robertc/baz2.0/plugins/builder/bug469874
------------------------------------------------------------
revno: 58
revision-id: robertc at robertcollins.net-20091110074456-3yzvryo3ihirfy73
parent: robertc at robertcollins.net-20091110070041-3oqjfebk9tej2ce2
author: Robert Collins <robert.collins at canonical.com>, Andrew Bennetts <andrew.bennetts at canonical.com>
committer: Robert Collins <robertc at robertcollins.net>
branch nick: bug469874
timestamp: Tue 2009-11-10 18:44:56 +1100
message:
Support {debupstream} as a recipe substitution variable
=== modified file '__init__.py'
--- a/__init__.py 2009-11-10 07:00:41 +0000
+++ b/__init__.py 2009-11-10 07:44:56 +0000
@@ -283,11 +283,9 @@
temp_dir = None
if not os.path.exists(working_basedir):
os.makedirs(working_basedir)
- # calculates the package name too.
- package_dir = self._calculate_package_dir(recipe_file,
- base_branch, working_basedir, package)
+ self._calculate_package_name(recipe_file, package)
working_directory = os.path.join(working_basedir,
- "%s-%s" % (self._package_name,self._template_version))
+ "%s-%s" % (self._package_name, self._template_version))
try:
# we want to use a consistent package_dir always to support
# updates in place, but debuild etc want PACKAGE-UPSTREAMVERSION
@@ -298,8 +296,11 @@
"bzr-builder.manifest")
build_tree(base_branch, working_directory)
self._write_manifest_to_path(manifest_path, base_branch)
+ # Add changelog also substitutes {debupstream}.
self._add_changelog_entry(base_branch, working_directory,
distribution=distribution, package=package)
+ package_dir = self._calculate_package_dir(base_branch,
+ working_basedir)
# working_directory -> package_dir: after this debian stuff works.
os.rename(working_directory, package_dir)
try:
@@ -337,11 +338,19 @@
distribution = cl._blocks[0].distributions.split()[0]
if package is None:
package = cl._blocks[0].package
+ if "{debupstream}" in base_branch.deb_version:
+ cl_version = cl._blocks[0].version
+ base_branch.deb_version = base_branch.deb_version.replace(
+ "{debupstream}", cl_version.upstream_version)
else:
if package is None:
raise errors.BzrCommandError("No previous changelog to "
"take the package name from, and --package not "
"specified.")
+ if "{debupstream}" in base_branch.deb_version:
+ raise errors.BzrCommandError("No previous changelog to "
+ "take the upstream version from - {debupstream} was "
+ "used.")
if distribution is None:
distribution = "jaunty"
# Use debian packaging environment variables
@@ -359,13 +368,8 @@
finally:
cl_f.close()
- def _calculate_package_dir(self, recipe_file, base_branch,
- working_basedir, package):
+ def _calculate_package_dir(self, base_branch, working_basedir):
"""Calculate the directory name that should be used while debuilding."""
- recipe_name = os.path.basename(recipe_file)
- if recipe_name.endswith(".recipe"):
- recipe_name = recipe_name[:-len(".recipe")]
- self._package_name = package or recipe_name
version = base_branch.deb_version
if "-" in version:
version = version[:version.rindex("-")]
@@ -373,6 +377,13 @@
package_dir = os.path.join(working_basedir, package_basedir)
return package_dir
+ def _calculate_package_name(self, recipe_file, package):
+ """Calculate the directory name that should be used while debuilding."""
+ recipe_name = os.path.basename(recipe_file)
+ if recipe_name.endswith(".recipe"):
+ recipe_name = recipe_name[:-len(".recipe")]
+ self._package_name = package or recipe_name
+
def _get_maintainer(self):
"""
Create maintainer string using the same algorithm as in dch
=== modified file 'recipe.py'
--- a/recipe.py 2009-11-10 05:49:56 +0000
+++ b/recipe.py 2009-11-10 07:44:56 +0000
@@ -288,7 +288,11 @@
if_changed_from=if_changed_from_revisions)
if not changed:
changed = changed_revisions
- if "{" in base_branch.deb_version:
+ ok_to_preserve = ["{debupstream}"]
+ checked_version = base_branch.deb_version
+ for token in ok_to_preserve:
+ checked_version = checked_version.replace(token, "")
+ if "{" in checked_version:
raise errors.BzrCommandError("deb-version not fully "
"expanded: %s" % base_branch.deb_version)
if if_changed_from is not None and not changed:
=== modified file 'tests/test_blackbox.py'
--- a/tests/test_blackbox.py 2009-11-10 05:21:29 +0000
+++ b/tests/test_blackbox.py 2009-11-10 07:44:56 +0000
@@ -185,8 +185,7 @@
out, err = self.run_bzr("dailydeb test.recipe "
"--manifest manifest --package foo --if-changed-from bar")
- def test_cmd_dailydeb_with_package_from_changelog(self):
- #TODO: define a test feature for debuild and require it here.
+ def make_simple_package(self):
source = self.make_branch_and_tree("source")
self.build_tree(["source/a", "source/debian/"])
cl_contents = ("package (0.1-1) unstable; urgency=low\n * foo\n"
@@ -199,7 +198,12 @@
("source/debian/changelog", cl_contents)])
source.add(["a", "debian/", "debian/rules", "debian/control",
"debian/changelog"])
- revid = source.commit("one")
+ source.commit("one")
+ return source
+
+ def test_cmd_dailydeb_with_package_from_changelog(self):
+ #TODO: define a test feature for debuild and require it here.
+ source = self.make_simple_package()
self.build_tree_contents([("test.recipe", "# bzr-builder format 0.1 "
"deb-version 1\nsource 1\n")])
out, err = self.run_bzr("dailydeb test.recipe "
@@ -211,5 +215,18 @@
actual_cl_contents = f.read()
finally:
f.close()
- self.assertEqual(new_cl_contents,
- actual_cl_contents[:len(new_cl_contents)])
+ self.assertStartsWith(actual_cl_contents, new_cl_contents)
+
+ def test_cmd_dailydeb_with_upstream_version_from_changelog(self):
+ source = self.make_simple_package()
+ self.build_tree_contents([("test.recipe", "# bzr-builder format 0.1 "
+ "deb-version {debupstream}-2\nsource 1\n")])
+ out, err = self.run_bzr("dailydeb test.recipe working")
+ new_cl_contents = ("package (0.1-2) unstable; urgency=low\n\n"
+ " * Auto build.\n\n -- M. Maintainer <maint at maint.org> ")
+ f = open("working/test-{debupstream}-2/debian/changelog")
+ try:
+ actual_cl_contents = f.read()
+ finally:
+ f.close()
+ self.assertStartsWith(actual_cl_contents, new_cl_contents)
=== modified file 'tests/test_recipe.py'
--- a/tests/test_recipe.py 2009-08-18 21:25:32 +0000
+++ b/tests/test_recipe.py 2009-11-10 07:44:56 +0000
@@ -714,7 +714,7 @@
def test_substitute(self):
source =self.make_branch_and_tree("source")
revid1 = source.commit("one")
- revid2 = source.commit("two")
+ source.commit("two")
branch1 = BaseRecipeBranch("source",
"{revno}-{revno:packaging}", 0.2, revspec="1")
branch2 = RecipeBranch("packaging", "source")
@@ -725,6 +725,16 @@
self.assertEqual("1", branch1.revspec)
self.assertEqual("1-2", branch1.deb_version)
+ def test_substitute_supports_debupstream(self):
+ # resolve_revisions should leave debupstream parameters alone and not
+ # complain.
+ source =self.make_branch_and_tree("source")
+ source.commit("one")
+ source.commit("two")
+ branch1 = BaseRecipeBranch("source", "{debupstream}-{revno}", 0.2)
+ resolve_revisions(branch1)
+ self.assertEqual("{debupstream}-2", branch1.deb_version)
+
class BuildManifestTests(TestCaseInTempDir):
More information about the bazaar-commits
mailing list