From: Guido Günther Date: Fri, 20 May 2011 18:54:43 +0000 (+0200) Subject: Add git-pbuilder 0.21 X-Git-Tag: debian/0.5.24~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09bf9f16ec1e0eaf50953f01670350f82c6e0ea9;p=tools%2Fgit-buildpackage.git Add git-pbuilder 0.21 Closes: #601045, #601298 Thanks: Russ Albery --- diff --git a/git-pbuilder b/git-pbuilder old mode 100755 new mode 100644 index b18b7a8..16d4914 --- a/git-pbuilder +++ b/git-pbuilder @@ -1,11 +1,12 @@ #!/bin/sh -# $Id: git-pbuilder,v 1.16 2010-09-01 21:30:33 eagle Exp $ +# $Id: git-pbuilder,v 1.21 2011-05-20 06:17:09 eagle Exp $ # # git-pbuilder -- Wrapper around pbuilder for git-buildpackage # # Written by Russ Allbery # Based on the example in the git-buildpackage documentation -# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University +# Copyright 2008, 2009, 2010, 2011 +# The Board of Trustees of the Leland Stanford Junior University # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, provided @@ -23,83 +24,142 @@ set -e -# The root directory where different cowbuilder --basepath directories are -# found. git-pbuilder expects them to be named base-.cow. -COWBUILDER_BASE=/var/cache/pbuilder - -# 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 -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-} +# Set BUILDER, DIST, and ARCH based on the name we were invoked as. This +# allows people to create symlinks like git-pbuilder-lenny and +# git-qemubuilder-lenny-amd64 pointing to git-pbuilder and auto-detecting the +# builder, distribution, and architecture from that. +if [ -z "$BUILDER" ] && [ -z "$DIST" ] ; then + BUILDER=${0#*git-} + DIST=${BUILDER#*-} + BUILDER=${BUILDER%%-*} + case $BUILDER in + pbuilder|cowbuilder) BUILDER=cowbuilder ;; + /*) BUILDER=cowbuilder ;; + esac + case $BUILDER in + *builder) ;; + *) BUILDER=cowbuilder ;; + esac case $DIST in - *git-pbuilder*) DIST= ;; + *builder) + DIST= + ;; + *-*) + ARCH=${DIST#*-} + DIST=${DIST%%-*} + ;; esac -fi -if [ -n "$DIST" ] ; then - if [ -n "$ARCH" ] ; then - echo "Building for distribution $DIST, architecture $ARCH" - else - echo "Building for distribution $DIST" - 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" + BUILDER=cowbuilder fi -# Make sure the base directory exists. -if [ ! -d "$BASE" ] && [ "$1" != "create" ]; then - echo "Base directory $BASE does not exist" >&2 +# 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 -# 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 +# Default options come from the environment. +OPTIONS="$GIT_PBUILDER_OPTIONS" + +# How we handle options depends on what type of builder we're using. +case $BUILDER in + cowbuilder) + # The root directory where different cowbuilder --basepath directories + # are found. git-pbuilder expects them to be named base-.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. + if [ -z "$DIST" ] ; then + DIST=sid + fi + if [ -n "$ARCH" ] ; then + BASE="$COWBUILDER_BASE/base-$DIST-$ARCH.cow" + OPTIONS="$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 + OPTIONS="$OPTIONS --basepath '$BASE'" + + # 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 + ;; + + qemubuilder) + # There always has to be an architecture for qemubuilder, and it + # doesn't make much sense to default to the current architecture. + # There's probably no good default, but this one at least makes some + # sense. + if [ -z "$DIST" ] ; then + DIST=sid + fi + if [ -z "$ARCH" ]; then + ARCH=armel + fi + + # There has to be a configuration file matching our distribution and + # architecture. + 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 "Unknown builder $BUILDER" >&2 + exit 1 + ;; +esac -# If the first argument to the script is update, create, or login, run -# cowbuilder with the corresponding option under sudo rather than proceeding. +# If the first argument to the script is update, create, or login, run the +# builder with the corresponding option under sudo rather than proceeding. case $1 in update|create|login) action="$1" shift - sudo cowbuilder --"$action" --basepath "$BASE" --dist "$DIST" $OPTIONS "$@" + sudo "$BUILDER" --"$action" --dist "$DIST" $OPTIONS "$@" exit $? ;; *) if [ -z "$GBP_BUILD_DIR" ]; then - echo "WARNING: not invoked by git-buildpackage." >&2 + echo "Warning: git-pbuilder should be run via git-buildpackage" >&2 fi ;; esac -if [ ! -f debian/source/format ] || grep -qs "^1.0" debian/source/format; then - echo "Source format 1.0 detected, adding excludes" +# Print out some information about what we're doing. +if [ -n "$ARCH" ] ; then + echo "Building with $BUILDER for distribution $DIST, architecture $ARCH" +else + echo "Building with $BUILDER for distribution $DIST" +fi + +# Source package format 1.0 doesn't automatically exclude Git files, so we +# want to add the appropriate flags to do that. But source package format 3.0 +# does exclude by default and has many other ways of controlling those +# exclusions that we don't want to tromp on. So we don't want to give any -i +# or -I flags unless we're using source format 1.0. +if [ ! -f debian/source/format ] || grep -qs '^1.0' debian/source/format ; then + echo 'Source format 1.0 detected, adding exclude flags' DEBBUILDOPTS="-i'(?:^|/)\\.git(attributes)?(?:\$|/.*\$)' -I.git $*" else DEBBUILDOPTS="$*" @@ -107,13 +167,13 @@ fi # Now we can finally run pdebuild. The quoting here is tricky, but this # seems to pass everything through properly. -pdebuild --buildresult .. --pbuilder cowbuilder \ - --debbuildopts "$DEBBUILDOPTS" \ - -- --basepath "$BASE" $OPTIONS +pdebuild --buildresult .. --pbuilder "$BUILDER" \ + --debbuildopts "$DEBBUILDOPTS" -- $OPTIONS +status="$?" if [ -n "`ls ../*_source.changes`" ] ; then rm ../*_source.changes fi -exit 0 +exit "$status" # Documentation. Use a hack to hide this from the shell. Because of the # above exit line, this should never be executed. @@ -121,22 +181,24 @@ DOCS=<<__END_OF_DOCS__ =head1 NAME -git-pbuilder - Wrapper around pbuilder for git-buildpackage +git-pbuilder - Wrapper around cowbuilder/qemubuilder for git-buildpackage =head1 SYNOPSIS -DIST=I ARCH=I B I +DIST=I ARCH=I [BUILDER=qemubuilder] \ + B I -DIST=I ARCH=I \ +DIST=I ARCH=I [BUILDER=qemubuilder] \ B (update | create | login) I =head1 DESCRIPTION B is a wrapper around B intended for use by -B. It configures B to use B, -passes appropriate options to B, and sets the base path for -B based on the environment variable DIST and, if set, the -environment variable ARCH. +B. It configures B to use B by +default, passes appropriate options to B, and sets the base path +for B based on the environment variable DIST and, if set, the +environment variable ARCH. B can be selected instead by +setting the environment variable BUILDER to C. By default, B assumes the target distribution is C, the same architecture as the B default, and uses @@ -148,15 +210,24 @@ is also passed to B. If ARCH is set, its value is the target architecture and F-I.cow> is used, with I being set to C if DIST was not set. -If B is invoked via a name that starts with -C, the part after the last hyphen is taken to be the -distribution (although the environment variable overrides this). One can -therefore create symlinks like C pointing to -B and use that name when wanting to use a distribution of -C. +If B is used as the builder, no base directory is used. +Instead, B is invoked with the B<--config> option pointing to +the file F-I.conf> + +If neither BUILDER nor DIST are set in the environment and B +is invoked via a name that starts with C, the part between the +hyphens is taken to be the name of the builder to use (with C +mapped to B.). The part after the last hyphen is taken to be +the distribution (if it contains no additional hyphen) or the distribution +followed by the architecture (if it contains a hyphen). One can therefore +create symlinks like C pointing to B and +use that name when wanting to use a distribution of C, or +C to use B to build for the +C architecture and the C distribution. Any arguments are passed as-is to B via the -B<--debbuildopts> option to B. +B<--debbuildopts> option to B. To pass arguments to the builder +instead, put them in the environment variable GIT_PBUILDER_OPTIONS. Normally, one does not run this script directly. Instead, it's used as the builder script for B. To configure @@ -167,25 +238,46 @@ B to use it, add a stanza like: in your F file (which can be F<.gbp.conf> in your home directory or at the top level of the repository, or F in the F<.git> -directory). DIST is read as an environment variable so that you can set -it before running B without having to worry about -passing parameters through B. +directory). DIST and ARCH are read as an environment variable so that you +can set it before running B without having to worry +about passing parameters through B. Alternately, B may be called with an argument of C, -C, or C. In this case, it calls B using -B and passes the corresponding command to B, using the -same logic as above to determine the base directory and distribution. Any -additional arguments to B are passed along to B. +C, or C. In this case, it calls B (or the +configured builder as described above) using B and passes the +corresponding command to the builder, using the same logic as above to +determine the base directory and distribution. Any additional arguments +to B are passed along to the builder. =head1 ENVIRONMENT =over 4 +=item ARCH + +Sets the target architecture. For a B builder, this sets both +the base path and is passed as the B<--architecture> option. For a +B, this controls the path to the configuration file. + +=item BUILDER + +Sets the builder to use. The only supported settings are C +(the default) and C. + =item DIST Sets the target distribution. This is used primarily to determine the -base path for B, but it's also used to determine whether to -pass B<--debian-etch-workaround> to B. +base path for B or the configuration file path for +B, but it's also used to determine whether to pass +B<--debian-etch-workaround> to B. + +=item GIT_PBUILDER_OPTIONS + +Add additional options for the builder. These options are passed as-is to +B or B via B. The contents of this +variable will undergo shell expansion, so any arguments containing shell +metacharacters or whitespace need to be quoted in the value of the +environment variable. =back @@ -198,18 +290,33 @@ pass B<--debian-etch-workaround> to B. =item /var/cache/pbuilder/base.cow The default C directories, searched for in that -order, if DIST is not set. +order, if neither DIST nor ARCH is set. + +=item /var/cache/pbuilder/base-sid-$ARCH.cow + +The C directory used if ARCH is set and DIST is not +set. =item /var/cache/pbuilder/base-$DIST.cow -The C directory used if DIST is set. +The C directory used if DIST is set and ARCH is +not. + +=item /var/cache/pbuilder/base-$DIST-$ARCH.cow + +The C directory used if DIST and ARCH are both set. + +=item /var/cache/pbuilder/qemubuilder-$ARCH-$DIST.conf + +The C file used. $ARCH defaults to C and +$DIST defaults to C if not set. =back =head1 SEE ALSO cowbuilder(8), dpkg-buildpackage(1), git-buildpackage(1), pdebuild(1), -sudo(8) +qemubuilder(8), sudo(8) The latest version of this script is available from L.