Update buildbot-build.sh to support prebuilts libartpalette-system.

The script will replace the stub in the out directory with the
implementation fetched from the build server.

Test: buildbot-build.sh --target, buildbot-build.sh --host
Bug: 142935992
Change-Id: If2aec5dad404c63d212412afa777a204ee6319c2
diff --git a/tools/buildbot-build.sh b/tools/buildbot-build.sh
index 80f771f..12271fa 100755
--- a/tools/buildbot-build.sh
+++ b/tools/buildbot-build.sh
@@ -21,7 +21,7 @@
   exit 1
 fi
 
-source build/envsetup.sh >&/dev/null # for get_build_var
+TARGET_ARCH=$(source build/envsetup.sh > /dev/null; get_build_var TARGET_ARCH)
 
 # Logic for setting out_dir from build/make/core/envsetup.mk:
 if [[ -z $OUT_DIR ]]; then
@@ -89,7 +89,7 @@
     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+=" libnetd_client-target toybox sh"
+  make_command+=" libnetd_client-target toybox sh libtombstoned_client"
   make_command+=" debuggerd su gdbserver"
   # vogar requires the class files for conscrypt and ICU.
   make_command+=" conscrypt core-icu4j"
@@ -137,6 +137,33 @@
     fi
   done
 
+  # Replace stub libraries with implemenation libraries: because we do chroot
+  # testing, we need to install an implementation of the libraries (and cannot
+  # rely on the one already installed on the device, if the device is post R and
+  # has it).
+  implementation_libs="libartpalette-system.so"
+  if [ -d prebuilts/runtime/mainline/platform/impl ]; then
+    if [[ $TARGET_ARCH = arm* ]]; then
+      arch32=arm
+      arch64=arm64
+    else
+      arch32=x86
+      arch64=x86_64
+    fi
+    for so in $implementation_libs; do
+      if [ -d "$ANDROID_PRODUCT_OUT/system/lib" ]; then
+        cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch32/$so $ANDROID_PRODUCT_OUT/system/lib/$so"
+        echo "Executing $cmd"
+        eval "$cmd"
+      fi
+      if [ -d "$ANDROID_PRODUCT_OUT/system/lib64" ]; then
+        cmd="cp -p prebuilts/runtime/mainline/platform/impl/$arch64/$so $ANDROID_PRODUCT_OUT/system/lib64/$so"
+        echo "Executing $cmd"
+        eval "$cmd"
+      fi
+   done
+  fi
+
   # Create canonical name -> file name symlink in the symbol directory for the
   # Testing ART APEX.
   #