changeset 452:bca5476beb41

Add --fork option to build-all-targets.sh (with --fork 3). Remove old forkbomb.sh.
author Rob Landley <rob@landley.net>
date Tue, 04 Nov 2008 03:57:54 -0600
parents d7fe6ae2c9e9
children 61a26b8092bf
files forkbomb.sh sources/build-all-targets.sh
diffstat 2 files changed, 37 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/forkbomb.sh	Tue Nov 04 01:40:21 2008 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-#!/bin/bash
-
-# Test script to build every target architecture, logging output.
-#  With --fork, it builds them in parallel
-#  With --nofork, it build them sequentially
-#  With --watch, it displays output from an existing parallel build
-
-function wait4background()
-{
-  # Wait for background task to finish
-  while [ $(jobs | wc -l) -ge $1 ]
-  do
-    sleep 1
-    # Without this next line, bash never notices a change in the number of jobs.
-    # Bug noticed in Ubuntu 7.04
-    jobs > /dev/null
-  done
-}
-
-# Build and package one architecture.
-
-function buildarch()
-{
-  nice -n 20 ./cross-compiler.sh $1 &&
-  nice -n 20 ./mini-native.sh $1 &&
-  nice -n 20 ./package-mini-native.sh $1
-}
-
-if [ "$1" != "--watch" ] && [ "$1" != "--stat" ]
-then
-  if [ $# -ne 0 ]
-  then
-
-     if [ ! -z "$RECORD_COMMANDS" ]
-     then
-       mkdir -p build/cmdlines-host &&
-       export WRAPPY_LOGDIR=`pwd`/build/cmdlines-host
-     fi
-
-    # The first thing we need to do is download the source, build the host
-    # tools, and extract the source packages.  This is only done once (not
-    # repeated for each architecure), so we do it up front here.  Doing this
-    # multiple times in parallel would collide, which is the main reason
-    # you can't just run build.sh several times in parallel.
-
-    (touch .kthxbye &&
-     nice -n 20 ./download.sh &&
-     # host-tools populates one directory with every command the build needs,
-     # so we can ditch the old $PATH afterwards.
-     nice -n 20 ./host-tools.sh || exit 1
-
-     # Ordinarily the build extracts packages the first time it needs them,
-     # but letting multiple builds do that in parallel can collide, so
-     # extract them all now up front.  (Adjust the path manually here so we're
-     # using the busybox tools rather than the host distro's to do the
-     # extract, just to be consistent.)
-     if [ -f `pwd`/build/host/busybox ]
-     then
-       PATH=`pwd`/build/host
-     fi
-     nice -n 20 ./download.sh --extract &&
-     rm .kthxbye) 2>&1 | tee out.txt
-
-     # Exiting from a sub-shell doesn't exit the parent shell, and because
-     # we piped the output of the subshell to tee, we can't get the exit code
-     # of the subshell.  So we use a sentinel file: if it wasn't deleted, the
-     # build went "boing" and should stop now.
-
-     rm .kthxbye 2>/dev/null && exit 1
-  fi
-
-  # Loop through each architecture and call "buildarch" as appropriate.
-
-  for i in `cd sources/targets; ls`
-  do
-
-    if [ ! -z "$RECORD_COMMANDS" ]
-    then
-      mkdir -p build/cmdlines-$i || exit 1
-      export WRAPPY_LOGDIR=`pwd`/build/cmdlines-$i
-    fi
-
-    # Build sequentially.
-
-    if [ "$1" == "--nofork" ]
-    then
-      buildarch $i 2>&1 | tee out-$i.txt || exit 1
-
-    # Build in parallel
-
-    elif [ "$1" == "--fork" ]
-    then
-      if [ -z "$2" ]
-      then
-        (buildarch $i > out-$i.txt 2>&1 &)&
-      else
-        (buildarch $i 2>&1 | tee out-$i.txt)&
-         wait4background $2
-      fi
-
-    # Didn't understand command line arguments, dump help.
-
-    else
-      echo "Usage: forkbomb.sh [--fork [N]] [--nofork] [--watch] [--stat]"
-      echo -e "\t--nofork  Build all targets one after another."
-      echo -e "\t--fork    Build N targets in parallel (omit for all, needs lots of RAM)."
-      echo -e "\t--watch   Restart monitor for --nofork."
-      echo -e "\t--stat    Grep logfiles for success/failure after build."
-      exit 1
-    fi
-  done
-fi
-
-# Show which builds did or didn't work.
-
-if [ "$1" == "--stat" ]
-then
-  echo "Success:"
-  grep -l system-image- out-*.txt
-
-  echo "Failed:"
-  (ls -1 out-*.txt; grep -l system-image- out-*.txt) | sort | uniq -u
-
-  exit 0
-fi
-
-# Show progress indicators for parallel build.
-
-if [ "$1" != "--nofork" ]
-then
-  watch -n 3 'X=; for i in out-*.txt; do /bin/echo -ne "$X"; X="\n"; grep -H === $i | tail -n 1; tail -n 1 $i; done'
-fi
--- a/sources/build-all-targets.sh	Tue Nov 04 01:40:21 2008 -0600
+++ b/sources/build-all-targets.sh	Tue Nov 04 03:57:54 2008 -0600
@@ -5,8 +5,7 @@
 # TODO:
 #
 # Wrapper must set:
-# SERVER=busybox.net
-# SERVERDIR=public_html/fwlnew
+# UPLOAD_TO=busybox.net:public_html/fwlnew
 # UNSTABLE=busybox,toybox,uClibc
 
 source sources/functions.sh
@@ -41,50 +40,69 @@
   Build script:
     Firmware Linux (http://landley.net/code/firmware) mercurial changeset $FWL_REV
 
-  Packages:
+  Base packages:
     uClibc (http://uclibc.org) $(identify_release uClibc)
     BusyBox (http://busybox.net) $(identify_release busybox)
     Linux (http://kernel.org/pub/linux/kernel) $(identify_release linux)
+
+  Toolchain packages:
     Binutils (http://www.gnu.org/software/binutils/) $(identify_release binutils)
     GCC (http://gcc.gnu.org) $(identify_release gcc-core)
     gmake (http://www.gnu.org/software/make) $(identify_release make)
+    bash (ftp://ftp.gnu.org/gnu/bash) $(identify_release bash)
+
+  Optional packages:
     Toybox (http://landley.net/code/toybox) $(identify_release toybox)
-
+    distcc (http://distcc.samba.org) $(identify_release distcc)
+    uClibc++ (http://cxx.uclibc.org) $(identify_release uClibc++)
 EOF
 }
 
 function build_this_target()
 {
-  ./cross-compiler.sh $i || return
+  ./cross-compiler.sh $1 || dienow
   [ ! -z "$SERVER" ] &&
-    scp build/cross-compiler-$i.tar.bz2 ${SERVER}:${SERVERDIR} >/dev/null &
-  ./mini-native.sh $i || return
+    scp build/cross-compiler-$1.tar.bz2 ${SERVER}:${SERVERDIR} >/dev/null &
+  ./mini-native.sh $1 || dienow
   [ ! -z "$SERVER" ] &&
-    scp build/mini-native-$i.tar.bz2 ${SERVER}:${SERVERDIR} >/dev/null &
-  ./package-mini-native.sh $i || return
+    scp build/mini-native-$1.tar.bz2 ${SERVER}:${SERVERDIR} >/dev/null &
+  ./package-mini-native.sh $1 || dienonw
   [ ! -z "$SERVER" ] &&
-    scp build/system-image-$i.tar.bz2 ${SERVER}:${SERVERDIR} >/dev/null &
+    scp build/system-image-$1.tar.bz2 ${SERVER}:${SERVERDIR} >/dev/null &
 }
 
-# Clean up old builds
+function build_log_upload()
+{
+  build_this_target $1 2>&1 | tee out-$1.txt
+  [ ! -z "$SERVER" ] && (cat out-$1 | bzip2 | ssh ${SERVER} \
+    "cat > ${SERVERDIR}/buildlog-$(echo $1 | sed 's/^out-//').bz2") &
+}
 
-hg pull -u &
+# Clean up old builds, fesh fresh packages.
+
+(hg pull -u; ./download.sh || dienow) &
 rm -rf build out-*.txt &
 wait4background 0
 
-# Fetch fresh packages, build host tools, extract packages. 
+# Build host tools, extract packages. 
 
-(./download.sh &&
- ./host-tools.sh &&
- ./download.sh --extract || dienow) | tee out.txt
+(./host-tools.sh && ./download.sh --extract || dienow) | tee out.txt
+
+SERVER="$(echo "$UPLOAD_TO" | sed 's/:.*//')"
+SERVERDIR="$(echo "$UPLOAD_TO" | sed 's/[^:]*://')"
 
 do_readme | tee build/README.txt | ( [ -z "$SERVER" ] && cat || ssh ${SERVER} "cd ${SERVERDIR}; cat > README.txt" ) &
 
 for i in $(cd sources/targets; ls);
 do
-  build_this_target 2>&1 | tee out-$i.txt
-  [ ! -z "$SERVER" ] && (cat out-$i | bzip2 | ssh ${SERVER} \
-    "cat > ${SERVERDIR}/buildlog-$(echo $i | sed 's/^out-//').bz2") &
+  if [ "$1" == "--fork" ]
+  then
+    echo Launching $i
+    (build_log_upload $i 2>&1 </dev/null | grep ===) &
+    [ ! -z "$2" ] && wait4background $[${2}-1]
+  else
+    build_log_upload $i
+  fi
 done
 
 # Wait for ssh/scp invocations to finish.