run-on-host fixes

 * Fix the path to bionic-benchmarks-glibc

 * Add symlinks for the toybox symlink commands. Each symlink bypasses the
   intermediate symlink in ${OUT}/system/bin and points to the final
   toybox binary. Suppress a bunch of warnings by skipping symlinks for
   non-existent files.

   The new spawn benchmarks try to run /system/bin/true. (They also try to
   run /vendor/bin/true and print an error.)

 * Quote "$@"

 * Use soong_ui.bash --dumpvars-mode to set a bunch of variables, rather
   than get_build_var, which invokes Soong once per variable. This reduces
   the "build/run-on-host.sh" runtime from 4s to 1.3s.

 * build/run-on-host.sh isn't executable and is only useful when it's
   sourced into another shell, so remove its shebang to reduce confusion.

Bug: none
Test: \
  . build/envsetup.sh
  lunch aosp_x86_64-userdebug
  . bionic/build/run-on-host.sh
  prepare MODULES-IN-bionic MODULES-IN-external-toybox
  /system/bin/true

Change-Id: I59e9a6aca77d35b16bdf51759c5fc7e725bfc67c
diff --git a/benchmarks/run-on-host.sh b/benchmarks/run-on-host.sh
index 0f2aefb..89112ae 100755
--- a/benchmarks/run-on-host.sh
+++ b/benchmarks/run-on-host.sh
@@ -8,7 +8,7 @@
         cd ${ANDROID_BUILD_TOP}
         export ANDROID_DATA=${TARGET_OUT_DATA}
         export ANDROID_ROOT=${TARGET_OUT}
-        ${HOST_OUT}/nativetest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc $@
+        ${HOST_OUT}/benchmarktest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc "$@"
     )
     exit 0
 elif [ "$1" != 32 -a "$1" != 64 ]; then
@@ -25,7 +25,7 @@
             cd ${ANDROID_BUILD_TOP}
             export ANDROID_DATA=${TARGET_OUT_DATA}
             export ANDROID_ROOT=${TARGET_OUT}
-            ${BENCHMARKS}/bionic-benchmarks/bionic-benchmarks $@
+            ${BENCHMARKS}/bionic-benchmarks/bionic-benchmarks "$@"
         )
     else
         echo "$0 not supported on TARGET_ARCH=$TARGET_ARCH"
diff --git a/build/run-on-host.sh b/build/run-on-host.sh
index 85539e2..0ca3b1e 100644
--- a/build/run-on-host.sh
+++ b/build/run-on-host.sh
@@ -1,18 +1,21 @@
-#!/bin/bash -e
+# source this script in bash
 
 source ${ANDROID_BUILD_TOP}/build/envsetup.sh
 
-TARGET_ARCH=$(get_build_var TARGET_ARCH)
-TARGET_OUT=$(get_build_var TARGET_OUT)
-TARGET_OUT_EXECUTABLES=$(get_build_var TARGET_OUT_EXECUTABLES)
-TARGET_OUT_DATA=$(get_build_var TARGET_OUT_DATA)
-HOST_OS=$(get_build_var HOST_OS)
-HOST_ARCH=$(get_build_var HOST_ARCH)
-HOST_OUT=$(get_build_var HOST_OUT)
+# See envsetup.sh for an example of using --dumpvars-mode to set shell variables.
+eval "$(cd ${ANDROID_BUILD_TOP}; build/soong/soong_ui.bash --dumpvars-mode --vars="\
+    TARGET_ARCH \
+    TARGET_OUT \
+    TARGET_OUT_EXECUTABLES \
+    TARGET_OUT_DATA \
+    HOST_OS \
+    HOST_ARCH \
+    HOST_OUT \
+    ")"
 
 function prepare()
 {
-    BITS=$1
+    local BITS=$1
     shift
 
     BENCHMARKS=${TARGET_OUT_DATA}/benchmarktest
@@ -23,27 +26,36 @@
     fi
 
     if [ ${TARGET_ARCH} = x86 -o ${TARGET_ARCH} = x86_64 ]; then
-        m -j MODULES-IN-bionic MODULES-IN-external-icu MODULES-IN-external-mksh ${TARGET_OUT}/etc/hosts $@
+        m -j MODULES-IN-bionic MODULES-IN-external-icu MODULES-IN-external-mksh ${TARGET_OUT}/etc/hosts "$@"
 
         if [ ! -d /system ]; then
-            echo "Attempting to create /system";
-            sudo mkdir -p -m 0777 /system;
-            mkdir -p -m 0777 /system/bin;
-            mkdir -p -m 0777 /system/lib;
-            mkdir -p -m 0777 /system/lib64;
+            echo "Attempting to create /system"
+            sudo mkdir -p -m 0777 /system
+            mkdir -p -m 0777 /system/bin
+            mkdir -p -m 0777 /system/lib
+            mkdir -p -m 0777 /system/lib64
         fi
         (
+            function make_link() {
+                dir=$1
+                tgt=$2
+                name=`basename ${tgt}`
+                src=$dir/$name
+                if [ -e $tgt ]; then
+                    ln -sfT `realpath ${tgt}` $src
+                fi
+            }
             cd ${ANDROID_BUILD_TOP}
             mkdir -p ${TARGET_OUT_DATA}/local/tmp
             for i in ${TARGET_OUT}/bin/bootstrap/* ${TARGET_OUT}/bin/*; do
-              ln -fs `realpath ${i}` /system/bin/
+                make_link /system/bin ${i}
             done
             ln -fs `realpath ${TARGET_OUT}/etc` /system/
             for i in ${TARGET_OUT}/lib/bootstrap/* ${TARGET_OUT}/lib/*; do
-              ln -fs `realpath ${i}` /system/lib/
+                make_link /system/lib ${i}
             done
             for i in ${TARGET_OUT}/lib64/bootstrap/* ${TARGET_OUT}/lib64/*; do
-              ln -fs `realpath ${i}` /system/lib64/
+                make_link /system/lib64 ${i}
             done
         )
     fi