Mercurial > hg > aboriginal
changeset 999:4bd1bc15a744
Move distcc setup to dev-environment.sh. Fix bug where CPUS wasn't defined if distcc wasn't being used (leading to make -j with no limit, and OOM conditions in the emulated system).
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 15 Mar 2010 06:01:36 -0500 |
parents | bbcafba8a594 |
children | 6a6a9e8de6ef |
files | sources/toys/dev-environment.sh sources/toys/run-emulator.sh system-image.sh |
diffstat | 3 files changed, 130 insertions(+), 135 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/toys/dev-environment.sh Mon Mar 15 06:01:36 2010 -0500 @@ -0,0 +1,119 @@ + +# Set up distcc acceleration + +source ./run-emulator.sh --norun || exit 1 + +# The following environment variables affect the behavior of this script: + +# HDB - Image file to use for -hdb on /home (none if blank) +# HDBMEGS - Number of megabytes to create +# HDC - Image file to use for -hdc on /mnt (none of blank) +# QEMU_MEMORY - number of megabytes of memory for qemu (defaults to 128) + +# Also, to use the distcc accelerator you need to have distccd and $ARCH-cc +# in the $PATH. + +[ -z "$QEMU_MEMORY" ] && QEMU_MEMORY=256 +QEMU_EXTRA="-m $QEMU_MEMORY $QEMU_EXTRA" + +# Should we set up an ext3 image as a second virtual hard drive for /home? + +if [ "$HDBMEGS" != "0" ] +then + [ -z "$HDB" ] && HDB=hdb.img + if [ ! -e "$HDB" ] + then + + # If we don't already have an hdb image, should we set up a sparse file and + # format it ext3? + + [ -z "$HDBMEGS" ] && HDBMEGS=2048 + + # Some distros don't put /sbin:/usr/sbin in the $PATH for non-root users. + [ -z "$(which mke2fs)" ] && export PATH=/sbin:/usr/bin:$PATH + + dd if=/dev/zero of="$HDB" bs=1024 seek=$[$HDBMEGS*1024-1] count=1 && + mke2fs -q -b 1024 -F "$HDB" -i 4096 && + tune2fs -j -c 0 -i 0 "$HDB" + + [ $? -ne 0 ] && exit 1 + fi +fi + +# Setup distcc + +# If the cross compiler isn't in the $PATH, look for it in the current +# 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 + do + [ -f "$i/$ARCH-cc" ] && DISTCC_PATH="$i" + break + done +fi + +CPUS=1 +if [ -z "$(which distccd)" ] +then + echo 'No distccd in $PATH, acceleration disabled.' +elif [ -z "$DISTCC_PATH" ] +then + echo "No $ARCH-cc in "'$PATH'", acceleration disabled." +else + + # Populate a directory full of symlinks to the cross compiler using the + # unprefixed names distccd will try to use. + + mkdir -p "distcc_links" && + for i in $(cd "$DISTCC_PATH"; ls $ARCH-* | sed "s/^$ARCH-//" ) + do + ln -sf "$DISTCC_PATH/$ARCH-$i" "distcc_links/$i" + done + if [ -e "$DISTCC_PATH/$ARCH-rawgcc" ] + then + for i in cc gcc g++ c++ + do + ln -sf "$DISTCC_PATH/$ARCH-rawgcc" distcc_links/$i + done + fi + + # Run the distcc daemon on the host system with $PATH restricted to the + # cross compiler binaries. + + # Note that we tell it --no-detach and background it ourselves so jobs -p can + # find it later to kill it after the emulator exits. + + PORT=$(unique_port) + CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)*2] + PATH="$(pwd)/distcc_links" "$(which distccd)" --no-detach --daemon \ + --listen 127.0.0.1 -a 127.0.0.1 -p $PORT --jobs $CPUS \ + --log-stderr --verbose 2>distccd.log & + + # Clean up afterwards: Kill child processes we started (I.E. distccd). + trap "kill $(jobs -p)" EXIT + + # When background processes die, they should do so silently. + disown $(jobs -p) + + # Let the QEMU launch know we're using distcc. + + DISTCC_PATH_PREFIX=/usr/distcc: + KERNEL_EXTRA="DISTCC_HOSTS=10.0.2.2:$PORT/$CPUS $KERNEL_EXTRA" +fi + +KERNEL_EXTRA="CPUS=$CPUS $KERNEL_EXTRA" + +# Kill our child processes on exit. + +trap "pkill -P$$" EXIT + +# The actual emulator invocation command gets appended here by system-image.sh + +[ ! -z "$HDC" ] && QEMU_EXTRA="-hdc $HDC $KERNEL_EXTRA" +[ ! -z "$HDB" ] && QEMU_EXTRA="-hdb $HDB $KERNEL_EXTRA" + +run_emulator
--- a/sources/toys/run-emulator.sh Sun Mar 14 01:18:27 2010 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -# The ARCH gets substituted in here by system-image.sh - -ARCH= - -# The following environment variables affect the behavior of this script: - -# HDB - Image file to use for -hdb on /home (none if blank) -# HDBMEGS - Number of megabytes to create -# HDC - Image file to use for -hdc on /mnt (none of blank) -# QEMU_MEMORY - number of megabytes of memory for qemu (defaults to 128) - -# Also, to use the distcc accelerator you need to have distccd and $ARCH-cc -# in the $PATH. - -[ ! -z "$QEMU_MEMORY" ] && QEMU_EXTRA="-m $QEMU_MEMORY $QEMU_EXTRA" - -# Should we set up an ext3 image as a second virtual hard drive for /home? - -if [ ! -z "$HDB" ] -then - if [ ! -e "$HDB" ] - then - - # If we don't already have an hdb image, should we set up a sparse file and - # format it ext3? - - if [ ! -z "$HDBMEGS" ] - then - # Some distros don't put /sbin:/usr/sbin in the $PATH for non-root users. - [ -z "$(which mke2fs)" ] && export PATH=/sbin:/usr/bin:$PATH - - dd if=/dev/zero of="$HDB" bs=1024 seek=$[$HDBMEGS*1024-1] count=1 && - mke2fs -q -b 1024 -F "$HDB" -i 4096 && - tune2fs -j -c 0 -i 0 "$HDB" - - [ $? -ne 0 ] && exit 1 - fi - fi - WITH_HDB="-hdb $HDB" -fi - -[ ! -z "$HDC" ] && [ -e "$HDC" ] && WITH_HDC="-hdc $HDC" - -# Setup distcc - -# The ARCH gets substituted in here by system-image.sh - -ARCH= - -# If the cross compiler isn't in the $PATH, look for it in the current -# 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 - do - [ -f "$i/$ARCH-cc" ] && DISTCC_PATH="$i" - break - done -fi - -if [ -z "$(which distccd)" ] -then - echo 'No distccd in $PATH, acceleration disabled.' -elif [ -z "$DISTCC_PATH" ] -then - echo "No $ARCH-cc in "'$PATH'", acceleration disabled." -else - - # Populate a directory full of symlinks to the cross compiler using the - # unprefixed names distccd will try to use. - - mkdir -p "distcc_links" && - for i in $(cd "$DISTCC_PATH"; ls $ARCH-* | sed "s/^$ARCH-//" ) - do - ln -sf "$DISTCC_PATH/$ARCH-$i" "distcc_links/$i" - done - if [ -e "$DISTCC_PATH/$ARCH-rawgcc" ] - then - for i in cc gcc g++ c++ - do - ln -sf "$DISTCC_PATH/$ARCH-rawgcc" distcc_links/$i - done - fi - - # Run the distcc daemon on the host system with $PATH restricted to the - # cross compiler binaries. - - # Note that we tell it --no-detach and background it ourselves so jobs -p can - # find it later to kill it after the emulator exits. - - PORT=$(unique_port) - CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)*2] - PATH="$(pwd)/distcc_links" "$(which distccd)" --no-detach --daemon \ - --listen 127.0.0.1 -a 127.0.0.1 -p $PORT --jobs $CPUS \ - --log-stderr --verbose 2>distccd.log & - - # Clean up afterwards: Kill child processes we started (I.E. distccd). - trap "kill $(jobs -p)" EXIT - - # When background processes die, they should do so silently. - disown $(jobs -p) - - # Let the QEMU launch know we're using distcc. - - DISTCC_PATH_PREFIX=/usr/distcc: - KERNEL_EXTRA="DISTCC_HOSTS=10.0.2.2:$PORT/$CPUS CPUS=$CPUS $KERNEL_EXTRA" -fi - -# Kill our child processes on exit. - -trap "pkill -P$$" EXIT - -# The actual emulator invocation command gets appended here by system-image.sh -
--- a/system-image.sh Sun Mar 14 01:18:27 2010 -0600 +++ b/system-image.sh Mon Mar 15 06:01:36 2010 -0500 @@ -54,8 +54,10 @@ # Build kernel in parallel with initramfs -echo "make -j $CPUS ARCH=$BOOT_KARCH $DO_CROSS $LINUX_FLAGS $VERBOSITY" -( make -j $CPUS ARCH=$BOOT_KARCH $DO_CROSS $LINUX_FLAGS $VERBOSITY || dienow ) & +[ ! -e "$STAGE_DIR/zImage-$ARCH" ] && + echo "make -j $CPUS ARCH=$BOOT_KARCH $DO_CROSS $LINUX_FLAGS $VERBOSITY" && + ( make -j $CPUS ARCH=$BOOT_KARCH $DO_CROSS $LINUX_FLAGS $VERBOSITY || + dienow ) & # Embed an initramfs image in the kernel? @@ -144,8 +146,8 @@ # Install kernel -[ -d "${TOOLS}/src" ] && cp .config "${TOOLS}"/src/config-linux -cp "${KERNEL_PATH}" "${STAGE_DIR}/zImage-${ARCH}" +[ -d "$TOOLS/src" ] && cp .config "$TOOLS/src/config-linux" +cp "$KERNEL_PATH" "$STAGE_DIR/zImage-$ARCH" cleanup @@ -171,21 +173,12 @@ # filesystem, kernel, and base kernel command line arguments in case you want # to use an emulator other than qemu, but put the default case in qemu_defaults -cat > "$STAGE_DIR/dev-environment.sh" << EOF && -#!/bin/sh - -# Run the emulator with default values intended for a development environment. +(echo -e "ARCH=$ARCH\nrun_emulator()\n{" && + emulator_command "$IMAGE" zImage-$ARCH && + echo "}" || dienow) > "$STAGE_DIR/run-emulator.sh" -QEMU_MEMORY=256 HDB=hdb.img HDBMEGS=2048 ./run-emulator.sh -EOF -chmod +x "$STAGE_DIR/dev-environment.sh" && -cp "$SOURCES/toys/unique-port.sh" "$STAGE_DIR/run-emulator.sh" && -sed -e 's/^ARCH=.*/ARCH='"$ARCH"/ "$SOURCES/toys/run-emulator.sh" >> \ - "$STAGE_DIR/run-emulator.sh" && -chmod +x "$STAGE_DIR/run-emulator.sh" && -emulator_command "$IMAGE" zImage-$ARCH >> "$STAGE_DIR/run-emulator.sh" - -[ $? -ne 0 ] && dienow +cat "$SOURCES"/toys/{unique-port,dev-environment}.sh >> "$STAGE_DIR/dev-environment.sh" && +chmod +x "$STAGE_DIR/dev-environment.sh" || dienow # Tar it up.