Query Soong for all build vars.

This avoids the dependency on a preceding lunch/banchan/tapas
invocation, and makes the script behaves better in e.g.
`env TARGET_PRODUCT=aosp_arm art/build/apex/runtests.sh`.

#codehealth

Test: env TARGET_PRODUCT=aosp_cf_x86_phone \
        art/build/apex/runtests.sh --bitness=multilib
  without preceding environment setup with lunch or similar
Test: env TARGET_PRODUCT=aosp_arm \
        art/build/apex/runtests.sh
  without preceding environment setup with lunch or similar
Change-Id: Ia0bee9109b203d97d4a1c3ef22518f8b043dca72
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index 8044574..acf6784 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -35,16 +35,21 @@
   exit 1
 }
 
-function setup_die {
-  die "You need to run lunch, banchan, or tapas before you can use this script."
-}
+if [[ -z "$ANDROID_BUILD_TOP" ]]; then
+  export ANDROID_BUILD_TOP=$(pwd)
+  if [[ ! -x "$ANDROID_BUILD_TOP/build/soong/soong_ui.bash" ]]; then
+    die "Run from the root of the Android tree, or run lunch/banchan/tapas first."
+  fi
+fi
 
-[[ -n "$ANDROID_BUILD_TOP" ]] || setup_die
-[[ -n "$ANDROID_PRODUCT_OUT" ]] || setup_die
-[[ -n "$ANDROID_HOST_OUT" ]] || setup_die
-
+query_build_vars=(
+  HOST_OUT
+  PRODUCT_COMPRESSED_APEX
+  PRODUCT_OUT
+  TARGET_FLATTEN_APEX
+)
 vars="$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash \
-        --dumpvars-mode --vars="TARGET_FLATTEN_APEX PRODUCT_COMPRESSED_APEX")"
+        --dumpvars-mode --vars="${query_build_vars[*]}")"
 # Assign to a variable and eval that, since bash ignores any error status from
 # the command substitution if it's directly on the eval line.
 eval $vars
@@ -56,7 +61,7 @@
 
 have_deapexer_p=false
 if [[ "$TARGET_FLATTEN_APEX" != true ]]; then
-  if [ ! -e "$ANDROID_HOST_OUT/bin/deapexer" -o ! -e "$ANDROID_HOST_OUT/bin/debugfs_static" ] ; then
+  if [ ! -e "$HOST_OUT/bin/deapexer" -o ! -e "$HOST_OUT/bin/debugfs_static" ] ; then
     say "Could not find deapexer and/or debugfs_static, building now."
     build/soong/soong_ui.bash --make-mode deapexer debugfs_static-host || \
       die "Cannot build deapexer and debugfs_static"
@@ -180,24 +185,24 @@
   art_apex_test_args="$global_art_apex_test_args --tmpdir $work_dir"
   test_only_args=""
   if [[ $apex_module = *.host ]]; then
-    apex_path="$ANDROID_HOST_OUT/apex/${apex_module}.zipapex"
+    apex_path="$HOST_OUT/apex/${apex_module}.zipapex"
     art_apex_test_args="$art_apex_test_args --host"
     test_only_args="--flavor debug"
   else
     if [[ "$TARGET_FLATTEN_APEX" = true ]]; then
-      apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}"
+      apex_path="$PRODUCT_OUT/system/apex/${apex_module}"
       art_apex_test_args="$art_apex_test_args --flattened"
     else
       # Note: The Testing ART APEX is never built as a Compressed APEX.
       if [[ "$PRODUCT_COMPRESSED_APEX" = true && $apex_module != *.testing ]]; then
-        apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.capex"
+        apex_path="$PRODUCT_OUT/system/apex/${apex_module}.capex"
       else
-        apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.apex"
+        apex_path="$PRODUCT_OUT/system/apex/${apex_module}.apex"
       fi
     fi
     if $have_deapexer_p; then
-      art_apex_test_args="$art_apex_test_args --deapexer $ANDROID_HOST_OUT/bin/deapexer"
-      art_apex_test_args="$art_apex_test_args --debugfs $ANDROID_HOST_OUT/bin/debugfs_static"
+      art_apex_test_args="$art_apex_test_args --deapexer $HOST_OUT/bin/deapexer"
+      art_apex_test_args="$art_apex_test_args --debugfs $HOST_OUT/bin/debugfs_static"
     fi
     case $apex_module in
       (*.debug)   test_only_args="--flavor debug";;