changeset 1072:94b0b4ef1157

Add native-build.sh to system-image (it takes only one argument now, the build control system image file). Make system-image.sh script processing understand an INCLUDE syntax to insert unique-port, and trim the unique-port comment to something less distracting.
author Rob Landley <rob@landley.net>
date Fri, 14 May 2010 01:28:02 -0500
parents 52a1b6c88128
children 9f62cd761498
files sources/more/native-build.sh sources/toys/dev-environment.sh sources/toys/native-build.sh sources/toys/unique-port.sh system-image.sh
diffstat 5 files changed, 109 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/sources/more/native-build.sh	Sat May 08 01:01:24 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#!/bin/bash
-
-# Launch a system image under the emulator under the control of a filesystem
-# image, with an FTP server to upload results to.
-
-# Parse arguments
-
-if [ $# -ne 3 ]
-then
-  echo "usage: $0 ARCH HDCFILE OUTPUTDIR" >&2
-  exit 1
-fi
-
-ARCH="$1"
-if [ ! -f "$2" ]
-then
-  echo "Filesystem image $2 missing" >&2
-  exit 1
-fi
-HDCFILE="$(readlink -f $2)"
-mkdir -p "$3" || dienow
-STAGE_DIR="$(readlink -f $3)"
-
-TOP="$(pwd)"
-
-# If running from the source directory, add build/host and cross compiler
-# to the path.
-
-[ -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
-
-  # 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.
-
-echo === Begin native build for $ARCH
-
-rm -f build/system-image-"$ARCH"/hdb.img
-HDC="$HDCFILE" KERNEL_EXTRA="OUTPORT=$FTP_PORT" \
-   $DO_TIMEOUT ./run-from-build.sh "$ARCH"
-
-echo === End native build for $ARCH
--- a/sources/toys/dev-environment.sh	Sat May 08 01:01:24 2010 -0500
+++ b/sources/toys/dev-environment.sh	Fri May 14 01:28:02 2010 -0500
@@ -1,7 +1,7 @@
+#!/bin/bash
 
-# Set up distcc acceleration
-
-source ./run-emulator.sh --norun || exit 1
+# Wrapper around run-environment.sh that sets up writeable space for /home
+# and distcc acceleration (if the cross compiler and distcc are available).
 
 # The following environment variables affect the behavior of this script:
 
@@ -13,6 +13,10 @@
 # Also, to use the distcc accelerator you need to have distccd and $ARCH-cc
 # in the $PATH.
 
+INCLUDE unique-port.sh
+
+source ./run-emulator.sh --norun || exit 1
+
 [ -z "$QEMU_MEMORY" ] && QEMU_MEMORY=256
 QEMU_EXTRA="-m $QEMU_MEMORY $QEMU_EXTRA"
 
@@ -43,19 +47,21 @@
 # Setup distcc
 
 # If the cross compiler isn't in the $PATH, look for it in the current
-# directory and the user's home directory.
+# directory, the parent directory, and the user's home directory.
 
 DISTCC_PATH="$(which $ARCH-cc 2>/dev/null | sed 's@\(.*\)/.*@\1@')"
 
 if [ -z "$DISTCC_PATH" ]
 then
-  for i in {"$(pwd)","$HOME"/}{,simple-}cross-compiler-"$ARCH"/bin
+  for i in {"$(pwd)/","$(pwd)/../","$HOME"/}{,simple-}cross-compiler-"$ARCH"/bin
   do
-    [ -f "$i/$ARCH-cc" ] && DISTCC_PATH="$i"
-    break
+    [ -f "$i/$ARCH-cc" ] && DISTCC_PATH="$i" && break
   done
 fi
 
+[ -z "$(which distccd)" ] && [ -e ../host/distccd ] &&
+  PATH="$PATH:$(pwd)/../host"
+
 CPUS=1
 if [ -z "$(which distccd)" ]
 then
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/toys/native-build.sh	Fri May 14 01:28:02 2010 -0500
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Launch a system image in the emulator with a control image to drive an
+# automated native build, plus an FTP server on the host to upload results to.
+
+# If you already have an FTP server, export FTP_SERVER and/or FTP_PORT.
+
+# Parse arguments
+
+if [ $# -ne 1 ]
+then
+  echo "usage: $0 CONTROL_IMAGE" >&2
+  exit 1
+fi
+
+if [ ! -f "$1" ]
+then
+  echo "Filesystem image $1 missing" >&2
+  exit 1
+fi
+HDCFILE="$(readlink -f $1)"
+
+TOP="$(pwd)"
+
+# If we're running from the build directory, add build/host and cross compiler
+# to the path.
+
+[ -d ../host ] &&
+  PATH="$TOP/../host:$TOP/../cross-compiler-$1/bin:$TOP/../simple-cross-compiler-$1/bin:$PATH"
+
+INCLUDE unique-port.sh
+
+# Do we already have an FTP daemon?
+
+if [ -z "$FTP_SERVER" ]
+then
+  FTP_SERVER=127.0.0.1
+elif [ -z "$FTP_PORT" ]
+then
+  FTP_PORT=21
+fi
+
+if [ -z "$FTP_PORT" ]
+then
+  if [ -z "$(which busybox)" ]
+  then
+    echo "Warning: can't find busybox, no ftp daemon launched." >&2
+  else
+    FTP_PORT=$(unique_port)
+
+    echo === launching FTP daemon on port "$FTP_PORT"
+
+    # 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.)
+
+    mkdir -p upload
+    # Replace toybox with busybox when busybox grows -L support.
+    busybox nc -s 127.0.0.1 -p $FTP_PORT -lle busybox ftpd -w upload &
+    trap "kill $(jobs -p)" EXIT
+    disown $(jobs -p)
+
+    # QEMU's alias for host loopback
+
+    FTP_SERVER=10.0.2.2
+  fi
+fi
+
+# Run emulator as a child process, feeding in -hdc and some extra environment
+# variables so it auto-launches the build process.
+
+rm -f hdb.img
+HDC="$HDCFILE" KERNEL_EXTRA="FTP_SERVER=$FTP_SERVER FTP_PORT=$FTP_PORT" \
+  ./dev-environment.sh
+
+echo === End native build
--- a/sources/toys/unique-port.sh	Sat May 08 01:01:24 2010 -0500
+++ b/sources/toys/unique-port.sh	Fri May 14 01:28:02 2010 -0500
@@ -1,15 +1,6 @@
-#!/bin/bash
-
 unique_port()
 {
-  # Try to find a unique port number for each running instance of the program.
-
-  # To reduce the chance of the port already being in use by another program,
-  # we use a range either before or after that used by normal programs, but
-  # beyond that allocated to most persistent demons.  There's a small chance
-  # even these ports are already in use, but this at least prevents
-  # simultaneous run-emulator instances for different targets from
-  # trivially interfering with each other.
+  # Try to find an unused port number for each running instance of the program.
 
   START=8192
   RANGE=$[$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range)-$START]
--- a/system-image.sh	Sat May 08 01:01:24 2010 -0500
+++ b/system-image.sh	Fri May 14 01:28:02 2010 -0500
@@ -197,8 +197,25 @@
 EOF
 chmod +x "$STAGE_DIR/run-emulator.sh" &&
 
-cat "$SOURCES"/toys/{unique-port,dev-environment}.sh > "$STAGE_DIR/dev-environment.sh" &&
-chmod +x "$STAGE_DIR/dev-environment.sh" || dienow
+# Write out development wrapper scripts, substituting INCLUDE lines.
+
+for FILE in dev-environment.sh native-build.sh
+do
+  (export IFS="$(echo -e "\n")"
+   cat "$SOURCES/toys/$FILE" | while read -r i
+   do
+     if [ "${i:0:8}" == "INCLUDE " ]
+     then
+       cat "$SOURCES/toys/${i:8}" || dienow
+     else
+       # because echo doesn't support --, that's why.
+       echo "$i" || dienow
+     fi
+   done
+  ) > "$STAGE_DIR/$FILE"
+
+  chmod +x "$STAGE_DIR/$FILE" || dienow
+done
 
 # Tar it up.