Package: qemubuilder
Version: 0.5.10
Severity: wishlist
Tags: patch

I'd like to propose the following patch, which adds qemubuilder support
to git-pbuilder. With the patch applied, using qemubuilder instead of
cowbuilder is as simple as creating a symlink to git-pbuilder. For
example:

  git-qemubuilder -> git-pbuilder
  git-qemubuilder-lenny -> git-pbuilder
  git-qemubuilder-lenny-armel -> git-pbuilder

The first one selects qemubuilder as the builder, and uses the default
distribution and architecture (sid and armel). The last form specifies
everything explicitly.

If this patch is considered for inclusion, the following further changes
should be considered:

 * Make git-buildpackage Suggest qemubuilder;
 * Create a default git-qemubuilder symlink during installation;
 * Properly document the new feature of git-pbuilder (I'll do it, but I
   don't want to do the work before I know the patch as any chance of
   being accepted).

I've tested the patch by calling git-pbuilder, git-qemubuilder,
git-qemubuilder-sid and git-qemubuilder-sid-armel from git-buildpackage,
and they all worked as expected.

This patch is also available in my git repository (commit adaaaa36):
git://gitorious.org/debian-pkg/git-buildpackage.git

-- 
Benoît Knecht
diff --git a/git-pbuilder b/git-pbuilder
index 50443c7..9bcacd4 100755
--- a/git-pbuilder
+++ b/git-pbuilder
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # $Id: git-pbuilder,v 1.16 2010-09-01 21:30:33 eagle Exp $
 #
 # git-pbuilder -- Wrapper around pbuilder for git-buildpackage
@@ -23,25 +23,103 @@
 
 set -e
 
-# The root directory where different cowbuilder --basepath directories are
-# found.  git-pbuilder expects them to be named base-<dist>.cow.
-COWBUILDER_BASE=/var/cache/pbuilder
+BASENAME=${0##*git-}
 
-# Make sure we have the necessary tools
-if [ ! -x /usr/sbin/cowbuilder ]; then
-    echo "Cowbuilder not found; you need to install the cowbuilder package" >&2
-    exit 1
+# Set BUILDER, DIST and ARCH based on the name we were invoked as. This allows
+# people to create symlinks like git-pbuilder-lenny-i386 pointing to
+# git-pbuilder and auto-detecting the builder, distribution and architecture
+# from that. DIST and ARCH can also be set with environment variables, but the
+# values extracted from the executable name take precedence.
+IFS="-" read BUILDER dist arch <<< "$BASENAME"
+
+if [ -n "$dist" ]; then
+    DIST=$dist
 fi
 
-# Set DIST based on the name we were invoked as.  This allows people to create
-# symlinks like git-pbuilder-lenny pointing to git-pbuilder and auto-detecting
-# the distribution from that.
-if [ -z "$DIST" ] ; then
-    DIST=${0#*git-pbuilder-}
-    case $DIST in
-    *git-pbuilder*) DIST= ;;
-    esac
+if [ -n "$arch" ]; then
+    ARCH=$arch
 fi
+
+case $BUILDER in
+    pbuilder|cowbuilder)
+        BUILDER=cowbuilder
+
+        # Make sure we have the necessary tools
+        if [ ! -x /usr/sbin/$BUILDER ]; then
+            echo "${BUILDER^} not found; you need to install the $BUILDER package" >&2
+            exit 1
+        fi
+
+        # The root directory where different cowbuilder --basepath directories
+        # are found. git-pbuilder expects them to be named base-<dist>.cow.
+        COWBUILDER_BASE=/var/cache/pbuilder
+
+        # If DIST is set, use base-$DIST.cow.  If DIST is not set, the sid chroot may
+        # be either base.cow or base-sid.cow.  Try both.  If ARCH is set, use
+        # base-$DIST-$ARCH.cow.
+        OPTIONS=
+        if [ -z "$DIST" ] ; then
+            DIST=sid
+        fi
+        if [ -n "$ARCH" ] ; then
+            BASE="$COWBUILDER_BASE/base-$DIST-$ARCH.cow"
+            OPTIONS="--architecture $ARCH"
+        elif [ "$DIST" = 'sid' ] ; then
+            if [ -d "$COWBUILDER_BASE/base-sid.cow" ] ; then
+                BASE="$COWBUILDER_BASE/base-sid.cow"
+            else
+                BASE="$COWBUILDER_BASE/base.cow"
+            fi
+        else
+            BASE="$COWBUILDER_BASE/base-$DIST.cow"
+        fi
+
+        # Make sure the base directory exists.
+        if [ ! -d "$BASE" ] && [ "$1" != "create" ]; then
+            echo "Base directory $BASE does not exist" >&2
+            exit 1
+        fi
+
+        # Set --debian-etch-workaround if DIST is etch.  Assume that everything else
+        # is new enough that it will be fine.
+        if [ "$DIST" = 'etch' ] || [ "$DIST" = 'ebo' ] ; then
+            OPTIONS="$OPTIONS --debian-etch-workaround"
+        fi
+
+        OPTIONS="$OPTIONS --basepath $BASE"
+        ;;
+
+    qemubuilder)
+        # Make sure we have the necessary tools
+        if [ ! -x /usr/sbin/$BUILDER ]; then
+            echo "${BUILDER^} not found; you need to install the $BUILDER package" >&2
+            exit 1
+        fi
+
+        OPTIONS=
+
+        # Assign default values
+        if [ -z $DIST ]; then
+            DIST="sid"
+        fi
+        if [ -z $ARCH ]; then
+            ARCH="armel"
+        fi
+
+        QEMUBUILDER_CONFIG="/var/cache/pbuilder/qemubuilder-$ARCH-$DIST.conf"
+        if [ ! -r "$QEMUBUILDER_CONFIG" ]; then
+            echo "Cannot read configuration file: $QEMUBUILDER_CONFIG" >&2
+            exit 1
+        fi
+
+        OPTIONS="$OPTIONS --config $QEMUBUILDER_CONFIG"
+        ;;
+    *)
+        echo "Error: Unhandled builder: $BUILDER" >&2
+        exit 1
+        ;;
+esac
+
 if [ -n "$DIST" ] ; then
     if [ -n "$ARCH" ] ; then
         echo "Building for distribution $DIST, architecture $ARCH"
@@ -50,37 +128,6 @@ if [ -n "$DIST" ] ; then
     fi
 fi
 
-# If DIST is set, use base-$DIST.cow.  If DIST is not set, the sid chroot may
-# be either base.cow or base-sid.cow.  Try both.  If ARCH is set, use
-# base-$DIST-$ARCH.cow.
-OPTIONS=
-if [ -z "$DIST" ] ; then
-    DIST=sid
-fi
-if [ -n "$ARCH" ] ; then
-    BASE="$COWBUILDER_BASE/base-$DIST-$ARCH.cow"
-    OPTIONS="--architecture $ARCH"
-elif [ "$DIST" = 'sid' ] ; then
-    if [ -d "$COWBUILDER_BASE/base-sid.cow" ] ; then
-        BASE="$COWBUILDER_BASE/base-sid.cow"
-    else
-        BASE="$COWBUILDER_BASE/base.cow"
-    fi
-else
-    BASE="$COWBUILDER_BASE/base-$DIST.cow"
-fi
-
-# Make sure the base directory exists.
-if [ ! -d "$BASE" ] && [ "$1" != "create" ]; then
-    echo "Base directory $BASE does not exist" >&2
-    exit 1
-fi
-
-# Set --debian-etch-workaround if DIST is etch.  Assume that everything else
-# is new enough that it will be fine.
-if [ "$DIST" = 'etch' ] || [ "$DIST" = 'ebo' ] ; then
-    OPTIONS="$OPTIONS --debian-etch-workaround"
-fi
 
 # If the first argument to the script is update, create, or login, run
 # cowbuilder with the corresponding option under sudo rather than proceeding.
@@ -88,7 +135,7 @@ case $1 in
 update|create|login)
     action="$1"
     shift
-    sudo cowbuilder --"$action" --basepath "$BASE" --dist "$DIST" $OPTIONS "$@"
+    sudo $BUILDER --"$action" --dist "$DIST" $OPTIONS "$@"
     exit $?
     ;;
 *)
@@ -100,9 +147,9 @@ esac
 
 # Now we can finally run pdebuild.  The quoting here is tricky, but this
 # seems to pass everything through properly.
-pdebuild --buildresult .. --pbuilder cowbuilder \
+pdebuild --buildresult .. --pbuilder $BUILDER \
     --debbuildopts "-i'(?:^|/)\\.git(attributes)?(?:\$|/.*\$)' -I.git $*" \
-    -- --basepath "$BASE" $OPTIONS
+    -- $OPTIONS
 if [ -n "`ls ../*_source.changes`" ] ; then
     rm ../*_source.changes
 fi

Reply via email to