[Pbuilder-maint] Cross-compile support and pre-build functionality patch

Eugene Bordenkircher eugebo at gmail.com
Sat Apr 28 16:14:21 UTC 2007


Hello all,

Below you will find a patch created by myself and Ryan Bradetich for
proposal/evaluation/submission.  The patch adds 2 new features and one small
proposed fix to pbuilder-0.155

1) Cross-compiling support:
         An arch parameter has been added to pbuilder (pbuilder-checkparams
and pbuilder-satisfydepends) to allow a user to specify the architecture a
package is being built for.  The arch parameter is used in
pbuilder-satisfydepends to allow the installation of the correct
build-dependencies for cross-compiling.  Specifically, the packages that
have been dpkg-cross'ed.  The dependencies are now checked in the following
order:  cross->normal->provides  This change does not determine if a package
'should' be dpkg-cross'ed to work, just for the existance of it.  We allow
the package to fail during build if the appropriate packages were not
dpkg-cross'ed.
         We have been very successful using this as a method to get pbuilder
to cross-compile for our powerpc target.  Now if only the packages
themselves would work as nicely during cross-compile ^_^

2) Pre-build command execution:
         This is a small feature addition.  The feature allows any command
to be run immediately before dpkg-buildpackage.  This allows slightly
different functionality from a hook.  In our particular case, it allows the
use of tools such as Rational Clearaudit which is a shell that records
file-access during the session, for metric purposes.  However, we feel the
command may be used more generically.  Just yesterday we found that this
provides us a way to use pbuilder to generate gcc cross-compilers directly
from the source packages.  Normally one would have to unpack the sources and
set the debian/target file to the appropriate architecture and then build.
With this patch we can execute "export GCC_TARGET; debian/rules control;"
from pbuilder parameters and not have to mess with the debian/target file.
         The appropriate lines are in pbuilder-buildpackage and
pbuilder-checkparams.  One note would be that we left the ';' out after the
$PRE_BUILDPKG variables in pbuilder-buildpackage intentionally.  Users can
still add the ';' in the parameter, however this implementation allows the
dpkg-buildpackage lines to be passed as arguments to the user specified
command. (namely, our audit shell)

3) LOGNAME warnings:
         Our proposed solution is the addition of "export
LOGNAME=$BUILDUSERNAME;" to the 3 lines in pbuilder-buildpackage, seen
below.  BUILDUSERNAME appears to always be set to either root or the build
user, so it appears to be a safe command.  This eliminates all the warnings
that LOGNAME is not set.

The whole patch set has been in use by us for several weeks for use in
building packages for i386 and powerpc.  If you have any points of
discussion or questions, I would be happy to field them.

Have a day,

Eugene T. Bordenkircher

pbuilder_arch_prebuild.patch
--------------------

diff -Naur pbuilder-0.155ubuntu3.orig/pbuilder-buildpackage
pbuilder-0.155ubuntu3/pbuilder-buildpackage
--- pbuilder-0.155ubuntu3.orig/pbuilder-buildpackage    2006-06-17 03:28:
03.000000000 -0700
+++ pbuilder-0.155ubuntu3/pbuilder-buildpackage    2007-04-23 11:27:
34.000000000 -0700
@@ -106,7 +106,7 @@
     echo "pbuilder: Failed chowning to $BUILDUSERNAME:$BUILDUSERNAME" >&2
     exit 1;
 fi
-if echo "( cd tmp/buildd; /usr/bin/dpkg-source -x $(basename $PACKAGENAME)
)" | $CHROOTEXEC $SUTOUSER ; then
+if echo "( export LOGNAME=$BUILDUSERNAME; cd tmp/buildd;
/usr/bin/dpkg-source -x $(basename $PACKAGENAME) )" | $CHROOTEXEC $SUTOUSER
; then
     : # success
 else
     echo "pbuilder: Failed extracting the source" >&2
@@ -118,9 +118,9 @@
 executehooks "A"

 if [ -z "$DEBEMAIL" ]; then
-    DPKG_COMMANDLINE="cd tmp/buildd/*/; dpkg-buildpackage -us -uc
$DEBBUILDOPTS"
+    DPKG_COMMANDLINE="export LOGNAME=$BUILDUSERNAME; cd tmp/buildd/*/;
$PRE_BUILDPKG dpkg-buildpackage -us -uc $DEBBUILDOPTS"
 else
-    DPKG_COMMANDLINE="cd tmp/buildd/*/; dpkg-buildpackage -us -uc
\"-m$DEBEMAIL\" $DEBBUILDOPTS"
+    DPKG_COMMANDLINE="export LOGNAME=$BUILDUSERNAME; cd tmp/buildd/*/;
$PRE_BUILDPKG dpkg-buildpackage -us -uc  \"-m$DEBEMAIL\" $DEBBUILDOPTS"
 fi

 (
diff -Naur pbuilder-0.155ubuntu3.orig/pbuilder-buildpackage-funcs
pbuilder-0.155ubuntu3/pbuilder-buildpackage-funcs
--- pbuilder-0.155ubuntu3.orig/pbuilder-buildpackage-funcs    2006-06-17
03:28:04.000000000 -0700
+++ pbuilder-0.155ubuntu3/pbuilder-buildpackage-funcs    2007-04-23 12:53:
29.000000000 -0700
@@ -37,7 +37,8 @@
     yes) BUILDOPT="--binary-arch";;
     *) ;;
     esac
-    if /usr/lib/pbuilder/pbuilder-satisfydepends --control "$1"
--internal-chrootexec "${CHROOTEXEC}" "${BUILDOPT}" ; then
+
+    if /usr/lib/pbuilder/pbuilder-satisfydepends --control "$1"
--internal-chrootexec "${CHROOTEXEC}" "${BUILDOPT}" ${ARCH:+--arch
"${ARCH}"}; then
     :
     else
     # If asked to preserve the build place, and pbuilder-satisfydepends
diff -Naur pbuilder-0.155ubuntu3.orig/pbuilder-checkparams
pbuilder-0.155ubuntu3/pbuilder-checkparams
--- pbuilder-0.155ubuntu3.orig/pbuilder-checkparams    2006-06-17 03:28:
03.000000000 -0700
+++ pbuilder-0.155ubuntu3/pbuilder-checkparams    2007-04-23 13:10:
45.000000000 -0700
@@ -32,6 +32,8 @@
 PBUILDER_BUILD_LOGFILE=
 USE_PKGNAME_LOGFILE=""
 PRESERVE_BUILDPLACE="no"
+ARCH=""
+PRE_BUILDPKG=""
 unset EXTRA_CONFIGFILE || true
 PBUILDER_DEBUGMODE=
 SAVE_AFTER_LOGIN=
@@ -189,6 +191,17 @@
         SAVE_AFTER_LOGIN=yes;
         shift;
         ;;
+        --arch)
+            # Specify the arch for Cross-Compiling.
+            ARCH="$2"
+            shift; shift;
+            ;;
+    --pre-build)
+        # Specify the command to get run immediately
+        # before dpkg-buildpackage
+        PRE_BUILDPKG="$2"
+        shift; shift;
+        ;;
     ## internal options.
     --internal-chrootexec)
         # specify custom chrootexec function -- this is internal debugging
function
diff -Naur pbuilder-0.155ubuntu3.orig/pbuilder-modules pbuilder-0.155ubuntu3
/pbuilder-modules
--- pbuilder-0.155ubuntu3.orig/pbuilder-modules    2006-06-17 03:28:
03.000000000 -0700
+++ pbuilder-0.155ubuntu3/pbuilder-modules    2007-04-23 12:49:44.000000000-0700
@@ -75,6 +75,8 @@
  --debootstrapopts [debootstrap options]
  --save-after-login/--save-after-exec
  --debootstrap [debootstrap|cdebootstrap]
+ --arch [cross-compile architecture]
+ --pre-build [command(s) to run immediately before dpkg-buildpackage]

 pdebuild-specific pbuilder-options:
  --pbuilderroot [command to obtain root privilege for pbuilder]
diff -Naur pbuilder-0.155ubuntu3.orig/pbuilder-satisfydepends
pbuilder-0.155ubuntu3/pbuilder-satisfydepends
--- pbuilder-0.155ubuntu3.orig/pbuilder-satisfydepends    2006-06-17 03:28:
02.000000000 -0700
+++ pbuilder-0.155ubuntu3/pbuilder-satisfydepends    2007-04-23 13:51:
58.000000000 -0700
@@ -86,7 +86,6 @@
 function checkbuilddep_internal () {
 # Use this function to fulfill the dependency (almost)

-    local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
     local INSTALLPKG
     local INSTALLPKGLIST
     local INSTALLPKGMULTI
@@ -125,37 +124,46 @@
           continue;
         fi
     fi
-    echo "   -> Trying ${CURRENTREALPKGNAME}"

-    if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
${CURRENTREALPKGNAME} >& /dev/null; then
-        SATISFIED="yes"
-        INSTALLPKGLIST="${INSTALLPKGLIST} ${CURRENTREALPKGNAME}"
-    else
-        echo "       -> Cannot install ${CURRENTREALPKGNAME}; apt errors
follow:"
-        if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
"${CURRENTREALPKGNAME}"; then
-        :
-        fi
-        # package could not be found. -- looking for alternative.
-        PROVIDED=""
-        checkbuilddep_provides "${CURRENTREALPKGNAME}"
-        if [ -n "$PROVIDED" ]; then
-        # something provides this package
-        echo "     -> Considering $PROVIDED to satisfy the dependency "
-        if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
${PROVIDED} >& /dev/null; then
-            SATISFIED="yes";
-            INSTALLPKGLIST="${INSTALLPKGLIST} ${PROVIDED}"
-        else
-            # show the error for diagnostic purposes
-            echo "       -> Cannot install $PROVIDED; apt errors follow:"
-            if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
${PROVIDED}; then
-            :
-            fi
+        if [ "${ARCH}" != "${HOST_ARCH}" ]; then
+            echo "   -> Trying ${CURRENTREALPKGNAME}-${ARCH}-cross"
+            if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
${CURRENTREALPKGNAME}-${ARCH}-cross >& /dev/null; then
+                SATISFIED="yes"
+                INSTALLPKGLIST="${INSTALLPKGLIST}
${CURRENTREALPKGNAME}-${ARCH}-cross"
+        break;
+            fi
+        fi
+
+        echo "   -> Trying ${CURRENTREALPKGNAME}"
+        if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
${CURRENTREALPKGNAME} >& /dev/null; then
+            SATISFIED="yes"
+            INSTALLPKGLIST="${INSTALLPKGLIST} ${CURRENTREALPKGNAME}"
+            break;
+        fi
+
+        echo "       -> Cannot install ${CURRENTREALPKGNAME}; apt errors
follow:"
+        if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
"${CURRENTREALPKGNAME}"; then
+            :
+        fi
+
+        # package could not be found. -- looking for alternative.
+        PROVIDED=""
+        checkbuilddep_provides "${CURRENTREALPKGNAME}"
+        if [ -n "$PROVIDED" ]; then
+            # something provides this package
+            echo "     -> Considering $PROVIDED to satisfy the dependency "
+            if $CHROOTEXEC /usr/bin/apt-get -s install ${INSTALLPKGLIST}
${PROVIDED} >& /dev/null; then
+                SATISFIED="yes";
+                INSTALLPKGLIST="${INSTALLPKGLIST} ${PROVIDED}"
+        break;
+            else
+                # show the error for diagnostic purposes
+                echo "       -> Cannot install $PROVIDED; apt errors
follow:"
+                if $CHROOTEXEC /usr/bin/apt-get -s install
${INSTALLPKGLIST} ${PROVIDED}; then
+                    :
         fi
-        fi
-    fi
-    if [ "$SATISFIED" = "yes" ]; then
-        break;
-    fi
+            fi
+        fi
       done;
       if [ "$SATISFIED" = "no" ]; then
       echo "E: Could not satisfy build-dependency." >&2
@@ -230,6 +238,7 @@
 Copyright 2002-2006  Junichi Uekawa <dancer at debian.org>

 --help:        give help
+--arch:        specify the architecture to build for (cross-compile)
 --control:     specify control file (debian/control, *.dsc)
 --chroot:      operate inside chroot
 --binary-all:  include binary-all
@@ -241,7 +250,8 @@
 EOF
 }

-
+ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
+HOST_ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
 DEBIAN_CONTROL=debian/control
 CHROOTEXEC=""
 BD_REGEXP="build-(depends|depends-indep)"
@@ -252,6 +262,10 @@

 while [ -n "$1" ]; do
     case "$1" in
+    --arch|-a)
+        ARCH="$2"
+        shift; shift
+        ;;
     --control|-c)
         DEBIAN_CONTROL="$2"
         shift; shift
@@ -293,5 +307,4 @@
     esac
 done

-
 checkbuilddep_internal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/pbuilder-maint/attachments/20070428/6d9475d3/attachment.htm


More information about the Pbuilder-maint mailing list