done
: ${buildroot=$HOME/build}
: ${default_targets="wheezy-amd64 wheezy-i386"}
-: ${parallel=-j3}
: ${DEB_BUILD_OPTIONS=parallel=4}; export DEB_BUILD_OPTIONS
###--------------------------------------------------------------------------
prog=${0##*/}
fail () { echo >&2 "$prog: $*"; exit 1; }
-usage () { echo "usage: $prog [-ain] [-t TARGET] COMMAND [ARGUMENTS ...]"; }
+usage () { echo "usage: $prog [-aiknT] [-t TARGET] [-A DBPARGS] COMMAND [ARGUMENTS ...]"; }
fail_usage () { usage >&2; exit 1; }
want_1 () {
echo "$1"
}
+run () {
+ case $notreally in
+ t) echo "+ $*" ;;
+ nil) nice "$@" ;;
+ esac
+}
+
+decor () {
+ tag=$1 marker=$2
+ while IFS= read -r line; do
+ printf "%-21s %c %s\n" "$tag" "$marker" "$line"
+ done
+}
+
###--------------------------------------------------------------------------
### Parse options.
-bogusp=nil archp=nil indepp=nil makeopts=""
-unset targets
+bogusp=nil archp=nil indepp=nil keepon=nil notreally=nil
+unset targets dbpargs
-while getopts "haint:" opt; do
+while getopts "haint:A:T" opt; do
case $opt in
h)
usage
-h Show this help text.
-a Build only architecture-dependent packages.
-i Build only architecture-neutral packages.
+ -k Keep going even if one fails.
-n Don't actually do the build.
-t TARGET Build in TARGET build environment.
+ -A ARGS Pass ARGS to \`dpkg-buildpackage'.
+ -T Don't run the tests.
Commands available:
;;
a) archp=t ;;
i) indepp=t ;;
- n) makeopts="${makeopts+$makeopts }-n" ;;
+ k) keepon=t ;;
+ n) notreally=t ;;
t) targets="${targets+$targets }$OPTARG" ;;
+ A) dbpargs="${dbpargs+$dbpargs }$OPTARG" ;;
+ T)
+ case " $DEB_BUILD_OPTIONS " in
+ *" nocheck "*) ;;
+ *) DEB_BUILD_OPTIONS=${DEB_BUILD_OPTIONS+"$DEB_BUILD_OPTIONS "} nocheck ;;
+ esac
+ ;;
*) bogusp=nil ;;
esac
done
## racing with another process, but that's why we're trying in a loop.
if mkdir "$ver#$nn" >/dev/null 2>&1; then
winp=t
+ cd "$ver#$nn"
break
fi
## Make sure we actually succeeded.
case $winp in t) ;; *) fail "failed to create build directory" ;; esac
+ ## Make an empty directory for dependency packages.
+ mkdir -p pkgs/
+
## Done.
echo "$buildroot/$dist#$nn"
;;
unset first rest; anyp=nil depp=nil allp=nil
wantarchs=$(sed -n '/^[Aa]rchitecture:/ s/^[^:]*: *//p' "$dsc")
: ${wantarchs:=any}
+ unset buildarchs buildarchs_seen=:
## Work through the available targets assigning builds to them. This is
## actually a little tricky.
for t in $targets; do
+ ## Dissect the target name.
+ suite=${t%%-*} archs=${t#*-}
+ case $archs in
+ */*) target=${archs%/*} host=${archs#*/} ;;
+ *) target=$archs host=$archs; t=$suite-$target/$host ;;
+ esac
+ case $buildarchs_seen in
+ *:$target:*)
+ ;;
+ *)
+ buildarchs=${buildarchs+$buildarchs }$target
+ buildarchs_seen=$buildarchs_seen$target:
+ ;;
+ esac
+
## Work through the architectures which we can build.
for arch in $wantarchs; do
case $arch in
*)
## There's at least one architecture-specific package.
- ## If we don't want to build architecture-specific package then
+ ## If we don't want to build architecture-specific packages then
## there's nothing to do.
case $archp in nil) continue ;; esac
## If we can't build it then we shouldn't try.
- if ! dpkg-architecture -a"$os-${t#*-}" -i"$arch"; then
+ if ! dpkg-architecture -a"$os-$target" -i"$arch"; then
continue
fi
esac
case $archp in
t) ;;
- nil) firstopt="$firstopt --debbuildopt=-A" ;;
+ nil) firstopt="$firstopt --no-arch-any" ;;
esac
- ## Build a cheesy makefile to run these in parallel.
- cat >build.mk <<EOF
-### -*-makefile-*-
-DSC = $dsc
-FIRST = $first
-REST = $rest
-SBUILD = t=\$@; sbuild \\
- --dist=\$\${t%-*} --arch=\$\${t\#*-} \\
- --chroot=\$@ --verbose
-TAGLINES = \\
- while IFS= read -r line; do printf "%s: %s\n" "\$@" "\$\$line"; done
-all: \$(FIRST) \$(REST)
-\$(FIRST):; \$(SBUILD) $firstopt \$(DSC) | \$(TAGLINES)
-\$(REST):; \$(SBUILD) --no-arch-all \$(DSC) | \$(TAGLINES)
-EOF
+ ## Sort out the additional packages. This is rather annoying, because
+ ## sbuild(1) does this in a really stupid way.
+ rm -rf pkgs.*
+ for a in $buildarchs; do
+ mkdir pkgs.$a
+ for f in $(dpkg-scanpackages -a$a pkgs/ |
+ sed -n '/^Filename: /s///p')
+ do
+ ln $f pkgs.$a/
+ done
+ done
- ## And we're ready to go.
- mkfifo pipeout
- cat pipeout& catpid=$!
- set +e; make -fbuild.mk $parallel $makeopts -k all >pipeout
- rc=$?; set -e
- wait $!
- rm build.mk pipeout
- find . -maxdepth 1 -type l -exec rm {} \;
+ ## Build the builds sequentially. Tests can conflict with each other,
+ ## e.g., over port numbers.
+ rc=0 buildopt=$firstopt
+ for t in $first $rest; do
+ host=${t##*/} full=${t%/*}
+ suite=${full%%-*} target=${full#*-}
+
+ ## And we're ready to go.
+ exec 3>&1
+ thisrc=$(
+ { { { { set +e
+ run sbuild --extra-package=$pkgs.$target \
+ --dist=$suite --build=$host --host=$target \
+ --chroot=$suite-$host --verbose $buildopt $dsc \
+ ${dbpargs+--debbuildopts="$dbpargs"} \
+ 3>&- 4>&- 5>&-
+ echo $? >&5
+ } |
+ decor "$full" "|" >&4; } 2>&1 |
+ decor "$full" "*" >&4; } 4>&1 |
+ cat -u >&3; } 5>&1 </dev/null)
+ exec 3>&-
+ case $thisrc in 0) ;;
+ *)
+ echo failed rc=$thisrc >$stat; rc=$thisrc
+ case $keepon in nil) break ;; esac
+ ;;
+ esac
+ buildopt=--no-arch-all
+ done
exit $rc
;;
build,*)