[buildd-tools-devel] Bug#705926: sbuild: Add basic DEP-8 autopkgtest

James Hunt james.hunt at ubuntu.com
Mon Apr 22 10:04:36 UTC 2013


Package: sbuild
Version: 0.63.2-1.1
Severity: normal
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu raring ubuntu-patch


Dear Maintainer,

The attached debdiff adds a basic DEP-8 autopkgtest for sbuild. See:

- https://code.launchpad.net/~jamesodhunt/ubuntu/raring/sbuild/dep8-procenv
-
https://code.launchpad.net/~jamesodhunt/ubuntu/raring/sbuild/dep8-procenv/+merge/159596

In Ubuntu, the attached patch was generated to achieve the following:

* ability to detect if sbuilder is able to:
  - create a chroot for the current release.
  - build a package.
* check that the resulting package is installable and the binary runnable.

Thanks for considering the patch.


Kind regards,

James.
--
James Hunt
____________________________________
#upstart on freenode
http://upstart.ubuntu.com/cookbook
https://lists.ubuntu.com/mailman/listinfo/upstart-devel
-------------- next part --------------
=== modified file 'debian/changelog'

=== modified file 'debian/control'
--- debian/control	2012-06-23 22:27:58 +0000
+++ debian/control	2013-04-22 10:00:27 +0000
@@ -8,6 +8,7 @@
 Standards-Version: 3.9.1
 Vcs-Browser: http://git.debian.org/?p=buildd-tools/sbuild.git
 Vcs-Git: git://git.debian.org/git/buildd-tools/sbuild
+XS-Testsuite: autopkgtest
 
 Package: libsbuild-perl
 Architecture: all

=== added directory 'debian/tests'
=== added file 'debian/tests/build_procenv'
--- debian/tests/build_procenv	1970-01-01 00:00:00 +0000
+++ debian/tests/build_procenv	2013-04-22 10:00:05 +0000
@@ -0,0 +1,132 @@
+#!/bin/sh -e
+#---------------------------------------------------------------------
+# DEP-8 test for sbuild.
+#
+# Creates a sbuild chroot, builds a package, installs the resulting
+# .deb, then runs the command provided by the .deb.
+#---------------------------------------------------------------------
+
+die()
+{
+    msg="$*"
+    echo "ERROR: $msg" >&2
+    exit 1
+}
+
+# The package we'll ask sbuild to build (we know its buildable since
+# it's already in the archive :-)
+#
+# The advantage of choosing this particular package being that it runs
+# *itself* at the end of its build, which has the nice side-effect of
+# exposing the full sbuild environment to those perusing the autopkgtest
+# logs.
+pkg=procenv
+
+release=$(lsb_release -c|cut -d: -f2|awk '{print $1}')
+dir="$ADTTMP/schroot-$release"
+arch=$(dpkg --print-architecture)
+chroot="${release}-${arch}-sbuild"
+
+distro=$(lsb_release --id|cut -d: -f2-|awk '{print $1}'|tr '[A-Z]' '[a-z]')
+
+if [ "$distro" = ubuntu ]
+then
+    url=http://archive.ubuntu.com/ubuntu
+else
+    url=http://archive.debian.org/debian
+fi
+
+# schroot does not allow a chroot name to be specified at creation time.
+# As such, we must take care to avoid stomping on a developers chroots.
+# If we find any that match the chroot we're about to try and make, exit
+# with a message.
+#
+# Note that we are very cautious in the grep check below; we purposely
+# don't match on the _type_ of schroot in case new schroot types are
+# added and this test is not updated to take account of the new types.
+
+schroots=$(schroot -l 2>/dev/null)
+
+if [ -n "$schroots" ] && echo "$schroots"|grep -q ":${release}-${arch}"
+then
+    echo "INFO:"
+    echo "INFO: Existing schroots detected for current release ($release)"
+    echo "INFO: and architecture ($arch)"
+    echo "INFO:"
+    echo "INFO: Not continuing."
+    echo "INFO:"
+
+    # exit successfully
+    exit 0
+fi
+
+echo "INFO: Creating sbuild chroot '$chroot' for release '$release' in directory '$dir' from url '$url'"
+sbuild-createchroot "$release" "$dir" "$url"
+
+echo "INFO: Checking chroot '$chroot' is known"
+schroot --list --all-chroots|grep "^chroot:${chroot}$"
+
+echo "INFO: Displaying information about chroot '$chroot'"
+schroot --info "${chroot}"
+
+# '--download-only' to avoid unpack which generates a signature
+# warning to stderr, causing this test to fail.
+echo "INFO: Downloading source for package '$pkg'"
+apt-get source --download-only "$pkg"
+
+dsc=$(ls ${pkg}*.dsc)
+
+# crucial
+echo "INFO: Creating sbuild key pair"
+sbuild-update --keygen 2>&1
+
+echo "INFO: Building package '$pkg' for release '$release' from '$dsc'"
+sbuild -A -d "$release" $dsc 2>&1
+
+pkg_and_version=$(echo "$dsc"|sed 's/\.dsc$//g')
+deb=${pkg_and_version}_${arch}.deb
+
+echo "INFO: Displaying sbuild log"
+cat ${pkg_and_version}_${arch}*.build
+
+echo "INFO: Installing package '$pkg' from '$deb'"
+dpkg -i "$deb"
+
+# run the command to prove the build worked but also to expose the
+# auto-package-test environment used for this test.
+cmd=$pkg
+echo "INFO: Showing AutoPkgTest environment by running '$cmd' from package '$pkg'"
+"$cmd"
+
+# There is no sbuild/schroot command to actually delete the chroot, but
+# we do want to clean up fully. The best we can do is end the schroot
+# session, and remove the sym links. Removing the chroot itself is not
+# necessary since it is created below $ADTTMP so will be removed
+# automatically by the AutoPkgTest environment.
+
+echo "INFO: Establishing schroot sessions for chroot '$chroot'"
+session=$(schroot --list --all-sessions|grep "^session:${release}-${arch}-" || :)
+if [ -n "$session" ]
+then
+    count=$(echo "$session"|wc -l)
+    [ $count -eq 1 ] || die "expected 1 session, found $count"
+
+    echo "INFO: Ending schroot session '$session'"
+    schroot --end-session --chroot "$session"
+else
+    echo "INFO: No schroot session to end"
+fi
+
+echo "INFO: Cleaning up"
+
+echo "INFO: Removing sbuild chroot symbolic link for '$chroot'"
+link=$(ls /etc/sbuild/chroot/${chroot})
+# remove soon-to-be-broken symbolic link
+[ -h "$link" ] && rm "$link"
+
+# remove soon-to-be stale configuration file
+echo "INFO: Removing schroot configuration file for '$chroot'"
+config=$(ls /etc/schroot/chroot.d/${chroot}-*)
+[ -f "$config" ] && rm "$config"
+
+echo "INFO: SUCCESS"

=== added file 'debian/tests/control'
--- debian/tests/control	1970-01-01 00:00:00 +0000
+++ debian/tests/control	2013-04-18 10:50:08 +0000
@@ -0,0 +1,3 @@
+Tests: build_procenv
+Depends: @
+Restrictions: needs-root



More information about the Buildd-tools-devel mailing list