changeset 1043:d62c5c8734b2

Reduce native-build.sh reliance on run-from-build.sh.
author Rob Landley <rob@landley.net>
date Sat, 01 May 2010 00:56:44 -0500
parents 0852a69b0d65
children c1556be739ba
files sources/more/buildall.sh sources/more/native-build.sh sources/more/timeout.sh sources/timeout.sh
diffstat 4 files changed, 49 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/sources/more/buildall.sh	Fri Apr 30 09:07:36 2010 -0500
+++ b/sources/more/buildall.sh	Sat May 01 00:56:44 2010 -0500
@@ -72,7 +72,7 @@
 mkdir -p build/native-static &&
 for i in ${ARCHES}
 do
-  maybe_fork "sources/more/native-build.sh $i build/host-temp/hdc.sqf build/native-static 60 | tee build/logs/native-$i.txt | maybe_quiet"
+  maybe_fork "sources/more/timeout 60 sources/more/native-build.sh $i build/host-temp/hdc.sqf build/native-static | tee build/logs/native-$i.txt | maybe_quiet"
 done
 
 wait
--- a/sources/more/native-build.sh	Fri Apr 30 09:07:36 2010 -0500
+++ b/sources/more/native-build.sh	Sat May 01 00:56:44 2010 -0500
@@ -1,18 +1,13 @@
 #!/bin/bash
 
-# setup hdc.sqf
-# find build -name "hdb.img" | xargs rm
-
 # Launch a system image under the emulator under the control of a filesystem
 # image, with an FTP server to upload results to.
 
-. sources/functions.sh || exit 1
-
 # Parse arguments
 
-if [ $# -lt 3 ]
+if [ $# -ne 3 ]
 then
-  echo "usage: $0 ARCH HDCFILE OUTPUTDIR [TIMEOUT_SECONDS]" >&2
+  echo "usage: $0 ARCH HDCFILE OUTPUTDIR" >&2
   exit 1
 fi
 
@@ -26,15 +21,33 @@
 mkdir -p "$3" || dienow
 STAGE_DIR="$(readlink -f $3)"
 
-[ ! -z "$4" ] && DO_TIMEOUT="sources/timeout.sh $4"
+TOP="$(pwd)"
+
+# If running from the source directory, add build/host and cross compiler
+# to the path.
 
-# Fire off the ftp daemon, making sure it's killed when this script exits
+[ -d build/host ] &&
+  PATH="$TOP/build/host:$TOP/build/cross-compiler-$1/bin:$TOP/build/simple-cross-compiler-$1/bin:$PATH"
+
+if [ -z "$(which busybox)" ]
+then
+  echo "Warning: can't find busybox, no ftp daemon launched." >&2
+else
 
-. sources/toys/unique-port.sh || exit 1
-PORT=$(unique_port)
-build/host/netcat -s 127.0.0.1 -p $PORT -L build/host/ftpd -w "$STAGE_DIR" &
-trap "kill $(jobs -p)" EXIT
-disown $(jobs -p)
+  # Fire off an ftp daemon, making sure it's killed when this script exits.
+  # (We use the busybox version because no two ftp daemons have quite the same
+  # command line arguments, and this one's a known quantity.)
+
+  . sources/toys/unique-port.sh 2>/dev/null &&
+    FTP_PORT=$(unique_port) ||
+    FTP_PORT=12345+$$
+
+  # Replace toybox with busybox once -L is supported.
+
+  toybox nc -s 127.0.0.1 -p $FTP_PORT -L busybox ftpd -w "$STAGE_DIR" &
+  trap "kill $(jobs -p)" EXIT
+  disown $(jobs -p)
+fi
 
 # Run emulator as a child process, feeding in -hdc and some extra environment
 # variables so it auto-launches the build process.
@@ -42,7 +55,7 @@
 echo === Begin native build for $ARCH
 
 rm -f sources/system-image-"$ARCH"/hdb.img
-HDC="$HDCFILE" KERNEL_EXTRA="OUTPORT=$PORT ARCH=$ARCH" \
+HDC="$HDCFILE" KERNEL_EXTRA="OUTPORT=$FTP_PORT ARCH=$ARCH" \
    $DO_TIMEOUT ./run-from-build.sh "$ARCH"
 
 echo === End native build for $ARCH
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/more/timeout.sh	Sat May 01 00:56:44 2010 -0500
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Run a command line with a hang timeout, which kills the child process if it
+# doesn't produce a new line of output for $1 seconds.
+
+# This script has to be a separate process (rather than just a shell function)
+# so killing it doesn't kill the parent process.
+
+source sources/functions.sh
+
+if [ $# -lt 1 ]
+then
+  echo "Usage: timeout.sh SECONDS COMMANDS..." >&2
+  exit 1
+fi
+
+trap "killtree $$" EXIT
+TIMEOUT="$1"
+shift
+( "$@" ) | tee >(while read -t "$TIMEOUT" -n 32 i; do true; done; sleep 1; kill -TERM $$ 2>/dev/null )
--- a/sources/timeout.sh	Fri Apr 30 09:07:36 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-# Run a command line with a hang timeout, which kills the child process if it
-# doesn't produce a new line of output for $1 seconds.
-
-# This script has to be a separate process (rather than just a shell function)
-# so killing it doesn't kill the parent process.
-
-source sources/functions.sh
-
-if [ $# -lt 1 ]
-then
-  echo "Need timeout value" >&2
-  exit 1
-fi
-
-trap "killtree $$" EXIT
-TIMEOUT="$1"
-shift
-( "$@" ) | tee >(while read -t "$TIMEOUT" -n 32 i; do true; done; sleep 1; kill -TERM $$ 2>/dev/null )