changeset 899:726cac165450

Remove old RECORD_COMMANDS debris from host-tools.sh and simplify result (lots of white-noise from de-intenting the "else" case of an if/else), factor out wrap_path from sources/more/record-commands.sh, fix the "build host tools first, then wrap it afterwards" case.
author Rob Landley <rob@landley.net>
date Mon, 23 Nov 2009 21:58:49 -0600
parents db0f536aee7c
children 266dc7ea04c2
files host-tools.sh sources/functions.sh sources/more/record-commands.sh
diffstat 3 files changed, 77 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/host-tools.sh	Sun Nov 22 03:56:04 2009 -0600
+++ b/host-tools.sh	Mon Nov 23 21:58:49 2009 -0600
@@ -34,38 +34,8 @@
 # Blank $WORK but accept $STAGE_DIR if it exists.  Re-running this script
 # should be a NOP.
 
-blank_tempdir "${WORK}"
-mkdir -p "${STAGE_DIR}" || dienow
-
-# If we want to record the host command lines, so we know exactly what commands
-# the build uses, set up a wrapper that does that.
-
-if [ ! -z "$RECORD_COMMANDS" ]
-then
-  if [ ! -f "$WRAPDIR/wrappy" ]
-  then
-    echo setup wrapdir
-
-    # Build the wrapper and install it into build/wrapdir/wrappy
-    blank_tempdir "$WRAPDIR"
-    $CC -Os "$SOURCES/toys/wrappy.c" -o "$WRAPDIR/wrappy"  || dienow
-
-    # Loop through each $PATH element and create a symlink to the wrapper with
-    # that name.
-
-    for i in $(echo "$PATH" | sed 's/:/ /g')
-    do
-      for j in $(ls $i)
-      do
-        [ -f "$WRAPDIR/$j" ] || ln -s wrappy "$WRAPDIR/$j"
-      done
-    done
-
-    # Adjust things to use wrapper directory
-
-    export WRAPPY_REALPATH="$PATH"
-    PATH="$WRAPDIR"
-  fi
+blank_tempdir "$WORK"
+mkdir -p "$STAGE_DIR" || dienow
 
 # If we're not recording the host command lines, then populate a directory
 # with host versions of all the command line utilities we're going to install
@@ -88,56 +58,53 @@
 #    same command line utilities no matter where we're running, because we
 #    provide our own.
 
-else
+# Use the new tools we build preferentially, as soon as they become
+# available.
 
-  # Use the new tools we build preferentially, as soon as they become
-  # available.
+PATH="$STAGE_DIR:$PATH"
 
-  PATH="$STAGE_DIR:$PATH"
+# Start by building busybox.  We have no idea what strange things our host
+# system has (or lacks, such as "which"), so throw busybox at it first
+# thing.
 
-  # Start by building busybox.  We have no idea what strange things our host
-  # system has (or lacks, such as "which"), so throw busybox at it first
-  # thing.
+if [ ! -f "${STAGE_DIR}/busybox" ]
+then
+  build_section busybox
+fi
 
-  if [ ! -f "${STAGE_DIR}/busybox" ]
-  then
-    build_section busybox
-  fi
+# Create symlinks to the host toolchain.  We need a usable existing host
+# toolchain in order to build anything else (even a new host toolchain),
+# and we don't really want to have to care what the host type is, so
+# just use the toolchain that's already there.
 
-  # Create symlinks to the host toolchain.  We need a usable existing host
-  # toolchain in order to build anything else (even a new host toolchain),
-  # and we don't really want to have to care what the host type is, so
-  # just use the toolchain that's already there.
+# This is a little more complicated than it needs to be, because the host
+# toolchain may be using ccache and/or distcc, which means we need every
+# instance of these tools that occurs in the $PATH, in order, each in its
+# own fallback directory.
 
-  # This is a little more complicated than it needs to be, because the host
-  # toolchain may be using ccache and/or distcc, which means we need every
-  # instance of these tools that occurs in the $PATH, in order, each in its
-  # own fallback directory.
-
-  for i in ar as nm cc make ld gcc
-  do
-    if [ ! -f "${STAGE_DIR}/$i" ]
-    then
-      # Loop through each instance, populating fallback directories.
+for i in ar as nm cc make ld gcc
+do
+  if [ ! -f "${STAGE_DIR}/$i" ]
+  then
+    # Loop through each instance, populating fallback directories.
 
-      X=0
-      FALLBACK="$STAGE_DIR"
-      PATH="$OLDPATH" "$STAGE_DIR/which" -a "$i" | while read j
-      do
-        mkdir -p "$FALLBACK" &&
-        ln -sf "$j" "$FALLBACK/$i" || dienow
+    X=0
+    FALLBACK="$STAGE_DIR"
+    PATH="$OLDPATH" "$STAGE_DIR/which" -a "$i" | while read j
+    do
+      mkdir -p "$FALLBACK" &&
+      ln -sf "$j" "$FALLBACK/$i" || dienow
 
-        X=$[$X+1]
-        FALLBACK="$STAGE_DIR/fallback-$X"
-      done
-    fi
-  done
+      X=$[$X+1]
+      FALLBACK="$STAGE_DIR/fallback-$X"
+    done
+  fi
+done
 
-  # We now have all the tools we need in $STAGE_DIR, so trim the $PATH to
-  # remove the old ones.
+# We now have all the tools we need in $STAGE_DIR, so trim the $PATH to
+# remove the old ones.
 
-  PATH="$(hosttools_path)"
-fi
+PATH="$(hosttools_path)"
 
 # This is optionally used by root-filesystem to accelerate native builds when
 # running under qemu.  It's not used to build root-filesystem, or to build
@@ -209,13 +176,4 @@
   cleanup
 fi
 
-if [ ! -z "$RECORD_COMMANDS" ]
-then 
-  # Make sure the host tools we just built are also in wrapdir
-  for j in $(ls "$STAGE_DIR")
-  do
-    [ -e "$BUILD/wrapdir/$j" ] || ln -s wrappy "$BUILD/wrapdir/$j"
-  done
-fi
-
 echo -e "\e[32mHost tools build complete.\e[0m"
--- a/sources/functions.sh	Sun Nov 22 03:56:04 2009 -0600
+++ b/sources/functions.sh	Mon Nov 23 21:58:49 2009 -0600
@@ -684,3 +684,35 @@
     X=$[$X+1]
   done
 }
+
+
+# Create a directory of symlinks to all binaries in a colon-separated path.
+
+# Arguments are path to search, directory to populate, and (optionally)
+# wrapper binary to symlink to instead of original binaries.
+
+wrap_path()
+{
+
+  # For each each $PATH element, loop through each file in that directory,
+  # and create a symlink to the wrapper with that name.  In the case of
+  # duplicates, keep the first one.
+
+  echo "$1" | sed 's/:/\n/g' | while read i
+  do
+    ls -1 "$i" | while read j
+    do
+      if [ ! -z "$3" ]
+      then
+        ln -s "$3" "$2/$j" 2>/dev/null
+      else
+        ln -s "$i/$j" "$2/$j" 2>/dev/null
+      fi
+
+      # Output is verbose.  Pipe it to dotprogress.
+
+      echo $j
+    done
+  done
+}
+
--- a/sources/more/record-commands.sh	Sun Nov 22 03:56:04 2009 -0600
+++ b/sources/more/record-commands.sh	Mon Nov 23 21:58:49 2009 -0600
@@ -10,23 +10,17 @@
 
 echo "=== Setting up command recording wrapper"
 
-PATH="$OLDPATH"
+echo OLDPATH=$OLDPATH
+echo PATH=$PATH
+
+[ -f "$WRAPDIR/wrappy" ] && PATH="$OLDPATH"
+[ -f "$HOSTTOOLS/busybox" ] && PATH="$HOSTTOOLS"
 blank_tempdir "$WRAPDIR"
 blank_tempdir "$BUILD/logs"
 
 # Populate a directory of symlinks with every command in the $PATH.
 
-# For each each $PATH element, loop through each file in that directory,
-# and create a symlink to the wrapper with that name.  In the case of
-# duplicates, keep the first one.
-
-echo "$PATH" | sed 's/:/\n/g' | while read i
-do
-  ls -1 "$i" | while read j
-  do
-    ln -s wrappy "$WRAPDIR/$j" 2>/dev/null
-  done
-done
+wrap_path "$PATH" "$WRAPDIR" wrappy | dotprogress
 
 # Build the wrapper
 $CC -Os "$SOURCES/toys/wrappy.c" -o "$WRAPDIR/wrappy"  || dienow