diff -Nru bzr-builder-0.7.2/cmds.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/cmds.py --- bzr-builder-0.7.2/cmds.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/cmds.py 2014-08-25 05:41:16.000000000 +0000 @@ -15,60 +15,31 @@ """Subcommands provided by bzr-builder.""" -from base64 import standard_b64decode from StringIO import StringIO import datetime -from email import utils -import errno import os -import signal import shutil -import subprocess import tempfile -try: - from debian import changelog, deb822 -except ImportError: - # In older versions of python-debian the main package was named - # debian_bundle - from debian_bundle import changelog, deb822 - -try: - get_maintainer = changelog.get_maintainer -except AttributeError: - # Implementation of get_maintainer was added after 0.1.18 so import same - # function from backports module if python-debian doesn't have it. - from bzrlib.plugins.builder.backports import get_maintainer - from bzrlib import ( - errors, - export as _mod_export, - lazy_regex, - osutils, - trace, - transport as _mod_transport, - urlutils, - ) + errors, + lazy_regex, + trace, + transport as _mod_transport, + urlutils, + ) from bzrlib.branch import Branch from bzrlib.commands import Command from bzrlib.option import Option from bzrlib.plugins.builder.recipe import ( - BaseRecipeBranch, - build_tree, - RecipeParser, - resolve_revisions, - SAFE_INSTRUCTIONS, - SubstitutionUnavailable, - ) - - -# The default distribution used by add_autobuild_changelog_entry() -DEFAULT_UBUNTU_DISTRIBUTION = "lucid" - + BaseRecipeBranch, + build_tree, + RecipeParser, + resolve_revisions, + SAFE_INSTRUCTIONS, + ) -class MissingDependency(errors.BzrError): - pass def write_manifest_to_transport(location, base_branch, @@ -135,233 +106,6 @@ return old_recipe -def add_autobuild_changelog_entry(base_branch, basedir, package, - distribution=None, author_name=None, author_email=None, - append_version=None): - """Add a new changelog entry for an autobuild. - - :param base_branch: Recipe base branch - :param basedir: Base working directory - :param package: package name - :param distribution: Optional distribution (defaults to last entry - distribution) - :param author_name: Name of the build requester - :param author_email: Email of the build requester - :param append_version: Optional version suffix to add - """ - debian_dir = os.path.join(basedir, "debian") - if not os.path.exists(debian_dir): - os.makedirs(debian_dir) - cl_path = os.path.join(debian_dir, "changelog") - file_found = False - if os.path.exists(cl_path): - file_found = True - cl_f = open(cl_path) - try: - contents = cl_f.read() - finally: - cl_f.close() - cl = changelog.Changelog(file=contents) - else: - cl = changelog.Changelog() - if len(cl._blocks) > 0: - if distribution is None: - distribution = cl._blocks[0].distributions.split()[0] - else: - if file_found: - if len(contents.strip()) > 0: - reason = ("debian/changelog didn't contain any " - "parseable stanzas") - else: - reason = "debian/changelog was empty" - else: - reason = "debian/changelog was not present" - if distribution is None: - distribution = DEFAULT_UBUNTU_DISTRIBUTION - if base_branch.format in (0.1, 0.2, 0.3): - try: - base_branch.substitute_changelog_vars(None, cl) - except SubstitutionUnavailable, e: - raise errors.BzrCommandError("No previous changelog to " - "take the upstream version from as %s was " - "used: %s: %s." % (e.name, e.reason, reason)) - # Use debian packaging environment variables - # or default values if they don't exist - if author_name is None or author_email is None: - author_name, author_email = get_maintainer() - # The python-debian package breaks compatibility at version 0.1.20 by - # switching to expecting (but not checking for) unicode rather than - # bytestring inputs. Detect this and decode environment if needed. - if getattr(changelog.Changelog, "__unicode__", None) is not None: - enc = osutils.get_user_encoding() - author_name = author_name.decode(enc) - author_email = author_email.decode(enc) - author = "%s <%s>" % (author_name, author_email) - - date = utils.formatdate(localtime=True) - version = base_branch.deb_version - if append_version is not None: - version += append_version - try: - changelog.Version(version) - except (changelog.VersionError, ValueError), e: - raise errors.BzrCommandError("Invalid deb-version: %s: %s" - % (version, e)) - cl.new_block(package=package, version=version, - distributions=distribution, urgency="low", - changes=['', ' * Auto build.', ''], - author=author, date=date) - cl_f = open(cl_path, 'wb') - try: - cl.write_to_open_file(cl_f) - finally: - cl_f.close() - - -def calculate_package_dir(package_name, package_version, working_basedir): - """Calculate the directory name that should be used while debuilding. - - :param base_branch: Recipe base branch - :param package_version: Version of the package - :param package_name: Package name - :param working_basedir: Base directory - """ - package_basedir = "%s-%s" % (package_name, package_version.upstream_version) - package_dir = os.path.join(working_basedir, package_basedir) - return package_dir - - -def _run_command(command, basedir, msg, error_msg, - not_installed_msg=None, env=None, success_exit_codes=None, indata=None): - """ Run a command in a subprocess. - - :param command: list with command and parameters - :param msg: message to display to the user - :param error_msg: message to display if something fails. - :param not_installed_msg: the message to display if the command - isn't available. - :param env: Optional environment to use rather than os.environ. - :param success_exit_codes: Exit codes to consider succesfull, defaults to [0]. - :param indata: Data to write to standard input - """ - def subprocess_setup(): - signal.signal(signal.SIGPIPE, signal.SIG_DFL) - trace.note(msg) - # Hide output if -q is in use. - quiet = trace.is_quiet() - if quiet: - kwargs = {"stderr": subprocess.STDOUT, "stdout": subprocess.PIPE} - else: - kwargs = {} - if env is not None: - kwargs["env"] = env - trace.mutter("running: %r", command) - try: - proc = subprocess.Popen(command, cwd=basedir, - stdin=subprocess.PIPE, preexec_fn=subprocess_setup, **kwargs) - except OSError, e: - if e.errno != errno.ENOENT: - raise - if not_installed_msg is None: - raise - raise MissingDependency(msg=not_installed_msg) - output = proc.communicate(indata) - if success_exit_codes is None: - success_exit_codes = [0] - if proc.returncode not in success_exit_codes: - if quiet: - raise errors.BzrCommandError("%s: %s" % (error_msg, output)) - else: - raise errors.BzrCommandError(error_msg) - - -def build_source_package(basedir, tgz_check=True): - command = ["/usr/bin/debuild"] - if tgz_check: - command.append("--tgz-check") - else: - command.append("--no-tgz-check") - command.extend(["-i", "-I", "-S", "-uc", "-us"]) - _run_command(command, basedir, - "Building the source package", - "Failed to build the source package", - not_installed_msg="debuild is not installed, please install " - "the devscripts package.") - - -def get_source_format(path): - """Retrieve the source format name from a package. - - :param path: Path to the package - :return: String with package format - """ - source_format_path = os.path.join(path, "debian", "source", "format") - if not os.path.exists(source_format_path): - return "1.0" - f = open(source_format_path, 'r') - try: - return f.read().strip() - finally: - f.close() - - -def convert_3_0_quilt_to_native(path): - """Convert a package in 3.0 (quilt) format to 3.0 (native). - - This applies all patches in the package and updates the - debian/source/format file. - - :param path: Path to the package on disk - """ - path = os.path.abspath(path) - patches_dir = os.path.join(path, "debian", "patches") - series_file = os.path.join(patches_dir, "series") - if os.path.exists(series_file): - _run_command(["quilt", "push", "-a", "-v"], path, - "Applying quilt patches", - "Failed to apply quilt patches", - not_installed_msg="quilt is not installed, please install it.", - env={"QUILT_SERIES": series_file, "QUILT_PATCHES": patches_dir}, - success_exit_codes=(0, 2)) - if os.path.exists(patches_dir): - shutil.rmtree(patches_dir) - f = open(os.path.join(path, "debian", "source", "format"), 'w') - try: - f.write("3.0 (native)\n") - finally: - f.close() - - -def force_native_format(working_tree_path, current_format): - """Make sure a package is a format that supports native packages. - - :param working_tree_path: Path to the package - """ - if current_format == "3.0 (quilt)": - convert_3_0_quilt_to_native(working_tree_path) - elif current_format not in ("1.0", "3.0 (native)"): - raise errors.BzrCommandError("Unknown source format %s" % - current_format) - - -def sign_source_package(basedir, key_id): - command = ["/usr/bin/debsign", "-S", "-k%s" % key_id] - _run_command(command, basedir, - "Signing the source package", - "Signing the package failed", - not_installed_msg="debsign is not installed, please install " - "the devscripts package.") - - -def dput_source_package(basedir, target): - command = ["/usr/bin/debrelease", "-S", "--dput", target] - _run_command(command, basedir, - "Uploading the source package", - "Uploading the package failed", - not_installed_msg="debrelease is not installed, please " - "install the devscripts package.") - - launchpad_recipe_re = lazy_regex.lazy_compile( r'^https://code.launchpad.net/~(.*)/\+recipe/(.*)$') @@ -409,6 +153,33 @@ return basename, recipe_transport.get(basename) +def get_prepared_branch_from_location(location, + safe=False, possible_transports=None, + revspec=None): + """Common code to prepare a branch and do substitutions. + + :param location: a path to a recipe file or branch to work from. + :param if_changed_from: an optional location of a manifest to + compare the recipe against. + :param safe: if True, reject recipes that would cause arbitrary code + execution. + :return: A tuple with (retcode, base_branch). If retcode is None + then the command execution should continue. + """ + try: + base_branch = get_branch_from_recipe_location(location, safe=safe, + possible_transports=possible_transports) + except (_mod_transport.LateReadError, errors.ReadError): + # Presume unable to read means location is a directory rather than a file + base_branch = get_branch_from_branch_location(location, + possible_transports=possible_transports) + else: + if revspec is not None: + raise errors.BzrCommandError("--revision only supported when " + "building from branch") + return base_branch + + class cmd_build(Command): """Build a tree based on a branch or a recipe. @@ -427,43 +198,6 @@ 'revision', ] - def _get_prepared_branch_from_location(self, location, - if_changed_from=None, safe=False, possible_transports=None, - revspec=None): - """Common code to prepare a branch and do substitutions. - - :param location: a path to a recipe file or branch to work from. - :param if_changed_from: an optional location of a manifest to - compare the recipe against. - :param safe: if True, reject recipes that would cause arbitrary code - execution. - :return: A tuple with (retcode, base_branch). If retcode is None - then the command execution should continue. - """ - try: - base_branch = get_branch_from_recipe_location(location, safe=safe, - possible_transports=possible_transports) - except (_mod_transport.LateReadError, errors.ReadError): - # Presume unable to read means location is a directory rather than a file - base_branch = get_branch_from_branch_location(location, - possible_transports=possible_transports) - else: - if revspec is not None: - raise errors.BzrCommandError("--revision only supported when " - "building from branch") - time = datetime.datetime.utcnow() - base_branch.substitute_time(time) - old_recipe = None - if if_changed_from is not None: - old_recipe = get_old_recipe(if_changed_from, possible_transports) - # Save the unsubstituted version for dailydeb. - self._template_version = base_branch.deb_version - changed = resolve_revisions(base_branch, if_changed_from=old_recipe) - if not changed: - trace.note("Unchanged") - return 0, base_branch - return None, base_branch - def run(self, location, working_directory, manifest=None, if_changed_from=None, revision=None): if revision is not None and len(revision) > 0: @@ -474,11 +208,16 @@ else: revspec = None possible_transports = [] - result, base_branch = self._get_prepared_branch_from_location(location, - if_changed_from=if_changed_from, + base_branch = get_prepared_branch_from_location(location, possible_transports=possible_transports, revspec=revspec) - if result is not None: - return result + if if_changed_from is not None: + old_recipe = get_old_recipe(if_changed_from, possible_transports) + else: + old_recipe = None + changed = resolve_revisions(base_branch, if_changed_from=old_recipe) + if not changed: + trace.note("Unchanged") + return 0 manifest_path = manifest or os.path.join(working_directory, "bzr-builder.manifest") build_tree(base_branch, working_directory) @@ -486,73 +225,7 @@ possible_transports) -def debian_source_package_name(control_path): - """Open a debian control file and extract the package name. - - """ - f = open(control_path, 'r') - try: - control = deb822.Deb822(f) - # Debian policy states package names are [a-z0-9][a-z0-9.+-]+ so ascii - return control["Source"].encode("ascii") - finally: - f.close() - - -def reconstruct_pristine_tar(dest, delta, dest_filename): - """Reconstruct a pristine tarball from a directory and a delta. - - :param dest: Directory to pack - :param delta: pristine-tar delta - :param dest_filename: Destination filename - """ - command = ["pristine-tar", "gentar", "-", - os.path.abspath(dest_filename)] - _run_command(command, dest, - "Reconstructing pristine tarball", - "Generating tar from delta failed", - not_installed_msg="pristine-tar is not installed", - indata=delta) - - -def extract_upstream_tarball(branch, package, version, dest_dir): - """Extract the upstream tarball from a branch. - - :param branch: Branch with the upstream pristine tar data - :param package: Package name - :param version: Package version - :param dest_dir: Destination directory - """ - tag_name = "upstream-%s" % version - revid = branch.tags.lookup_tag(tag_name) - tree = branch.repository.revision_tree(revid) - rev = branch.repository.get_revision(revid) - if 'deb-pristine-delta' in rev.properties: - uuencoded = rev.properties['deb-pristine-delta'] - dest_filename = "%s_%s.orig.tar.gz" % (package, version) - elif 'deb-pristine-delta-bz2' in rev.properties: - uuencoded = rev.properties['deb-pristine-delta-bz2'] - dest_filename = "%s_%s.orig.tar.bz2" % (package, version) - else: - uuencoded = None - if uuencoded is not None: - delta = standard_b64decode(uuencoded) - dest = os.path.join(dest_dir, "orig") - try: - _mod_export.export(tree, dest, format='dir') - reconstruct_pristine_tar(dest, delta, - os.path.join(dest_dir, dest_filename)) - finally: - if os.path.exists(dest): - shutil.rmtree(dest) - else: - # Default to .tar.gz - dest_filename = "%s_%s.orig.tar.gz" % (package, version) - _mod_export.export(tree, os.path.join(dest_dir, dest_filename), - per_file_timestamps=True) - - -class cmd_dailydeb(cmd_build): +class cmd_dailydeb(Command): """Build a deb based on a 'recipe' or from a branch. See "bzr help builder" for more information on what a recipe is. @@ -600,6 +273,36 @@ if_changed_from=None, package=None, distribution=None, dput=None, key_id=None, no_build=None, watch_ppa=False, append_version=None, safe=False, allow_fallback_to_native=False): + try: + try: + import debian + except ImportError: + # In older versions of python-debian the main package was named + # debian_bundle + import debian_bundle + except ImportError: + raise errors.BzrCommandError("The 'debian' python module " + "is required for 'bzr dailydeb'. Install the " + "python-debian package.") + + from bzrlib.plugins.builder.deb_util import ( + add_autobuild_changelog_entry, + build_source_package, + calculate_package_dir, + changelog, + debian_source_package_name, + dput_source_package, + extract_upstream_tarball, + force_native_format, + get_source_format, + sign_source_package, + target_from_dput, + ) + from bzrlib.plugins.builder.deb_version import ( + check_expanded_deb_version, + substitute_branch_vars, + substitute_time, + ) if dput is not None and key_id is None: raise errors.BzrCommandError("You must specify --key-id if you " @@ -613,11 +316,25 @@ target_from_dput(dput) possible_transports = [] - result, base_branch = self._get_prepared_branch_from_location(location, - if_changed_from=if_changed_from, safe=safe, + base_branch = get_prepared_branch_from_location(location, safe=safe, possible_transports=possible_transports) - if result is not None: - return result + # Save the unsubstituted version + template_version = base_branch.deb_version + if if_changed_from is not None: + old_recipe = get_old_recipe(if_changed_from, possible_transports) + else: + old_recipe = None + if base_branch.deb_version is not None: + time = datetime.datetime.utcnow() + substitute_time(base_branch, time) + changed = resolve_revisions(base_branch, if_changed_from=old_recipe, + substitute_branch_vars=substitute_branch_vars) + check_expanded_deb_version(base_branch) + else: + changed = resolve_revisions(base_branch, if_changed_from=old_recipe) + if not changed: + trace.note("Unchanged") + return 0 if working_basedir is None: temp_dir = tempfile.mkdtemp(prefix="bzr-builder-") working_basedir = temp_dir @@ -626,12 +343,12 @@ if not os.path.exists(working_basedir): os.makedirs(working_basedir) package_name = self._calculate_package_name(location, package) - if self._template_version is None: + if template_version is None: working_directory = os.path.join(working_basedir, "%s-direct" % (package_name,)) else: working_directory = os.path.join(working_basedir, - "%s-%s" % (package_name, self._template_version)) + "%s-%s" % (package_name, template_version)) try: # we want to use a consistent package_dir always to support # updates in place, but debuild etc want PACKAGE-UPSTREAMVERSION @@ -655,7 +372,7 @@ if autobuild: # Add changelog also substitutes {debupstream}. add_autobuild_changelog_entry(base_branch, working_directory, - package, distribution=distribution, + package, distribution=distribution, append_version=append_version) else: if append_version: @@ -671,37 +388,35 @@ working_basedir) # working_directory -> package_dir: after this debian stuff works. os.rename(working_directory, package_dir) - if no_build: - if manifest is not None: - write_manifest_to_transport(manifest, base_branch, - possible_transports) - return 0 - current_format = get_source_format(package_dir) - if (package_version.debian_version is not None or - current_format == "3.0 (quilt)"): - # Non-native package - try: - extract_upstream_tarball(base_branch.branch, package_name, - package_version.upstream_version, working_basedir) - except errors.NoSuchTag, e: - if not allow_fallback_to_native: - raise errors.BzrCommandError( - "Unable to find the upstream source. Import it " - "as tag %s or build with " - "--allow-fallback-to-native." % e.tag_name) - else: - force_native_format(package_dir, current_format) try: - build_source_package(package_dir, - tgz_check=not allow_fallback_to_native) - if key_id is not None: - sign_source_package(package_dir, key_id) - if dput is not None: - dput_source_package(package_dir, dput) + current_format = get_source_format(package_dir) + if (package_version.debian_version is not None or + current_format == "3.0 (quilt)"): + # Non-native package + try: + extract_upstream_tarball(base_branch.branch, package_name, + package_version.upstream_version, working_basedir) + except errors.NoSuchTag, e: + if not allow_fallback_to_native: + raise errors.BzrCommandError( + "Unable to find the upstream source. Import it " + "as tag %s or build with " + "--allow-fallback-to-native." % e.tag_name) + else: + force_native_format(package_dir, current_format) + if not no_build: + build_source_package(package_dir, + tgz_check=not allow_fallback_to_native) + if key_id is not None: + sign_source_package(package_dir, key_id) + if dput is not None: + dput_source_package(package_dir, dput) finally: - # package_dir -> working_directory - # FIXME: may fail in error unwind, masking the original exception. - os.rename(package_dir, working_directory) + if not no_build: + # package_dir -> working_directory + # FIXME: may fail in error unwind, masking the + # original exception. + os.rename(package_dir, working_directory) # Note that this may write a second manifest. if manifest is not None: write_manifest_to_transport(manifest, base_branch, @@ -722,20 +437,3 @@ recipe_name = recipe_name[:-len(".recipe")] return package or recipe_name - -def target_from_dput(dput): - """Convert a dput specification to a LP API specification. - - :param dput: A dput command spec like ppa:team-name. - :return: A LP API target like team-name/ppa. - """ - ppa_prefix = 'ppa:' - if not dput.startswith(ppa_prefix): - raise errors.BzrCommandError('%r does not appear to be a PPA. ' - 'A dput target like \'%suser[/name]\' must be used.' - % (dput, ppa_prefix)) - base, _, suffix = dput[len(ppa_prefix):].partition('/') - if not suffix: - suffix = 'ppa' - return base, suffix - diff -Nru bzr-builder-0.7.2/debian/bzr-builder.manifest bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/bzr-builder.manifest --- bzr-builder-0.7.2/debian/bzr-builder.manifest 1970-01-01 00:00:00.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/bzr-builder.manifest 2014-08-25 05:41:17.000000000 +0000 @@ -0,0 +1,3 @@ +# bzr-builder format 0.4 deb-version 0.7.3+bzr174~ppa13 +lp:bzr-builder revid:william.grant@canonical.com-20140806120929-1leqzdwteb2yhqq1 +nest-part packaging lp:ubuntu/trusty/bzr-builder debian debian revid:package-import@ubuntu.com-20120610024503-4syoetggxq6qr1lp diff -Nru bzr-builder-0.7.2/debian/changelog bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/changelog --- bzr-builder-0.7.2/debian/changelog 2011-11-10 13:42:21.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/changelog 2014-08-25 05:41:17.000000000 +0000 @@ -1,3 +1,23 @@ +bzr-builder (0.7.3+bzr174~ppa13~ubuntu12.04.1) precise; urgency=low + + * Auto build. + + -- William Grant Mon, 25 Aug 2014 05:41:17 +0000 + +bzr-builder (0.7.3-0ubuntu1) quantal; urgency=low + + * New upstream release. + + -- Logan Rosen Sun, 10 Jun 2012 02:45:03 -0400 + +bzr-builder (0.7.2-0ubuntu2) precise; urgency=low + + * Add pristine-tar to build-dependencies, for use by the test suite. + * Add pristine-tar to recommends, move dput and devscripts from Depends to + Recommends. + + -- Jelmer Vernooij Fri, 11 Nov 2011 13:26:39 +0100 + bzr-builder (0.7.2-0ubuntu1) precise; urgency=low * New upstream release. diff -Nru bzr-builder-0.7.2/debian/control bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/control --- bzr-builder-0.7.2/debian/control 2011-11-10 13:34:57.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/control 2014-08-25 05:41:17.000000000 +0000 @@ -3,7 +3,7 @@ Priority: optional Maintainer: Ubuntu Developers XSBC-Original-Maintainer: James Westby -Build-Depends: debhelper (>= 7.0.50~), python (>= 2.6.6-3~), python-testtools, python-bzrlib.tests | bzr (<< 2.4.0~beta1-2), devscripts, quilt +Build-Depends: debhelper (>= 7.0.50~), python (>= 2.6.6-3~), python-testtools, python-bzrlib.tests | bzr (<< 2.4.0~beta1-2), devscripts, quilt, pristine-tar Build-Depends-Indep: bzr, python-debian X-Python-Version: >= 2.4 Standards-Version: 3.9.2 @@ -13,11 +13,10 @@ Package: bzr-builder Architecture: all Depends: bzr, - devscripts, - dput, python-debian, ${misc:Depends}, ${python:Depends} +Recommends: pristine-tar, devscripts, dput Description: construct a bzr branch from a recipe bzr-builder takes a 'recipe' which specifies several Bazaar branches to combine in a certain fashion as input, and provides the resulting branch diff -Nru bzr-builder-0.7.2/debian/source/format bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/source/format --- bzr-builder-0.7.2/debian/source/format 2011-11-10 13:28:27.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/debian/source/format 2014-08-25 05:41:17.000000000 +0000 @@ -1 +1 @@ -3.0 (quilt) +3.0 (native) diff -Nru bzr-builder-0.7.2/deb_util.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/deb_util.py --- bzr-builder-0.7.2/deb_util.py 1970-01-01 00:00:00.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/deb_util.py 2014-08-25 05:41:16.000000000 +0000 @@ -0,0 +1,379 @@ +# bzr-builder: a bzr plugin to constuct trees based on recipes +# Copyright 2009-2011 Canonical Ltd. + +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Debian-specific utility functions.""" + +from base64 import standard_b64decode +from email import utils +import errno +import os +import shutil +import signal +import subprocess + +from bzrlib import ( + errors, + export as _mod_export, + osutils, + trace, + ) + +from bzrlib.plugins.builder.deb_version import substitute_changelog_vars +from bzrlib.plugins.builder.recipe import ( + SubstitutionUnavailable, + ) + +try: + from debian import changelog, deb822 +except ImportError: + # In older versions of python-debian the main package was named + # debian_bundle + from debian_bundle import changelog, deb822 + + +try: + get_maintainer = changelog.get_maintainer +except AttributeError: + # Implementation of get_maintainer was added after 0.1.18 so import same + # function from backports module if python-debian doesn't have it. + from bzrlib.plugins.builder.backports import get_maintainer + +# The default distribution used by add_autobuild_changelog_entry() +DEFAULT_UBUNTU_DISTRIBUTION = "lucid" + + +class MissingDependency(errors.BzrError): + pass + + +def target_from_dput(dput): + """Convert a dput specification to a LP API specification. + + :param dput: A dput command spec like ppa:team-name. + :return: A LP API target like team-name/ppa. + """ + ppa_prefix = 'ppa:' + if not dput.startswith(ppa_prefix): + raise errors.BzrCommandError('%r does not appear to be a PPA. ' + 'A dput target like \'%suser[/name]\' must be used.' + % (dput, ppa_prefix)) + base, _, suffix = dput[len(ppa_prefix):].partition('/') + if not suffix: + suffix = 'ppa' + return base, suffix + + +def debian_source_package_name(control_path): + """Open a debian control file and extract the package name. + + """ + f = open(control_path, 'r') + try: + control = deb822.Deb822(f) + # Debian policy states package names are [a-z0-9][a-z0-9.+-]+ so ascii + return control["Source"].encode("ascii") + finally: + f.close() + + +def reconstruct_pristine_tar(dest, delta, dest_filename): + """Reconstruct a pristine tarball from a directory and a delta. + + :param dest: Directory to pack + :param delta: pristine-tar delta + :param dest_filename: Destination filename + """ + command = ["pristine-tar", "gentar", "-", + os.path.abspath(dest_filename)] + _run_command(command, dest, + "Reconstructing pristine tarball", + "Generating tar from delta failed", + not_installed_msg="pristine-tar is not installed", + indata=delta) + + +def extract_upstream_tarball(branch, package, version, dest_dir): + """Extract the upstream tarball from a branch. + + :param branch: Branch with the upstream pristine tar data + :param package: Package name + :param version: Package version + :param dest_dir: Destination directory + """ + tag_names = ["upstream-%s" % version, "upstream/%s" % version] + for tag_name in tag_names: + try: + revid = branch.tags.lookup_tag(tag_name) + except errors.NoSuchTag: + pass + else: + break + else: + raise errors.NoSuchTag(tag_names[0]) + tree = branch.repository.revision_tree(revid) + rev = branch.repository.get_revision(revid) + if 'deb-pristine-delta' in rev.properties: + uuencoded = rev.properties['deb-pristine-delta'] + dest_filename = "%s_%s.orig.tar.gz" % (package, version) + elif 'deb-pristine-delta-bz2' in rev.properties: + uuencoded = rev.properties['deb-pristine-delta-bz2'] + dest_filename = "%s_%s.orig.tar.bz2" % (package, version) + else: + uuencoded = None + if uuencoded is not None: + delta = standard_b64decode(uuencoded) + dest = os.path.join(dest_dir, "orig") + try: + _mod_export.export(tree, dest, format='dir') + reconstruct_pristine_tar(dest, delta, + os.path.join(dest_dir, dest_filename)) + finally: + if os.path.exists(dest): + shutil.rmtree(dest) + else: + # Default to .tar.gz + dest_filename = "%s_%s.orig.tar.gz" % (package, version) + _mod_export.export(tree, os.path.join(dest_dir, dest_filename), + per_file_timestamps=True) + + +def add_autobuild_changelog_entry(base_branch, basedir, package, + distribution=None, author_name=None, author_email=None, + append_version=None): + """Add a new changelog entry for an autobuild. + + :param base_branch: Recipe base branch + :param basedir: Base working directory + :param package: package name + :param distribution: Optional distribution (defaults to last entry + distribution) + :param author_name: Name of the build requester + :param author_email: Email of the build requester + :param append_version: Optional version suffix to add + """ + debian_dir = os.path.join(basedir, "debian") + if not os.path.exists(debian_dir): + os.makedirs(debian_dir) + cl_path = os.path.join(debian_dir, "changelog") + file_found = False + if os.path.exists(cl_path): + file_found = True + cl_f = open(cl_path) + try: + contents = cl_f.read() + finally: + cl_f.close() + cl = changelog.Changelog(file=contents) + else: + cl = changelog.Changelog() + if len(cl._blocks) > 0: + if distribution is None: + distribution = cl._blocks[0].distributions.split()[0] + else: + if file_found: + if len(contents.strip()) > 0: + reason = ("debian/changelog didn't contain any " + "parseable stanzas") + else: + reason = "debian/changelog was empty" + else: + reason = "debian/changelog was not present" + if distribution is None: + distribution = DEFAULT_UBUNTU_DISTRIBUTION + if base_branch.format in (0.1, 0.2, 0.3): + try: + substitute_changelog_vars(base_branch, None, cl) + except SubstitutionUnavailable, e: + raise errors.BzrCommandError("No previous changelog to " + "take the upstream version from as %s was " + "used: %s: %s." % (e.name, e.reason, reason)) + # Use debian packaging environment variables + # or default values if they don't exist + if author_name is None or author_email is None: + author_name, author_email = get_maintainer() + # The python-debian package breaks compatibility at version 0.1.20 by + # switching to expecting (but not checking for) unicode rather than + # bytestring inputs. Detect this and decode environment if needed. + if getattr(changelog.Changelog, "__unicode__", None) is not None: + enc = osutils.get_user_encoding() + author_name = author_name.decode(enc) + author_email = author_email.decode(enc) + author = "%s <%s>" % (author_name, author_email) + + date = utils.formatdate(localtime=True) + version = base_branch.deb_version + if append_version is not None: + version += append_version + try: + changelog.Version(version) + except (changelog.VersionError, ValueError), e: + raise errors.BzrCommandError("Invalid deb-version: %s: %s" + % (version, e)) + cl.new_block(package=package, version=version, + distributions=distribution, urgency="low", + changes=['', ' * Auto build.', ''], + author=author, date=date) + cl_f = open(cl_path, 'wb') + try: + cl.write_to_open_file(cl_f) + finally: + cl_f.close() + + +def calculate_package_dir(package_name, package_version, working_basedir): + """Calculate the directory name that should be used while debuilding. + + :param base_branch: Recipe base branch + :param package_version: Version of the package + :param package_name: Package name + :param working_basedir: Base directory + """ + package_basedir = "%s-%s" % (package_name, package_version.upstream_version) + package_dir = os.path.join(working_basedir, package_basedir) + return package_dir + + +def _run_command(command, basedir, msg, error_msg, + not_installed_msg=None, env=None, success_exit_codes=None, indata=None): + """ Run a command in a subprocess. + + :param command: list with command and parameters + :param msg: message to display to the user + :param error_msg: message to display if something fails. + :param not_installed_msg: the message to display if the command + isn't available. + :param env: Optional environment to use rather than os.environ. + :param success_exit_codes: Exit codes to consider succesfull, defaults to [0]. + :param indata: Data to write to standard input + """ + def subprocess_setup(): + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + trace.note(msg) + # Hide output if -q is in use. + quiet = trace.is_quiet() + if quiet: + kwargs = {"stderr": subprocess.STDOUT, "stdout": subprocess.PIPE} + else: + kwargs = {} + if env is not None: + kwargs["env"] = env + trace.mutter("running: %r", command) + try: + proc = subprocess.Popen(command, cwd=basedir, + stdin=subprocess.PIPE, preexec_fn=subprocess_setup, **kwargs) + except OSError, e: + if e.errno != errno.ENOENT: + raise + if not_installed_msg is None: + raise + raise MissingDependency(msg=not_installed_msg) + output = proc.communicate(indata) + if success_exit_codes is None: + success_exit_codes = [0] + if proc.returncode not in success_exit_codes: + if quiet: + raise errors.BzrCommandError("%s: %s" % (error_msg, output)) + else: + raise errors.BzrCommandError(error_msg) + + +def build_source_package(basedir, tgz_check=True): + command = ["/usr/bin/debuild"] + if tgz_check: + command.append("--tgz-check") + else: + command.append("--no-tgz-check") + command.extend(["-i", "-I", "-S", "-uc", "-us"]) + _run_command(command, basedir, + "Building the source package", + "Failed to build the source package", + not_installed_msg="debuild is not installed, please install " + "the devscripts package.") + + +def get_source_format(path): + """Retrieve the source format name from a package. + + :param path: Path to the package + :return: String with package format + """ + source_format_path = os.path.join(path, "debian", "source", "format") + if not os.path.exists(source_format_path): + return "1.0" + f = open(source_format_path, 'r') + try: + return f.read().strip() + finally: + f.close() + + +def convert_3_0_quilt_to_native(path): + """Convert a package in 3.0 (quilt) format to 3.0 (native). + + This applies all patches in the package and updates the + debian/source/format file. + + :param path: Path to the package on disk + """ + path = os.path.abspath(path) + patches_dir = os.path.join(path, "debian", "patches") + series_file = os.path.join(patches_dir, "series") + if os.path.exists(series_file): + _run_command(["quilt", "push", "-a", "-v"], path, + "Applying quilt patches", + "Failed to apply quilt patches", + not_installed_msg="quilt is not installed, please install it.", + env={"QUILT_SERIES": series_file, "QUILT_PATCHES": patches_dir}, + success_exit_codes=(0, 2)) + if os.path.exists(patches_dir): + shutil.rmtree(patches_dir) + f = open(os.path.join(path, "debian", "source", "format"), 'w') + try: + f.write("3.0 (native)\n") + finally: + f.close() + + +def force_native_format(working_tree_path, current_format): + """Make sure a package is a format that supports native packages. + + :param working_tree_path: Path to the package + """ + if current_format == "3.0 (quilt)": + convert_3_0_quilt_to_native(working_tree_path) + elif current_format not in ("1.0", "3.0 (native)"): + raise errors.BzrCommandError("Unknown source format %s" % + current_format) + + +def sign_source_package(basedir, key_id): + command = ["/usr/bin/debsign", "-S", "-k%s" % key_id] + _run_command(command, basedir, + "Signing the source package", + "Signing the package failed", + not_installed_msg="debsign is not installed, please install " + "the devscripts package.") + + +def dput_source_package(basedir, target): + command = ["/usr/bin/debrelease", "-S", "--dput", target] + _run_command(command, basedir, + "Uploading the source package", + "Uploading the package failed", + not_installed_msg="debrelease is not installed, please " + "install the devscripts package.") + + + diff -Nru bzr-builder-0.7.2/deb_version.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/deb_version.py --- bzr-builder-0.7.2/deb_version.py 1970-01-01 00:00:00.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/deb_version.py 2014-08-25 05:41:16.000000000 +0000 @@ -0,0 +1,214 @@ +# bzr-builder: a bzr plugin to constuct trees based on recipes +# Copyright 2009-2011 Canonical Ltd. + +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +from bzrlib import ( + errors, + lazy_regex, + ) + +from bzrlib.plugins.builder.recipe import ( + BranchSubstitutionVariable, + DateVariable, + GitCommitVariable, + LatestTagVariable, + RevdateVariable, + RevtimeVariable, + RevnoVariable, + SubstitutionUnavailable, + SubversionRevnumVariable, + TimeVariable, + branch_vars, + simple_vars, + ) +try: + from debian import changelog +except ImportError: + # In older versions of python-debian the main package was named + # debian_bundle + from debian_bundle import changelog + + +class DebUpstreamVariable(BranchSubstitutionVariable): + + basename = "debupstream" + + minimum_format = 0.1 + + def __init__(self, branch_name, version): + super(DebUpstreamVariable, self).__init__(branch_name) + self._version = version + + @classmethod + def from_changelog(cls, branch_name, changelog): + if len(changelog._blocks) > 0: + return cls(branch_name, changelog._blocks[0].version) + else: + return cls(branch_name, None) + + def get(self): + if self._version is None: + raise SubstitutionUnavailable(self.name, + "No previous changelog to take the upstream version from") + # Should we include the epoch? + return self._version.upstream_version + + +class DebVersionVariable(BranchSubstitutionVariable): + + basename = "debversion" + + minimum_format = 0.3 + + def __init__(self, branch_name, version): + super(DebVersionVariable, self).__init__(branch_name) + self._version = version + + @classmethod + def from_changelog(cls, branch_name, changelog): + if len(changelog._blocks) > 0: + return cls(branch_name, changelog._blocks[0].version) + else: + return cls(branch_name, None) + + def get(self): + if self._version is None: + raise SubstitutionUnavailable(self.name, + "No previous changelog to take the version from") + return str(self._version) + +dfsg_regex = lazy_regex.lazy_compile( + r'[+.]*dfsg[.]*[0-9]+') + +version_regex = lazy_regex.lazy_compile( + r'([~+])(svn[0-9]+|bzr[0-9]+|git[0-9a-f]+)') + +def version_extract_base(version): + version = dfsg_regex.sub("", version) + return version_regex.sub("\\1", version) + + +class DebUpstreamBaseVariable(DebUpstreamVariable): + + basename = "debupstream-base" + minimum_format = 0.3 + + def get(self): + version = super(DebUpstreamBaseVariable, self).get() + version = version_extract_base(version) + if version[-1] not in ("~", "+"): + version += "+" + return version + + +ok_to_preserve = [DebUpstreamVariable, DebUpstreamBaseVariable, + DebVersionVariable] +deb_branch_vars = [DebVersionVariable, DebUpstreamBaseVariable, DebUpstreamVariable] + + +def check_expanded_deb_version(base_branch): + checked_version = base_branch.deb_version + if checked_version is None: + return + for token in ok_to_preserve: + if issubclass(token, BranchSubstitutionVariable): + for name in base_branch.list_branch_names(): + checked_version = checked_version.replace( + token.determine_name(name), "") + checked_version = checked_version.replace( + token.determine_name(None), "") + else: + checked_version = checked_version.replace( + token.name, "") + if "{" in checked_version: + available_tokens = [var.name for var in simple_vars if + var.available_in(base_branch.format)] + for var_kls in branch_vars + deb_branch_vars: + if not var_kls.available_in(base_branch.format): + continue + for name in base_branch.list_branch_names(): + available_tokens.append(var_kls.determine_name(name)) + available_tokens.append(var_kls.determine_name(None)) + raise errors.BzrCommandError("deb-version not fully " + "expanded: %s. Valid substitutions in recipe format %s are: %s" + % (base_branch.deb_version, base_branch.format, + available_tokens)) + + +def substitute_branch_vars(base_branch, branch_name, branch, revid): + """Substitute the branch variables for the given branch name in deb_version. + + Where deb_version has a place to substitute the revno for a branch + this will substitute it for the given branch name. + + :param branch_name: the name of the RecipeBranch to substitute. + :param branch: Branch object for the branch + :param revid: Revision id in the branch for which to return the revno + """ + if base_branch.deb_version is None: + return + revno_var = RevnoVariable(branch_name, branch, revid) + base_branch.deb_version = revno_var.replace(base_branch.deb_version) + if base_branch.format < 0.4: + # The other variables were introduced in recipe format 0.4 + return + svn_revno_var = SubversionRevnumVariable(branch_name, branch, revid) + base_branch.deb_version = svn_revno_var.replace(base_branch.deb_version) + git_commit_var = GitCommitVariable(branch_name, branch, revid) + base_branch.deb_version = git_commit_var.replace(base_branch.deb_version) + latest_tag_var = LatestTagVariable(branch_name, branch, revid) + base_branch.deb_version = latest_tag_var.replace(base_branch.deb_version) + revdate_var = RevdateVariable(branch_name, branch, revid) + base_branch.deb_version = revdate_var.replace(base_branch.deb_version) + revtime_var = RevtimeVariable(branch_name, branch, revid) + base_branch.deb_version = revtime_var.replace(base_branch.deb_version) + tree = branch.repository.revision_tree(revid) + cl_file_id = tree.path2id("debian/changelog") + if cl_file_id is not None: + tree.lock_read() + try: + cl = changelog.Changelog(tree.get_file_text(cl_file_id)) + substitute_changelog_vars(base_branch, branch_name, cl) + finally: + tree.unlock() + + +def substitute_changelog_vars(base_branch, branch_name, changelog): + """Substitute variables related from a changelog. + + :param branch_name: Branch name (None for root branch) + :param changelog: Changelog object to use + """ + from bzrlib.plugins.builder.deb_version import DebUpstreamVariable, DebUpstreamBaseVariable, DebVersionVariable + debupstream_var = DebUpstreamVariable.from_changelog(branch_name, changelog) + base_branch.deb_version = debupstream_var.replace(base_branch.deb_version) + if base_branch.format < 0.3: + # The other variables were introduced in recipe format 0.4 + return + debupstreambase_var = DebUpstreamBaseVariable.from_changelog( + branch_name, changelog) + base_branch.deb_version = debupstreambase_var.replace(base_branch.deb_version) + pkgversion_var = DebVersionVariable.from_changelog(branch_name, changelog) + base_branch.deb_version = pkgversion_var.replace(base_branch.deb_version) + + +def substitute_time(base_branch, time): + """Substitute the time in to deb_version if needed. + + :param time: a datetime.datetime with the desired time. + """ + if base_branch.deb_version is None: + return + base_branch.deb_version = TimeVariable(time).replace(base_branch.deb_version) + base_branch.deb_version = DateVariable(time).replace(base_branch.deb_version) diff -Nru bzr-builder-0.7.2/info.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/info.py --- bzr-builder-0.7.2/info.py 1970-01-01 00:00:00.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/info.py 2014-08-25 05:41:16.000000000 +0000 @@ -0,0 +1,17 @@ +# bzr-builder: a bzr plugin to constuct trees based on recipes +# Copyright 2011 Canonical Ltd. + +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + + +bzr_plugin_version = (0, 7, 4, 'dev', 0) diff -Nru bzr-builder-0.7.2/__init__.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/__init__.py --- bzr-builder-0.7.2/__init__.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/__init__.py 2014-08-25 05:41:16.000000000 +0000 @@ -123,10 +123,31 @@ * {revno} will be the revno of the base branch (the first specified). * {revno:} will be substituted with the revno for the branch named in the recipe. - * {debupstream} will be replaced by the upstream portion of the version - number taken from debian/changelog in the final tree. If when the - tree is built the top of debian/changelog has a version number of - "1.0-1" then this would evaluate to "1.0". + * {debupstream}/{debupstream:} will be replaced by the upstream + portion of the version number taken from debian/changelog in the branch. + For example, if debian/changelog has a version number of "1.0-1" then this + would evaluate to "1.0". + * {debupstream-base}/{debupstream-base:} will be replaced by the + upstream portion of the version number taken from debian/changelog in the + branch, with any VCS markers stripped. For example, if debian/changelog + has a version number of "1.0~bzr43-1" then this would evaluate to "1.0~". + For any upstream versions without a VCS marker, a "+" is added to the + version ("1.0-1" becomes "1.0+"). + * {debversion}/{debversion:} will be substituted with + the exact version string from debian/changelog in the branch. + * {revtime}/{revtime:} will be substituted with the date and + time of the revision that was built, such as 201108191512. + * {revdate}/{revdate:} will be substituted with the date + of the revision that was built, such as 20111222. + * {latest-tag}/{latest-tag:} will be replaced with the + name of the tag found on the most recent revision in the + branch mainline that has a tag. + * {git-commit}/{git-commit:} will be substituted with the last 7 + characters of the SHA1 checksum of the revision that was built, if the + revision was imported from a Git repository. + * {svn-revno}/{svn-revno:} will be substituted with the + Subversion revision number of the revision that was built, if the + revision was imported from a Subversion repository. Instruction syntax summary: @@ -145,15 +166,17 @@ resulting tree """ -if __name__ == '__main__': - import os - import subprocess - import sys - dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugins") - retcode = subprocess.call("bzr selftest -s bzrlib.plugins.builder", - shell=True, env={"BZR_PLUGIN_PATH": dir}) - sys.exit(retcode) +from __future__ import absolute_import +from bzrlib.plugins.builder.info import ( + bzr_plugin_version as version_info, + ) + +if version_info[3] == 'final': + version_string = '%d.%d.%d' % version_info[:3] +else: + version_string = '%d.%d.%d%s%d' % version_info +__version__ = version_string from bzrlib.commands import plugin_cmds plugin_cmds.register_lazy("cmd_build", [], "bzrlib.plugins.builder.cmds") diff -Nru bzr-builder-0.7.2/recipe.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/recipe.py --- bzr-builder-0.7.2/recipe.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/recipe.py 2014-08-25 05:41:16.000000000 +0000 @@ -22,7 +22,6 @@ branch as _mod_branch, bzrdir, errors, - lazy_regex, merge, revision, revisionspec, @@ -40,11 +39,6 @@ try: - from debian import changelog -except ImportError: - from debian_bundle import changelog - -try: MergeIntoMerger = merge.MergeIntoMerger except (AttributeError, NameError): from bzrlib.plugins.builder.backports import MergeIntoMerger @@ -84,11 +78,18 @@ """Replace name with value.""" raise NotImplementedError(self.replace) + @classmethod + def available_in(cls, format): + """Check if this variable is available in a particular format.""" + raise NotImplementedError(cls.available_in) + class SimpleSubstitutionVariable(SubstitutionVariable): name = None + minimum_format = None + def replace(self, value): if not self.name in value: return value @@ -97,6 +98,10 @@ def get(self): raise NotImplementedError(self.value) + @classmethod + def available_in(self, format): + return (format >= self.minimum_format) + class BranchSubstitutionVariable(SimpleSubstitutionVariable): @@ -122,6 +127,8 @@ name = "{time}" + minimum_format = 0.1 + def __init__(self, time): self._time = time @@ -133,6 +140,8 @@ name = "{date}" + minimum_format = 0.1 + def __init__(self, time): self._time = time @@ -140,66 +149,10 @@ return self._time.strftime("%Y%m%d") -class DebUpstreamVariable(BranchSubstitutionVariable): - - basename = "debupstream" - - def __init__(self, branch_name, version): - super(DebUpstreamVariable, self).__init__(branch_name) - self._version = version - - @classmethod - def from_changelog(cls, branch_name, changelog): - if len(changelog._blocks) > 0: - return cls(branch_name, changelog._blocks[0].version) - else: - return cls(branch_name, None) - - def get(self): - if self._version is None: - raise SubstitutionUnavailable(self.name, - "No previous changelog to take the upstream version from") - # Should we include the epoch? - return self._version.upstream_version - - -class DebVersionVariable(BranchSubstitutionVariable): - - basename = "debversion" - - def __init__(self, branch_name, version): - super(DebVersionVariable, self).__init__(branch_name) - self._version = version - - @classmethod - def from_changelog(cls, branch_name, changelog): - if len(changelog._blocks) > 0: - return cls(branch_name, changelog._blocks[0].version) - else: - return cls(branch_name, None) - - def get(self): - if self._version is None: - raise SubstitutionUnavailable(self.name, - "No previous changelog to take the version from") - return str(self._version) - - -class DebUpstreamBaseVariable(DebUpstreamVariable): - - basename = "debupstream-base" - version_regex = lazy_regex.lazy_compile(r'([~+])(svn[0-9]+|bzr[0-9]+|git[0-9a-f]+)') - - def get(self): - version = super(DebUpstreamBaseVariable, self).get() - version = self.version_regex.sub("\\1", version) - if version[-1] not in ("~", "+"): - version += "+" - return version - - class RevisionVariable(BranchSubstitutionVariable): + minimum_format = 0.1 + def __init__(self, branch_name, branch, revid): super(RevisionVariable, self).__init__(branch_name) self.branch = branch @@ -210,6 +163,8 @@ basename = "revno" + minimum_format = 0.1 + def get_revno(self): try: revno = self.branch.revision_id_to_revno(self.revid) @@ -235,6 +190,8 @@ basename = "revtime" + minimum_format = 0.4 + def get(self): rev = self.branch.repository.get_revision(self.revid) return time.strftime("%Y%m%d%H%M", time.gmtime(rev.timestamp)) @@ -244,6 +201,8 @@ basename = "revdate" + minimum_format = 0.4 + def get(self): rev = self.branch.repository.get_revision(self.revid) return time.strftime("%Y%m%d", time.gmtime(rev.timestamp)) @@ -271,6 +230,8 @@ basename = "svn-revno" + minimum_format = 0.4 + def get(self): rev = self.branch.repository.get_revision(self.revid) try: @@ -304,6 +265,8 @@ basename = "git-commit" + minimum_format = 0.4 + def get(self): rev = self.branch.repository.get_revision(self.revid) try: @@ -319,6 +282,8 @@ basename = "latest-tag" + minimum_format = 0.4 + def get(self): reverse_tag_dict = self.branch.tags.get_reverse_tag_dict() self.branch.lock_read() @@ -334,39 +299,10 @@ self.branch.unlock() -ok_to_preserve = [DebUpstreamVariable, DebUpstreamBaseVariable, - DebVersionVariable] -# The variables that don't require substitution in their name -simple_vars = [TimeVariable, DateVariable] branch_vars = [RevnoVariable, SubversionRevnumVariable, - GitCommitVariable, LatestTagVariable, DebVersionVariable, - DebUpstreamBaseVariable, DebUpstreamVariable, RevdateVariable, + GitCommitVariable, LatestTagVariable, RevdateVariable, RevtimeVariable] - - -def check_expanded_deb_version(base_branch): - checked_version = base_branch.deb_version - if checked_version is None: - return - for token in ok_to_preserve: - if issubclass(token, BranchSubstitutionVariable): - for name in base_branch.list_branch_names(): - checked_version = checked_version.replace( - token.determine_name(name), "") - checked_version = checked_version.replace( - token.determine_name(None), "") - else: - checked_version = checked_version.replace( - token.name, "") - if "{" in checked_version: - available_tokens = [var.name for var in simple_vars] - for var_kls in branch_vars: - for name in base_branch.list_branch_names(): - available_tokens.append(var_kls.determine_name(name)) - available_tokens.append(var_kls.determine_name(None)) - raise errors.BzrCommandError("deb-version not fully " - "expanded: %s. Valid substitutions are: %s" - % (base_branch.deb_version, available_tokens)) +simple_vars = [TimeVariable, DateVariable] class CommandFailedError(errors.BzrError): @@ -558,6 +494,14 @@ try: if target_subdir is None: target_subdir = os.path.basename(subpath) + # Create any missing parent directories + target_subdir_parent = os.path.dirname(target_subdir) + missing = [] + while tree_to.path2id(target_subdir_parent) is None: + missing.append(target_subdir_parent) + target_subdir_parent = os.path.dirname(target_subdir_parent) + for path in reversed(missing): + tree_to.mkdir(path) merger = MergeIntoMerger(this_tree=tree_to, other_tree=other_tree, other_branch=child_branch.branch, target_subdir=target_subdir, source_subpath=subpath, other_rev_id=child_branch.revid) @@ -599,7 +543,8 @@ new_branch.branch.lock_read() try: new_branch.resolve_revision_id() - substitute_branch_vars(new_branch.name, new_branch.branch, new_branch.revid) + if substitute_branch_vars is not None: + substitute_branch_vars(new_branch.name, new_branch.branch, new_branch.revid) if (if_changed_from is not None and (new_branch.revspec is not None or if_changed_from.revspec is not None)): @@ -628,10 +573,11 @@ new_branch.branch.unlock() -def resolve_revisions(base_branch, if_changed_from=None): +def resolve_revisions(base_branch, if_changed_from=None, substitute_branch_vars=None): """Resolve all the unknowns in base_branch. - This walks the RecipeBranch and substitutes in revnos and deb_version. + This walks the RecipeBranch and calls substitute_branch_vars for + each child branch. If if_changed_from is not None then it should be a second RecipeBranch to compare base_branch against. If the shape, or the revision ids differ @@ -639,6 +585,8 @@ :param base_branch: the RecipeBranch we plan to build. :param if_changed_from: the RecipeBranch that we want to compare against. + :param substitute_branch_vars: Callable called for + each branch with (name, bzr branch and last revision) :return: False if if_changed_from is not None, and the shape and revisions of the two branches don't differ. True otherwise. """ @@ -648,12 +596,16 @@ if_changed_from_revisions = if_changed_from if changed: if_changed_from_revisions = None + + if substitute_branch_vars is not None: + real_subsitute_branch_vars = lambda n, b, r: substitute_branch_vars(base_branch, n, b, r) + else: + real_subsitute_branch_vars = None changed_revisions = _resolve_revisions_recurse(base_branch, - base_branch.substitute_branch_vars, + real_subsitute_branch_vars, if_changed_from=if_changed_from_revisions) if not changed: changed = changed_revisions - check_expanded_deb_version(base_branch) if if_changed_from is not None and not changed: return False return True @@ -984,66 +936,6 @@ self.deb_version = deb_version self.format = format - def substitute_branch_vars(self, branch_name, branch, revid): - """Substitute the branch variables for the given branch name in deb_version. - - Where deb_version has a place to substitute the revno for a branch - this will substitute it for the given branch name. - - :param branch_name: the name of the RecipeBranch to substitute. - :param branch: Branch object for the branch - :param revid: Revision id in the branch for which to return the revno - """ - if self.deb_version is None: - return - revno_var = RevnoVariable(branch_name, branch, revid) - self.deb_version = revno_var.replace(self.deb_version) - if self.format in (0.1, 0.2, 0.3): - return - svn_revno_var = SubversionRevnumVariable(branch_name, branch, revid) - self.deb_version = svn_revno_var.replace(self.deb_version) - git_commit_var = GitCommitVariable(branch_name, branch, revid) - self.deb_version = git_commit_var.replace(self.deb_version) - latest_tag_var = LatestTagVariable(branch_name, branch, revid) - self.deb_version = latest_tag_var.replace(self.deb_version) - revdate_var = RevdateVariable(branch_name, branch, revid) - self.deb_version = revdate_var.replace(self.deb_version) - revtime_var = RevtimeVariable(branch_name, branch, revid) - self.deb_version = revtime_var.replace(self.deb_version) - tree = branch.repository.revision_tree(revid) - cl_file_id = tree.path2id("debian/changelog") - if cl_file_id is not None: - tree.lock_read() - try: - cl = changelog.Changelog(tree.get_file(cl_file_id)) - self.substitute_changelog_vars(branch_name, cl) - finally: - tree.unlock() - - def substitute_changelog_vars(self, branch_name, changelog): - """Substitute variables related from a changelog. - - :param branch_name: Branch name (None for root branch) - :param changelog: Changelog object to use - """ - debupstream_var = DebUpstreamVariable.from_changelog(branch_name, changelog) - self.deb_version = debupstream_var.replace(self.deb_version) - debupstreambase_var = DebUpstreamBaseVariable.from_changelog( - branch_name, changelog) - self.deb_version = debupstreambase_var.replace(self.deb_version) - pkgversion_var = DebVersionVariable.from_changelog(branch_name, changelog) - self.deb_version = pkgversion_var.replace(self.deb_version) - - def substitute_time(self, time): - """Substitute the time in to deb_version if needed. - - :param time: a datetime.datetime with the desired time. - """ - if self.deb_version is None: - return - self.deb_version = TimeVariable(time).replace(self.deb_version) - self.deb_version = DateVariable(time).replace(self.deb_version) - def _add_child_branches_to_manifest(self, child_branches, indent_level): manifest = "" for instruction in child_branches: diff -Nru bzr-builder-0.7.2/setup.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/setup.py --- bzr-builder-0.7.2/setup.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/setup.py 2014-08-25 05:41:16.000000000 +0000 @@ -1,10 +1,15 @@ #!/usr/bin/python +from info import * + from distutils.core import setup if __name__ == '__main__': + version = bzr_plugin_version[:3] + version_string = ".".join([str(x) for x in version]) + setup(name="bzr-builder", - version="0.7.2", + version=version_string, description="Turn a recipe in to a bzr branch", author="James Westby", author_email="james.westby@canonical.com", diff -Nru bzr-builder-0.7.2/tests/__init__.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/__init__.py --- bzr-builder-0.7.2/tests/__init__.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/__init__.py 2014-08-25 05:41:16.000000000 +0000 @@ -45,7 +45,8 @@ suite = TestSuite() testmod_names = [ 'blackbox', - 'ppa', + 'deb_util', + 'deb_version', 'recipe', ] suite.addTest(loader.loadTestsFromModuleNames(["%s.test_%s" % (__name__, i) diff -Nru bzr-builder-0.7.2/tests/test_blackbox.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_blackbox.py --- bzr-builder-0.7.2/tests/test_blackbox.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_blackbox.py 2014-08-25 05:41:16.000000000 +0000 @@ -26,13 +26,13 @@ ) from bzrlib.branch import Branch from bzrlib.tests import ( - TestCaseWithTransport, - TestSkipped, - ) -from bzrlib.tests.features import Feature - + TestCaseWithTransport, + ) -from bzrlib.plugins.builder.tests import PristineTarFeature +from bzrlib.plugins.builder.tests import ( + Feature, + PristineTarFeature, + ) try: from debian import changelog @@ -381,7 +381,7 @@ def test_cmd_dailydeb_with_version_from_changelog(self): self.requireFeature(NotUnderFakeRootFeature) self.make_simple_package("source") - self.build_tree_contents([("test.recipe", "# bzr-builder format 0.1 " + self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 " "deb-version {debversion}-2\nsource 1\n")]) out, err = self.run_bzr( "dailydeb --allow-fallback-to-native -q test.recipe working") @@ -485,8 +485,10 @@ source = self.make_simple_package("source") self.build_tree(["source/debian/source/"]) self.build_tree_contents([ - ("source/debian/source/format", "3.0 (quilt)\n")]) - source.add(["debian/source", "debian/source/format"]) + ("source/debian/source/format", "3.0 (quilt)\n"), + ("source/debian/source/options", 'compression = "gzip"\n')]) + source.add([ + "debian/source", "debian/source/format", "debian/source/options"]) source.commit("set source format") return source diff -Nru bzr-builder-0.7.2/tests/test_deb_util.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_deb_util.py --- bzr-builder-0.7.2/tests/test_deb_util.py 1970-01-01 00:00:00.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_deb_util.py 2014-08-25 05:41:16.000000000 +0000 @@ -0,0 +1,28 @@ +# bzr-builder: a bzr plugin to construct trees based on recipes +# Copyright 2009 Canonical Ltd. + +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +from bzrlib.plugins.builder.deb_util import target_from_dput +from bzrlib.tests import ( + TestCase, + ) + + +class TestTargetFromDPut(TestCase): + + def test_default_ppa(self): + self.assertEqual(('team-name', 'ppa'), target_from_dput('ppa:team-name')) + + def test_named_ppa(self): + self.assertEqual(('team', 'ppa2'), target_from_dput('ppa:team/ppa2')) diff -Nru bzr-builder-0.7.2/tests/test_deb_version.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_deb_version.py --- bzr-builder-0.7.2/tests/test_deb_version.py 1970-01-01 00:00:00.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_deb_version.py 2014-08-25 05:41:16.000000000 +0000 @@ -0,0 +1,441 @@ +# bzr-builder: a bzr plugin to constuct trees based on recipes +# Copyright 2009-2011 Canonical Ltd. + +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +import datetime +import textwrap + +from bzrlib import ( + errors, + ) +from bzrlib.tests import ( + TestCase, + TestCaseWithTransport, + ) +from bzrlib.plugins.builder.deb_version import ( + DebUpstreamBaseVariable, + DebUpstreamVariable, + DebVersionVariable, + SubstitutionUnavailable, + check_expanded_deb_version, + version_extract_base, + substitute_branch_vars, + substitute_time, + ) +from bzrlib.plugins.builder.recipe import ( + BaseRecipeBranch, + RecipeBranch, + resolve_revisions, + ) + +try: + from debian import changelog +except ImportError: + # In older versions of python-debian the main package was named + # debian_bundle + from debian_bundle import changelog + + +class ResolveRevisionsTests(TestCaseWithTransport): + + def test_unchanged(self): + source =self.make_branch_and_tree("source") + revid = source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1") + branch2 = BaseRecipeBranch("source", "{revno}", 0.2, + revspec="revid:%s" % revid) + self.assertEqual(False, resolve_revisions(branch1, + if_changed_from=branch2, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + self.assertEqual(revid, branch1.revid) + self.assertEqual("1", branch1.revspec) + self.assertEqual("1", branch1.deb_version) + + def test_unchanged_not_explicit(self): + source =self.make_branch_and_tree("source") + revid = source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2) + branch2 = BaseRecipeBranch("source", "{revno}", 0.2, + revspec="revid:%s" % revid) + self.assertEqual(False, resolve_revisions(branch1, + if_changed_from=branch2, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + self.assertEqual(revid, branch1.revid) + self.assertEqual(None, branch1.revspec) + self.assertEqual("1", branch1.deb_version) + + def test_unchanged_multilevel(self): + source =self.make_branch_and_tree("source") + revid = source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2) + branch2 = RecipeBranch("nested1", "source") + branch3 = RecipeBranch("nested2", "source") + branch2.nest_branch("bar", branch3) + branch1.nest_branch("foo", branch2) + branch4 = BaseRecipeBranch("source", "{revno}", 0.2, + revspec="revid:%s" % revid) + branch5 = RecipeBranch("nested1", "source", + revspec="revid:%s" % revid) + branch6 = RecipeBranch("nested2", "source", + revspec="revid:%s" % revid) + branch5.nest_branch("bar", branch6) + branch4.nest_branch("foo", branch5) + self.assertEqual(False, resolve_revisions(branch1, + if_changed_from=branch4, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + self.assertEqual(revid, branch1.revid) + self.assertEqual(None, branch1.revspec) + self.assertEqual("1", branch1.deb_version) + + def test_changed(self): + source =self.make_branch_and_tree("source") + revid = source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1") + branch2 = BaseRecipeBranch("source", "{revno}", 0.2, + revspec="revid:foo") + self.assertEqual(True, resolve_revisions(branch1, + if_changed_from=branch2, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + self.assertEqual(revid, branch1.revid) + self.assertEqual("1", branch1.revspec) + self.assertEqual("1", branch1.deb_version) + + def test_changed_shape(self): + source =self.make_branch_and_tree("source") + revid = source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1") + branch2 = BaseRecipeBranch("source", "{revno}", 0.2, + revspec="revid:%s" % revid) + branch3 = RecipeBranch("nested", "source") + branch1.nest_branch("foo", branch3) + self.assertEqual(True, resolve_revisions(branch1, + if_changed_from=branch2, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + self.assertEqual(revid, branch1.revid) + self.assertEqual("1", branch1.revspec) + self.assertEqual("1", branch1.deb_version) + + def test_changed_command(self): + source =self.make_branch_and_tree("source") + source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2) + branch2 = BaseRecipeBranch("source", "{revno}", 0.2) + branch1.run_command("touch test1") + branch2.run_command("touch test2") + self.assertEqual(True, resolve_revisions(branch1, + if_changed_from=branch2, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + + def test_unchanged_command(self): + source =self.make_branch_and_tree("source") + source.commit("one") + branch1 = BaseRecipeBranch("source", "{revno}", 0.2) + branch2 = BaseRecipeBranch("source", "{revno}", 0.2) + branch1.run_command("touch test1") + branch2.run_command("touch test1") + self.assertEqual(False, resolve_revisions(branch1, + if_changed_from=branch2, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + + def test_substitute(self): + source =self.make_branch_and_tree("source") + revid1 = source.commit("one") + source.commit("two") + branch1 = BaseRecipeBranch("source", + "{revno}-{revno:packaging}", 0.2, revspec="1") + branch2 = RecipeBranch("packaging", "source") + branch1.nest_branch("debian", branch2) + self.assertEqual(True, resolve_revisions(branch1, + substitute_branch_vars=substitute_branch_vars)) + self.assertEqual("source", branch1.url) + self.assertEqual(revid1, branch1.revid) + 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, + substitute_branch_vars=substitute_branch_vars) + self.assertEqual("{debupstream}-2", branch1.deb_version) + + def test_subsitute_not_fully_expanded(self): + source =self.make_branch_and_tree("source") + source.commit("one") + source.commit("two") + branch1 = BaseRecipeBranch("source", "{revno:packaging}", 0.2) + resolve_revisions(branch1, substitute_branch_vars=substitute_branch_vars) + self.assertRaises(errors.BzrCommandError, check_expanded_deb_version, branch1) + + def test_substitute_svn_not_svn(self): + br = self.make_branch("source") + source = br.create_checkout("checkout") + source.commit("one") + source.commit("two") + branch1 = BaseRecipeBranch("source", "foo-{svn-revno}", 0.4) + e = self.assertRaises(errors.BzrCommandError, resolve_revisions, + branch1, None, substitute_branch_vars) + self.assertTrue(str(e).startswith("unable to expand {svn-revno} "), + e) + + def test_substitute_svn(self): + br = self.make_branch("source") + source = br.create_checkout("checkout") + source.commit("one") + source.commit("two", + rev_id="svn-v4:be7e6eca-30d4-0310-a8e5-ac0d63af7070:trunk:5344") + branch1 = BaseRecipeBranch("source", "foo-{svn-revno}", 0.4) + resolve_revisions(branch1, substitute_branch_vars=substitute_branch_vars) + self.assertEqual("foo-5344", branch1.deb_version) + + def test_substitute_git_not_git(self): + source = self.make_branch_and_tree("source") + source.commit("one") + source.commit("two") + branch1 = BaseRecipeBranch("source", "foo-{git-commit}", 0.4) + e = self.assertRaises(errors.BzrCommandError, resolve_revisions, + branch1, None, substitute_branch_vars) + self.assertTrue(str(e).startswith("unable to expand {git-commit} "), + e) + + def test_substitute_git(self): + source = self.make_branch_and_tree("source") + source.commit("one", + rev_id="git-v1:a029d7b2cc83c26a53d8b2a24fa12c340fcfac58") + branch1 = BaseRecipeBranch("source", "foo-{git-commit}", 0.4) + resolve_revisions(branch1, + substitute_branch_vars=substitute_branch_vars) + self.assertEqual("foo-a029d7b", branch1.deb_version) + + def test_latest_tag(self): + source = self.make_branch_and_tree("source") + revid = source.commit("one") + source.branch.tags.set_tag("millbank", revid) + source.commit("two") + branch1 = BaseRecipeBranch("source", "foo-{latest-tag}", 0.4) + resolve_revisions(branch1, + substitute_branch_vars=substitute_branch_vars) + self.assertEqual("foo-millbank", branch1.deb_version) + + def test_latest_tag_no_tag(self): + source = self.make_branch_and_tree("source") + revid = source.commit("one") + source.commit("two") + branch1 = BaseRecipeBranch("source", "foo-{latest-tag}", 0.4) + e = self.assertRaises(errors.BzrCommandError, + resolve_revisions, branch1, + substitute_branch_vars=substitute_branch_vars) + self.assertTrue(str(e).startswith("No tags set on branch None mainline"), + e) + + def test_substitute_revdate(self): + br = self.make_branch("source") + source = br.create_checkout("checkout") + source.commit("one") + source.commit("two", timestamp=1307708628, timezone=0) + branch1 = BaseRecipeBranch("source", "foo-{revdate}", 0.4) + resolve_revisions(branch1, + substitute_branch_vars=substitute_branch_vars) + self.assertEqual("foo-20110610", branch1.deb_version) + + def test_substitute_revtime(self): + br = self.make_branch("source") + source = br.create_checkout("checkout") + source.commit("one") + source.commit("two", timestamp=1307708628, timezone=0) + branch1 = BaseRecipeBranch("source", "foo-{revtime}", 0.4) + resolve_revisions(branch1, + substitute_branch_vars=substitute_branch_vars) + self.assertEqual("foo-201106101223", branch1.deb_version) + + +class DebUpstreamVariableTests(TestCase): + + def write_changelog(self, version): + contents = textwrap.dedent(""" + package (%s) experimental; urgency=low + + * Initial release. (Closes: #XXXXXX) + + -- Jelmer Vernooij Thu, 19 May 2011 10:07:41 +0100 + """ % version)[1:] + return changelog.Changelog(file=contents) + + def test_empty_changelog(self): + var = DebUpstreamVariable.from_changelog(None, changelog.Changelog()) + self.assertRaises(SubstitutionUnavailable, var.get) + + def test_version(self): + var = DebUpstreamVariable.from_changelog(None, + self.write_changelog("2.3")) + self.assertEquals("2.3", var.get()) + + def test_epoch(self): + # The epoch is (currently) ignored by {debupstream}. + var = DebUpstreamVariable.from_changelog(None, + self.write_changelog("2:2.3")) + self.assertEquals("2.3", var.get()) + + def test_base_without_snapshot(self): + var = DebUpstreamBaseVariable.from_changelog(None, + self.write_changelog("2.4")) + self.assertEquals("2.4+", var.get()) + + def test_base_with_svn_snapshot(self): + var = DebUpstreamBaseVariable.from_changelog(None, + self.write_changelog("2.4~svn4")) + self.assertEquals("2.4~", var.get()) + + def test_base_with_bzr_snapshot(self): + var = DebUpstreamBaseVariable.from_changelog(None, + self.write_changelog("2.4+bzr343")) + self.assertEquals("2.4+", var.get()) + + +class VersionExtractBaseTests(TestCase): + + def test_simple_extract(self): + self.assertEquals("2.4", version_extract_base("2.4")) + self.assertEquals("2.4+foobar", version_extract_base("2.4+foobar")) + + def test_with_bzr(self): + self.assertEquals("2.4+", version_extract_base("2.4+bzr32")) + self.assertEquals("2.4~", version_extract_base("2.4~bzr32")) + + def test_with_git(self): + self.assertEquals("2.4+", version_extract_base("2.4+git20101010")) + self.assertEquals("2.4~", version_extract_base("2.4~gitaabbccdd")) + + def test_with_svn(self): + self.assertEquals("2.4+", version_extract_base("2.4+svn45")) + self.assertEquals("2.4~", version_extract_base("2.4~svn45")) + + def test_with_dfsg(self): + self.assertEquals("2.4+", version_extract_base("2.4+bzr32+dfsg1")) + self.assertEquals("2.4~", version_extract_base("2.4~bzr32+dfsg.1")) + self.assertEquals("2.4~", version_extract_base("2.4~bzr32.dfsg.1")) + self.assertEquals("2.4~", version_extract_base("2.4~bzr32dfsg.1")) + self.assertEquals("1.6~", version_extract_base("1.6~git20120320.dfsg.1")) + + +class DebVersionVariableTests(TestCase): + + def write_changelog(self, version): + contents = textwrap.dedent(""" + package (%s) experimental; urgency=low + + * Initial release. (Closes: #XXXXXX) + + -- Jelmer Vernooij Thu, 19 May 2011 10:07:41 +0100 + """ % version)[1:] + return changelog.Changelog(file=contents) + + def test_empty_changelog(self): + var = DebVersionVariable.from_changelog(None, changelog.Changelog()) + self.assertRaises(SubstitutionUnavailable, var.get) + + def test_simple(self): + var = DebVersionVariable.from_changelog( + None, self.write_changelog("2.3-1")) + self.assertEquals("2.3-1", var.get()) + + def test_epoch(self): + var = DebVersionVariable.from_changelog( + None, self.write_changelog("4:2.3-1")) + self.assertEquals("4:2.3-1", var.get()) + + +class RecipeBranchTests(TestCaseWithTransport): + + def test_substitute_time(self): + time = datetime.datetime.utcfromtimestamp(1) + base_branch = BaseRecipeBranch("base_url", "1-{time}", 0.2) + substitute_time(base_branch, time) + self.assertEqual("1-197001010000", base_branch.deb_version) + substitute_time(base_branch, time) + self.assertEqual("1-197001010000", base_branch.deb_version) + + def test_substitute_date(self): + time = datetime.datetime.utcfromtimestamp(1) + base_branch = BaseRecipeBranch("base_url", "1-{date}", 0.2) + substitute_time(base_branch, time) + self.assertEqual("1-19700101", base_branch.deb_version) + substitute_time(base_branch, time) + self.assertEqual("1-19700101", base_branch.deb_version) + + def test_substitute_branch_vars(self): + base_branch = BaseRecipeBranch("base_url", "1", 0.2) + wt = self.make_branch_and_tree("br") + revid = wt.commit("acommit") + substitute_branch_vars(base_branch, None, wt.branch, revid) + self.assertEqual("1", base_branch.deb_version) + substitute_branch_vars(base_branch, None, wt.branch, revid) + self.assertEqual("1", base_branch.deb_version) + base_branch = BaseRecipeBranch("base_url", "{revno}", 0.2) + substitute_branch_vars(base_branch, None, wt.branch, revid) + self.assertEqual("1", base_branch.deb_version) + base_branch = BaseRecipeBranch("base_url", "{revno}", 0.2) + substitute_branch_vars(base_branch, "foo", wt.branch, revid) + self.assertEqual("{revno}", base_branch.deb_version) + substitute_branch_vars(base_branch, "foo", wt.branch, revid) + self.assertEqual("{revno}", base_branch.deb_version) + base_branch = BaseRecipeBranch("base_url", "{revno:foo}", 0.2) + substitute_branch_vars(base_branch, "foo", wt.branch, revid) + self.assertEqual("1", base_branch.deb_version) + + def test_substitute_branch_vars_debupstream(self): + wt = self.make_branch_and_tree("br") + revid1 = wt.commit("acommit") + cl_contents = ("package (0.1-1) unstable; urgency=low\n * foo\n" + " -- maint Tue, 04 Aug 2009 " + "10:03:10 +0100\n") + self.build_tree_contents( + [("br/debian/", ), ('br/debian/changelog', cl_contents)]) + wt.add(['debian', 'debian/changelog']) + revid2 = wt.commit("with changelog") + base_branch = BaseRecipeBranch("base_url", "{debupstream}", 0.4) + # No changelog file, so no substitution + substitute_branch_vars(base_branch, None, wt.branch, revid1) + self.assertEqual("{debupstream}", base_branch.deb_version) + substitute_branch_vars(base_branch, None, wt.branch, revid2) + self.assertEqual("0.1", base_branch.deb_version) + base_branch = BaseRecipeBranch("base_url", "{debupstream:tehname}", 0.4) + substitute_branch_vars(base_branch, "tehname", wt.branch, revid2) + self.assertEqual("0.1", base_branch.deb_version) + + def test_substitute_branch_vars_debupstream_pre_0_4(self): + wt = self.make_branch_and_tree("br") + cl_contents = ("package (0.1-1) unstable; urgency=low\n * foo\n" + " -- maint Tue, 04 Aug 2009 " + "10:03:10 +0100\n") + self.build_tree_contents( + [("br/debian/", ), ('br/debian/changelog', cl_contents)]) + wt.add(['debian', 'debian/changelog']) + revid = wt.commit("with changelog") + # In recipe format < 0.4 {debupstream} gets replaced from the resulting + # tree, not from the branch vars. + base_branch = BaseRecipeBranch("base_url", "{debupstream}", 0.2) + substitute_branch_vars(base_branch, None, wt.branch, revid) + self.assertEqual("{debupstream}", base_branch.deb_version) diff -Nru bzr-builder-0.7.2/tests/test_ppa.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_ppa.py --- bzr-builder-0.7.2/tests/test_ppa.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_ppa.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ -# bzr-builder: a bzr plugin to construct trees based on recipes -# Copyright 2009 Canonical Ltd. - -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 3, as published -# by the Free Software Foundation. - -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranties of -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . - -from bzrlib.plugins.builder.cmds import target_from_dput -from bzrlib.tests import ( - TestCase, - ) - - -class TestTargetFromDPut(TestCase): - - def test_default_ppa(self): - self.assertEqual(('team-name', 'ppa'), target_from_dput('ppa:team-name')) - - def test_named_ppa(self): - self.assertEqual(('team', 'ppa2'), target_from_dput('ppa:team/ppa2')) diff -Nru bzr-builder-0.7.2/tests/test_recipe.py bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_recipe.py --- bzr-builder-0.7.2/tests/test_recipe.py 2011-11-10 13:25:38.000000000 +0000 +++ bzr-builder-0.7.3+bzr174~ppa13~ubuntu12.04.1/tests/test_recipe.py 2014-08-25 05:41:16.000000000 +0000 @@ -13,9 +13,7 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . -import datetime import os -import textwrap from bzrlib import ( errors, @@ -23,41 +21,27 @@ workingtree, ) from bzrlib.tests import ( - TestCase, TestCaseInTempDir, TestCaseWithTransport, ) from bzrlib.plugins.builder.recipe import ( BaseRecipeBranch, build_tree, - DebUpstreamBaseVariable, - DebUpstreamVariable, ensure_basedir, InstructionParseError, ForbiddenInstructionError, MERGE_INSTRUCTION, NEST_INSTRUCTION, NEST_PART_INSTRUCTION, - DebVersionVariable, pull_or_branch, RecipeParser, RecipeBranch, RecipeParseError, - resolve_revisions, RUN_INSTRUCTION, SAFE_INSTRUCTIONS, - SubstitutionUnavailable, USAGE, ) -try: - from debian import changelog -except ImportError: - # In older versions of python-debian the main package was named - # debian_bundle - from debian_bundle import changelog - - class RecipeParserTests(TestCaseInTempDir): deb_version = "0.1-{revno}" @@ -654,6 +638,33 @@ self.assertEqual(source1_rev_id, base_branch.revid) self.assertEqual(source2_rev_id, merged_branch.revid) + def test_build_tree_implicit_dir(self): + # Branches nested into non-existant directories trigger creation of + # those directories. + source1 = self.make_source_branch("source1") + source2 = self.make_source_branch("source2") + source3 = self.make_source_branch("source3") + self.build_tree_contents([ + ("source2/file", "new file"), + ("source3/yetanotherfile", "rugby")]) + source2.add(["file"]) + source2.commit("two") + source3.add(["yetanotherfile"]) + source3.commit("three") + base_branch = BaseRecipeBranch("source1", "1", 0.4) + merged_branch_2 = RecipeBranch("merged", "source2") + # Merge source2 into path implicit/b + base_branch.nest_part_branch(merged_branch_2, ".", + target_subdir="implicit/b") + # Merge source3 into path implicit/moreimplicit/c + merged_branch_3 = RecipeBranch("merged", "source3") + base_branch.nest_part_branch(merged_branch_3, ".", + target_subdir="moreimplicit/another/c") + build_tree(base_branch, "target") + self.check_file_contents("target/implicit/b/file", "new file") + self.check_file_contents("target/moreimplicit/another/c/yetanotherfile", + "rugby") + def test_build_tree_nest_part(self): """A recipe can specify a merge of just part of an unrelated tree.""" source1 = self.make_source_branch("source1") @@ -723,7 +734,7 @@ self.assertPathExists("target") tree = workingtree.WorkingTree.open("target") last_revid = tree.last_revision() - previous_revid = tree.branch.revision_history()[-2] + previous_revid = tree.branch.repository.get_revision(tree.branch.last_revision()).parent_ids[0] last_revtree = tree.branch.repository.revision_tree(last_revid) previous_revtree = tree.branch.repository.revision_tree(previous_revid) self.assertEqual([previous_revid, source3_rev_id], @@ -932,214 +943,6 @@ "revspec at the end of the merge line?")) -class ResolveRevisionsTests(TestCaseWithTransport): - - def test_unchanged(self): - source =self.make_branch_and_tree("source") - revid = source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1") - branch2 = BaseRecipeBranch("source", "{revno}", 0.2, - revspec="revid:%s" % revid) - self.assertEqual(False, resolve_revisions(branch1, - if_changed_from=branch2)) - self.assertEqual("source", branch1.url) - self.assertEqual(revid, branch1.revid) - self.assertEqual("1", branch1.revspec) - self.assertEqual("1", branch1.deb_version) - - def test_unchanged_not_explicit(self): - source =self.make_branch_and_tree("source") - revid = source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2) - branch2 = BaseRecipeBranch("source", "{revno}", 0.2, - revspec="revid:%s" % revid) - self.assertEqual(False, resolve_revisions(branch1, - if_changed_from=branch2)) - self.assertEqual("source", branch1.url) - self.assertEqual(revid, branch1.revid) - self.assertEqual(None, branch1.revspec) - self.assertEqual("1", branch1.deb_version) - - def test_unchanged_multilevel(self): - source =self.make_branch_and_tree("source") - revid = source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2) - branch2 = RecipeBranch("nested1", "source") - branch3 = RecipeBranch("nested2", "source") - branch2.nest_branch("bar", branch3) - branch1.nest_branch("foo", branch2) - branch4 = BaseRecipeBranch("source", "{revno}", 0.2, - revspec="revid:%s" % revid) - branch5 = RecipeBranch("nested1", "source", - revspec="revid:%s" % revid) - branch6 = RecipeBranch("nested2", "source", - revspec="revid:%s" % revid) - branch5.nest_branch("bar", branch6) - branch4.nest_branch("foo", branch5) - self.assertEqual(False, resolve_revisions(branch1, - if_changed_from=branch4)) - self.assertEqual("source", branch1.url) - self.assertEqual(revid, branch1.revid) - self.assertEqual(None, branch1.revspec) - self.assertEqual("1", branch1.deb_version) - - def test_changed(self): - source =self.make_branch_and_tree("source") - revid = source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1") - branch2 = BaseRecipeBranch("source", "{revno}", 0.2, - revspec="revid:foo") - self.assertEqual(True, resolve_revisions(branch1, - if_changed_from=branch2)) - self.assertEqual("source", branch1.url) - self.assertEqual(revid, branch1.revid) - self.assertEqual("1", branch1.revspec) - self.assertEqual("1", branch1.deb_version) - - def test_changed_shape(self): - source =self.make_branch_and_tree("source") - revid = source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2, revspec="1") - branch2 = BaseRecipeBranch("source", "{revno}", 0.2, - revspec="revid:%s" % revid) - branch3 = RecipeBranch("nested", "source") - branch1.nest_branch("foo", branch3) - self.assertEqual(True, resolve_revisions(branch1, - if_changed_from=branch2)) - self.assertEqual("source", branch1.url) - self.assertEqual(revid, branch1.revid) - self.assertEqual("1", branch1.revspec) - self.assertEqual("1", branch1.deb_version) - - def test_changed_command(self): - source =self.make_branch_and_tree("source") - source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2) - branch2 = BaseRecipeBranch("source", "{revno}", 0.2) - branch1.run_command("touch test1") - branch2.run_command("touch test2") - self.assertEqual(True, resolve_revisions(branch1, - if_changed_from=branch2)) - self.assertEqual("source", branch1.url) - - def test_unchanged_command(self): - source =self.make_branch_and_tree("source") - source.commit("one") - branch1 = BaseRecipeBranch("source", "{revno}", 0.2) - branch2 = BaseRecipeBranch("source", "{revno}", 0.2) - branch1.run_command("touch test1") - branch2.run_command("touch test1") - self.assertEqual(False, resolve_revisions(branch1, - if_changed_from=branch2)) - self.assertEqual("source", branch1.url) - - def test_substitute(self): - source =self.make_branch_and_tree("source") - revid1 = source.commit("one") - source.commit("two") - branch1 = BaseRecipeBranch("source", - "{revno}-{revno:packaging}", 0.2, revspec="1") - branch2 = RecipeBranch("packaging", "source") - branch1.nest_branch("debian", branch2) - self.assertEqual(True, resolve_revisions(branch1)) - self.assertEqual("source", branch1.url) - self.assertEqual(revid1, branch1.revid) - 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) - - def test_subsitute_not_fully_expanded(self): - source =self.make_branch_and_tree("source") - source.commit("one") - source.commit("two") - branch1 = BaseRecipeBranch("source", "{revno:packaging}", 0.2) - self.assertRaises(errors.BzrCommandError, resolve_revisions, branch1) - - def test_substitute_svn_not_svn(self): - br = self.make_branch("source") - source = br.create_checkout("checkout") - source.commit("one") - source.commit("two") - branch1 = BaseRecipeBranch("source", "foo-{svn-revno}", 0.4) - e = self.assertRaises(errors.BzrCommandError, resolve_revisions, - branch1) - self.assertTrue(str(e).startswith("unable to expand {svn-revno} "), - e) - - def test_substitute_svn(self): - br = self.make_branch("source") - source = br.create_checkout("checkout") - source.commit("one") - source.commit("two", - rev_id="svn-v4:be7e6eca-30d4-0310-a8e5-ac0d63af7070:trunk:5344") - branch1 = BaseRecipeBranch("source", "foo-{svn-revno}", 0.4) - resolve_revisions(branch1) - self.assertEqual("foo-5344", branch1.deb_version) - - def test_substitute_git_not_git(self): - source = self.make_branch_and_tree("source") - source.commit("one") - source.commit("two") - branch1 = BaseRecipeBranch("source", "foo-{git-commit}", 0.4) - e = self.assertRaises(errors.BzrCommandError, resolve_revisions, - branch1) - self.assertTrue(str(e).startswith("unable to expand {git-commit} "), - e) - - def test_substitute_git(self): - source = self.make_branch_and_tree("source") - source.commit("one", - rev_id="git-v1:a029d7b2cc83c26a53d8b2a24fa12c340fcfac58") - branch1 = BaseRecipeBranch("source", "foo-{git-commit}", 0.4) - resolve_revisions(branch1) - self.assertEqual("foo-a029d7b", branch1.deb_version) - - def test_latest_tag(self): - source = self.make_branch_and_tree("source") - revid = source.commit("one") - source.branch.tags.set_tag("millbank", revid) - source.commit("two") - branch1 = BaseRecipeBranch("source", "foo-{latest-tag}", 0.4) - resolve_revisions(branch1) - self.assertEqual("foo-millbank", branch1.deb_version) - - def test_latest_tag_no_tag(self): - source = self.make_branch_and_tree("source") - revid = source.commit("one") - source.commit("two") - branch1 = BaseRecipeBranch("source", "foo-{latest-tag}", 0.4) - e = self.assertRaises(errors.BzrCommandError, resolve_revisions, branch1) - self.assertTrue(str(e).startswith("No tags set on branch None mainline"), - e) - - def test_substitute_revdate(self): - br = self.make_branch("source") - source = br.create_checkout("checkout") - source.commit("one") - source.commit("two", timestamp=1307708628, timezone=0) - branch1 = BaseRecipeBranch("source", "foo-{revdate}", 0.4) - resolve_revisions(branch1) - self.assertEqual("foo-20110610", branch1.deb_version) - - def test_substitute_revtime(self): - br = self.make_branch("source") - source = br.create_checkout("checkout") - source.commit("one") - source.commit("two", timestamp=1307708628, timezone=0) - branch1 = BaseRecipeBranch("source", "foo-{revtime}", 0.4) - resolve_revisions(branch1) - self.assertEqual("foo-201106101223", branch1.deb_version) - - class StringifyTests(TestCaseInTempDir): def test_missing_debversion(self): @@ -1317,77 +1120,6 @@ rbranch2 = RecipeBranch("name", "other_url2") self.assertTrue(rbranch1.different_shape_to(rbranch2)) - def test_substitute_time(self): - time = datetime.datetime.utcfromtimestamp(1) - base_branch = BaseRecipeBranch("base_url", "1-{time}", 0.2) - base_branch.substitute_time(time) - self.assertEqual("1-197001010000", base_branch.deb_version) - base_branch.substitute_time(time) - self.assertEqual("1-197001010000", base_branch.deb_version) - - def test_substitute_date(self): - time = datetime.datetime.utcfromtimestamp(1) - base_branch = BaseRecipeBranch("base_url", "1-{date}", 0.2) - base_branch.substitute_time(time) - self.assertEqual("1-19700101", base_branch.deb_version) - base_branch.substitute_time(time) - self.assertEqual("1-19700101", base_branch.deb_version) - - def test_substitute_branch_vars(self): - base_branch = BaseRecipeBranch("base_url", "1", 0.2) - wt = self.make_branch_and_tree("br") - revid = wt.commit("acommit") - base_branch.substitute_branch_vars(None, wt.branch, revid) - self.assertEqual("1", base_branch.deb_version) - base_branch.substitute_branch_vars(None, wt.branch, revid) - self.assertEqual("1", base_branch.deb_version) - base_branch = BaseRecipeBranch("base_url", "{revno}", 0.2) - base_branch.substitute_branch_vars(None, wt.branch, revid) - self.assertEqual("1", base_branch.deb_version) - base_branch = BaseRecipeBranch("base_url", "{revno}", 0.2) - base_branch.substitute_branch_vars("foo", wt.branch, revid) - self.assertEqual("{revno}", base_branch.deb_version) - base_branch.substitute_branch_vars("foo", wt.branch, revid) - self.assertEqual("{revno}", base_branch.deb_version) - base_branch = BaseRecipeBranch("base_url", "{revno:foo}", 0.2) - base_branch.substitute_branch_vars("foo", wt.branch, revid) - self.assertEqual("1", base_branch.deb_version) - - def test_substitute_branch_vars_debupstream(self): - wt = self.make_branch_and_tree("br") - revid1 = wt.commit("acommit") - cl_contents = ("package (0.1-1) unstable; urgency=low\n * foo\n" - " -- maint Tue, 04 Aug 2009 " - "10:03:10 +0100\n") - self.build_tree_contents( - [("br/debian/", ), ('br/debian/changelog', cl_contents)]) - wt.add(['debian', 'debian/changelog']) - revid2 = wt.commit("with changelog") - base_branch = BaseRecipeBranch("base_url", "{debupstream}", 0.4) - # No changelog file, so no substitution - base_branch.substitute_branch_vars(None, wt.branch, revid1) - self.assertEqual("{debupstream}", base_branch.deb_version) - base_branch.substitute_branch_vars(None, wt.branch, revid2) - self.assertEqual("0.1", base_branch.deb_version) - base_branch = BaseRecipeBranch("base_url", "{debupstream:tehname}", 0.4) - base_branch.substitute_branch_vars("tehname", wt.branch, revid2) - self.assertEqual("0.1", base_branch.deb_version) - - def test_substitute_branch_vars_debupstream_pre_0_4(self): - wt = self.make_branch_and_tree("br") - cl_contents = ("package (0.1-1) unstable; urgency=low\n * foo\n" - " -- maint Tue, 04 Aug 2009 " - "10:03:10 +0100\n") - self.build_tree_contents( - [("br/debian/", ), ('br/debian/changelog', cl_contents)]) - wt.add(['debian', 'debian/changelog']) - revid = wt.commit("with changelog") - # In recipe format < 0.4 {debupstream} gets replaced from the resulting - # tree, not from the branch vars. - base_branch = BaseRecipeBranch("base_url", "{debupstream}", 0.2) - base_branch.substitute_branch_vars(None, wt.branch, revid) - self.assertEqual("{debupstream}", base_branch.deb_version) - def test_list_branch_names(self): base_branch = BaseRecipeBranch("base_url", "1", 0.2) base_branch.merge_branch(RecipeBranch("merged", "merged_url")) @@ -1431,73 +1163,3 @@ self.assertEqual([ cmd, nest, merge_into_nested], list(base_branch.iter_all_instructions())) - - -class DebUpstreamVariableTests(TestCase): - - def write_changelog(self, version): - contents = textwrap.dedent(""" - package (%s) experimental; urgency=low - - * Initial release. (Closes: #XXXXXX) - - -- Jelmer Vernooij Thu, 19 May 2011 10:07:41 +0100 - """ % version)[1:] - return changelog.Changelog(file=contents) - - def test_empty_changelog(self): - var = DebUpstreamVariable.from_changelog(None, changelog.Changelog()) - self.assertRaises(SubstitutionUnavailable, var.get) - - def test_version(self): - var = DebUpstreamVariable.from_changelog(None, - self.write_changelog("2.3")) - self.assertEquals("2.3", var.get()) - - def test_epoch(self): - # The epoch is (currently) ignored by {debupstream}. - var = DebUpstreamVariable.from_changelog(None, - self.write_changelog("2:2.3")) - self.assertEquals("2.3", var.get()) - - def test_base_without_snapshot(self): - var = DebUpstreamBaseVariable.from_changelog(None, - self.write_changelog("2.4")) - self.assertEquals("2.4+", var.get()) - - def test_base_with_svn_snapshot(self): - var = DebUpstreamBaseVariable.from_changelog(None, - self.write_changelog("2.4~svn4")) - self.assertEquals("2.4~", var.get()) - - def test_base_with_bzr_snapshot(self): - var = DebUpstreamBaseVariable.from_changelog(None, - self.write_changelog("2.4+bzr343")) - self.assertEquals("2.4+", var.get()) - - -class DebVersionVariableTests(TestCase): - - def write_changelog(self, version): - contents = textwrap.dedent(""" - package (%s) experimental; urgency=low - - * Initial release. (Closes: #XXXXXX) - - -- Jelmer Vernooij Thu, 19 May 2011 10:07:41 +0100 - """ % version)[1:] - return changelog.Changelog(file=contents) - - def test_empty_changelog(self): - var = DebVersionVariable.from_changelog(None, changelog.Changelog()) - self.assertRaises(SubstitutionUnavailable, var.get) - - def test_simple(self): - var = DebVersionVariable.from_changelog( - None, self.write_changelog("2.3-1")) - self.assertEquals("2.3-1", var.get()) - - def test_epoch(self): - var = DebVersionVariable.from_changelog( - None, self.write_changelog("4:2.3-1")) - self.assertEquals("4:2.3-1", var.get())