#!/bin/sh # Launch sbuild from jenkins # Input: # .dsc source package in current directory # JOB_NAME=$pkg-binaries # architecture=amd64/i386 # distribution=foo (caveat: sbuild -d foo-pgdg will be called) # DEB_PG_SUPPORTED_VERSIONS (optional, defaults to pgdg) # Output: # .changes and .deb in current directory # autopkgtest.xml in current directory # Requirements: # schroot $foo-pgdg-$arch-sbuild # gid sbuild (for sbuild as such and for /var/lock/sbuild-package) # adt-sbuild available in chroot (in pgdg-buildenv package) # /var/tmp bind mount in schroot fstab for retrieving adt-run summary # sbuild needs to pass through DEB_* variables (default) # Optional: # newpid installed in chroot # /etc/sbuild/sbuild.conf: $build_env_cmnd = 'newnet'; set -eu error () { echo "Error: $@" >&2 exit 1 } chroot="chroot:$distribution-pgdg-$architecture-sbuild" # find dsc to build PACKAGE="${JOB_NAME%%-binaries*}" set -- ${PACKAGE}_*.dsc DSC="$1" [ "${2:-}" ] && error "There is more than one \${PACKAGE}_*.dsc in $PWD" # exit early if package is arch:all only and we are not on amd64 if [ "$architecture" != "amd64" ] && egrep -q '^Architecture: all$' $DSC; then echo "Package is arch:all only and we are not on amd64" adtsummary2junit /dev/null > autopkgtest.xml exit fi # check if chroot exists schroot -l | grep -q $chroot || \ error "There is no schroot definition for $chroot" # decide if we should build arch:all packages case $architecture in amd64) BITS=64 ARCH_ALL="--arch-all" ;; # always build arch:all binaries here *) BITS=32 if egrep -q '^Testsuite: autopkgtest$' $DSC; then echo "Package has Testsuite: autopkgtest, will build arch:all binaries even on $architecture. We'll throw them away at the end." ARCH_ALL="--arch-all" FILTER_ARCH_ALL="true" fi ;; esac # resolve alternative build-dependencies on dists other than sid if [ "$distribution" != "sid" ]; then RESOLVE_ALTERNATIVES="--resolve-alternatives" fi # disable parallel builds export DEB_BUILD_OPTIONS="parallel=1" # set DEB_PG_SUPPORTED_VERSIONS : ${DEB_PG_SUPPORTED_VERSIONS:=pgdg} export DEB_PG_SUPPORTED_VERSIONS if [ "$DEB_PG_SUPPORTED_VERSIONS" != "pgdg" ]; then ADD_DEPENDS="--add-depends=postgresql-server-dev-$DEB_PG_SUPPORTED_VERSIONS --chroot-setup-commands=sbuild-pgdg-components" fi # prepare temp file for adt-run results if [ "${ADT:-}" != "skip" ]; then export DEB_ADT_SUMMARY=$(mktemp /var/tmp/$PACKAGE.XXXXXX.xml) trap "rm -f $DEB_ADT_SUMMARY" 0 2 3 15 FINISHED_BUILD_COMMAND='adt-sbuild %SBUILD_BUILD_DIR %SBUILD_PKGBUILD_DIR' fi # lock against concurrent apt-get update/upgrade operations on the source chroot LOCKDIR="/var/lock/sbuild-package" if ! test -d $LOCKDIR; then mkdir $LOCKDIR chgrp sbuild $LOCKDIR chmod 3775 $LOCKDIR fi umask 002 # build package and run autopkgtests inside the chroot ( echo "Bulding $PACKAGE (DEB_PG_SUPPORTED_VERSIONS=$DEB_PG_SUPPORTED_VERSIONS)" set -x flock --shared 9 newpid -iuN newpid$distribution$BITS \ sbuild --nolog --batch \ -d $distribution-pgdg --arch $architecture ${ARCH_ALL:-} ${RESOLVE_ALTERNATIVES:-} \ --finished-build-commands="${FINISHED_BUILD_COMMAND:-}" \ ${ADD_DEPENDS:-} $DSC ) 9> $LOCKDIR/$distribution-$architecture.lock # remove arch:all packages that were only built for autopkgtests if [ "${FILTER_ARCH_ALL:-}" ]; then sed -i -e '/_all\.deb$/d' *.changes fi # copy autopkgtest results back (already in junit format) if [ "${DEB_ADT_SUMMARY:-}" ]; then cp $DEB_ADT_SUMMARY autopkgtest.xml else adtsummary2junit /dev/null > autopkgtest.xml fi