bin/disorder-notify, dot/e16-bindings: Escape HTMLish stuff in notifications.
[profile] / bin / mdw-sbuild-server
index a1355b8..705592b 100755 (executable)
@@ -137,6 +137,7 @@ case "$#,$1" in
       ## 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
 
@@ -149,6 +150,9 @@ case "$#,$1" in
     ## 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"
     ;;
@@ -171,11 +175,27 @@ case "$#,$1" in
     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
@@ -194,12 +214,12 @@ case "$#,$1" 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
 
@@ -229,29 +249,57 @@ case "$#,$1" in
       nil) firstopt="$firstopt --debbuildopt=-A" ;;
     esac
 
+    ## 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
+
     ## 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
+sbuild-wrap = \\
+       t=\$@; \\
+       host=\$\${t\#\#*/} full=\$\${t%/*}; \\
+       suite=\$\${full%%-*} target=\$\${full\#*-}; \\
+       { echo started >build-status.\$\$full; \\
+         sbuild \\
+               --extra-package=pkgs.\$\$target/ \\
+               --dist=\$\$suite --build=\$\$host --host=\$\$target \\
+               --chroot=\$\$suite-\$\$host --verbose \$1 \$(DSC); \\
+         rc=\$\$?; case \$\$rc in \\
+           0) echo ok >build-status.\$\$full ;; \\
+           *) echo failed rc=\$\$rc >build-status.\$\$full ;; \\
+         esac; } | \\
+       while IFS= read -r line; do \\
+         printf "%s: %s\n" "\$\$full" "\$\$line"; \\
+       done; \\
+       read st _ <build-status.\$\$full && \\
+       case \$\$st in ok) exit 0 ;; *) exit 1 ;; esac
 all: \$(FIRST) \$(REST)
-\$(FIRST):; \$(SBUILD) $firstopt \$(DSC) | \$(TAGLINES)
-\$(REST):; \$(SBUILD) --no-arch-all \$(DSC) | \$(TAGLINES)
+\$(FIRST):; \$(call sbuild-wrap,$firstopt)
+\$(REST):; \$(call sbuild-wrap,--no-arch-all)
 EOF
 
+    ## Make some marker files to say things are in progress.
+    for i in $first $rest; do echo "starting" >build-status.${i%/*}; 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
+    rm build.mk pipeout build-status.*
     find . -maxdepth 1 -type l -exec rm {} \;
     exit $rc
     ;;