buildbot-build.sh: Enable build of both host and target. am: fe1c7b4a5b am: c4251c8631 am: be2f405d00 am: 10ba7f3f49

Original change: https://android-review.googlesource.com/c/platform/art/+/1685634

Change-Id: I60c2290ab1df7da8514743d72cb6484a9b55ad3f
diff --git a/tools/buildbot-build.sh b/tools/buildbot-build.sh
index bfb099f..3cd774c 100755
--- a/tools/buildbot-build.sh
+++ b/tools/buildbot-build.sh
@@ -38,17 +38,20 @@
 
 java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES
 common_targets="vogar core-tests apache-harmony-jdwp-tests-hostdex jsr166-tests libartpalette-system mockito-target"
-mode="target"
+# These build targets have different names on device and host.
+specific_targets="libjavacoretests libjdwp libwrapagentproperties libwrapagentpropertiesd"
+build_host="no"
+build_target="no"
 j_arg="-j$(nproc)"
 showcommands=
 make_command=
 
 while true; do
   if [[ "$1" == "--host" ]]; then
-    mode="host"
+    build_host="yes"
     shift
   elif [[ "$1" == "--target" ]]; then
-    mode="target"
+    build_target="yes"
     shift
   elif [[ "$1" == -j* ]]; then
     j_arg=$1
@@ -64,6 +67,12 @@
   fi
 done
 
+# If neither was selected, build both by default.
+if [[ $build_host == "no" ]] && [[ $build_target == "no" ]]; then
+  build_host="yes"
+  build_target="yes"
+fi
+
 # Allow to build successfully in master-art.
 extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true"
 
@@ -81,16 +90,20 @@
   "com.android.os.statsd"
 )
 
-if [[ $mode == "host" ]]; then
-  make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-host-tests $common_targets"
+make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands $common_targets"
+if [[ $build_host == "yes" ]]; then
+  make_command+=" build-art-host-tests"
   make_command+=" dx-tests junit-host"
-  mode_suffix="-host"
-elif [[ $mode == "target" ]]; then
+  for LIB in ${specific_targets} ; do
+    make_command+=" $LIB-host"
+  done
+fi
+if [[ $build_target == "yes" ]]; then
   if [[ -z "${ANDROID_PRODUCT_OUT}" ]]; then
     echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
     exit 1
   fi
-  make_command="build/soong/soong_ui.bash --make-mode $j_arg $extra_args $showcommands build-art-target-tests $common_targets"
+  make_command+=" build-art-target-tests"
   make_command+=" libnetd_client-target toybox sh libtombstoned_client"
   make_command+=" debuggerd su gdbserver"
   # vogar requires the class files for conscrypt and ICU.
@@ -106,13 +119,9 @@
   make_command+=" deapexer"
   # Build/install the required APEXes.
   make_command+=" ${apexes[*]}"
+  make_command+=" ${specific_targets}"
 fi
 
-mode_specific_libraries="libjavacoretests libjdwp libwrapagentproperties libwrapagentpropertiesd"
-for LIB in ${mode_specific_libraries} ; do
-  make_command+=" $LIB${mode_suffix}"
-done
-
 echo "Do installclean"
 build/soong/soong_ui.bash --make-mode installclean
 
@@ -120,7 +129,7 @@
 # Disable path restrictions to enable luci builds using vpython.
 eval "$make_command"
 
-if [[ $mode == "target" ]]; then
+if [[ $build_target == "yes" ]]; then
   if [[ -z "${ANDROID_HOST_OUT}" ]]; then
     echo "ANDROID_HOST_OUT environment variable is empty; using $out_dir/host/linux-x86"
     ANDROID_HOST_OUT=$out_dir/host/linux-x86