Only append suffixes to dex2oat(d) on host.

Amends https://r.android.com/1235151 which broke target testing.

Also move the logic for the --host argument out of the argument parsing
loop to work correctly if it's specified multiple times.

Test: art/test/testrunner/testrunner.py --target --64 -t 641-checker-arraycopy
  (in ART test chroot)
Test: lunch sdk-eng && art/tools/buildbot-build.sh --host && \
  art/test/run-test --host --optimizing 641-checker-arraycopy
  (with and without HOST_PREFER_32_BIT=true)
Bug: 148372405

Change-Id: I64277db1a99ed409696dc8aae2f1982fc2a14c9d
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 3684fc3..3068cd8 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -13,12 +13,6 @@
     fi
 }
 
-if [ "$HOST_PREFER_32_BIT" = true ]; then
-  DEX2OAT_SUFFIX=32
-else
-  DEX2OAT_SUFFIX=64
-fi
-
 ANDROID_ROOT="/system"
 ANDROID_ART_ROOT="/apex/com.android.art"
 ANDROID_I18N_ROOT="/apex/com.android.i18n"
@@ -36,8 +30,8 @@
 DEBUGGER_AGENT=""
 WRAP_DEBUGGER_AGENT="n"
 DEV_MODE="n"
-DEX2OAT_NDEBUG_BINARY="dex2oat${DEX2OAT_SUFFIX}"
-DEX2OAT_DEBUG_BINARY="dex2oatd${DEX2OAT_SUFFIX}"
+DEX2OAT_NDEBUG_BINARY="dex2oat"
+DEX2OAT_DEBUG_BINARY="dex2oatd"
 EXPERIMENTAL=""
 FALSE_BIN="false"
 FLAGS=""
@@ -244,10 +238,6 @@
         shift
     elif [ "x$1" = "x--host" ]; then
         HOST="y"
-        ANDROID_ROOT="${ANDROID_HOST_OUT}"
-        ANDROID_ART_ROOT="${ANDROID_HOST_OUT}/com.android.art"
-        ANDROID_I18N_ROOT="${ANDROID_HOST_OUT}/com.android.i18n"
-        ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
         shift
     elif [ "x$1" = "x--bionic" ]; then
         BIONIC="y"
@@ -455,8 +445,20 @@
     fi
 done
 
-# HACK: Force the use of `signal_dumper` on host.
 if [[ "$HOST" = "y" ]]; then
+  ANDROID_ROOT="${ANDROID_HOST_OUT}"
+  ANDROID_ART_ROOT="${ANDROID_HOST_OUT}/com.android.art"
+  ANDROID_I18N_ROOT="${ANDROID_HOST_OUT}/com.android.i18n"
+  ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
+  if [ "$HOST_PREFER_32_BIT" = true ]; then
+    DEX2OAT_HOST_SUFFIX=32
+  else
+    DEX2OAT_HOST_SUFFIX=64
+  fi
+  DEX2OAT_NDEBUG_BINARY="${DEX2OAT_NDEBUG_BINARY}${DEX2OAT_HOST_SUFFIX}"
+  DEX2OAT_DEBUG_BINARY="${DEX2OAT_DEBUG_BINARY}${DEX2OAT_HOST_SUFFIX}"
+
+  # HACK: Force the use of `signal_dumper` on host.
   TIME_OUT="timeout"
 fi