Add option to skip building the run tests in buildbot-build.sh.

With the run test compilation moved to the build step
(https://r.android.com/1794531), it takes a lot longer. Add an option
to skip it, in case the caller doesn't intend to run the run tests.

This unearthed a few missing dependencies in system/lib(64) when
building gtests only. One reason it's necessary to add them here is
that prebuilts don't retain the source shared_lib dependencies.

Test: art/tools/buildbot-build.sh --installclean \
        --skip-run-tests-build && \
      art/tools/buildbot-teardown-device.sh && \
      art/tools/buildbot-cleanup-device.sh && \
      art/tools/buildbot-setup-device.sh && \
      art/tools/buildbot-sync.sh && \
      art/tools/run-gtests.sh && \
      m TARGET_BUILD_UNBUNDLED=true test-art-host-gtest
  on master-art
Test: art/tools/buildbot-build.sh --installclean && \
      art/tools/buildbot-teardown-device.sh && \
      art/tools/buildbot-cleanup-device.sh && \
      art/tools/buildbot-setup-device.sh && \
      art/tools/buildbot-sync.sh && \
      art/test/testrunner/testrunner.py --target --64 --optimizing && \
      art/test/testrunner/testrunner.py --host --64 --optimizing
  on master-art
Bug: 147814778
Change-Id: Iff15ccdc1113d19289176447fc42a40a3005bfd1
diff --git a/Android.mk b/Android.mk
index 0b456c9..58f1aec 100644
--- a/Android.mk
+++ b/Android.mk
@@ -738,11 +738,21 @@
 ########################################################################
 # Rules for building all dependencies for tests.
 
-.PHONY: build-art-host-tests
-build-art-host-tests:   build-art-host $(TEST_ART_RUN_TEST_DEPENDENCIES) $(ART_TEST_HOST_RUN_TEST_DEPENDENCIES) $(ART_TEST_HOST_GTEST_DEPENDENCIES)
+.PHONY: build-art-host-gtests build-art-host-run-tests build-art-host-tests
 
-.PHONY: build-art-target-tests
-build-art-target-tests:   build-art-target $(TEST_ART_RUN_TEST_DEPENDENCIES) $(ART_TEST_TARGET_RUN_TEST_DEPENDENCIES) $(ART_TEST_TARGET_GTEST_DEPENDENCIES)
+build-art-host-gtests: build-art-host $(ART_TEST_HOST_GTEST_DEPENDENCIES)
+
+build-art-host-run-tests: build-art-host $(TEST_ART_RUN_TEST_DEPENDENCIES) $(ART_TEST_HOST_RUN_TEST_DEPENDENCIES)
+
+build-art-host-tests: build-art-host-gtests build-art-host-run-tests
+
+.PHONY: build-art-target-gtests build-art-target-run-tests build-art-target-tests
+
+build-art-target-gtests: build-art-target $(ART_TEST_TARGET_GTEST_DEPENDENCIES)
+
+build-art-target-run-tests: build-art-target $(TEST_ART_RUN_TEST_DEPENDENCIES) $(ART_TEST_TARGET_RUN_TEST_DEPENDENCIES)
+
+build-art-target-tests: build-art-target-gtests build-art-target-run-tests
 
 ########################################################################
 # targets to switch back and forth from libdvm to libart
diff --git a/tools/buildbot-build.sh b/tools/buildbot-build.sh
index 3e0bfa6..e9ff627 100755
--- a/tools/buildbot-build.sh
+++ b/tools/buildbot-build.sh
@@ -43,6 +43,7 @@
 build_host="no"
 build_target="no"
 installclean="no"
+skip_run_tests_build="no"
 j_arg="-j$(nproc)"
 showcommands=
 make_command=
@@ -57,6 +58,9 @@
   elif [[ "$1" == "--installclean" ]]; then
     installclean="yes"
     shift
+  elif [[ "$1" == "--skip-run-tests-build" ]]; then
+    skip_run_tests_build="yes"
+    shift
   elif [[ "$1" == -j* ]]; then
     j_arg=$1
     shift
@@ -96,7 +100,8 @@
 
 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+=" build-art-host-gtests"
+  test $skip_run_tests_build == "yes" || make_command+=" build-art-host-run-tests"
   make_command+=" dx-tests junit-host libjdwp-host"
   for LIB in ${specific_targets} ; do
     make_command+=" $LIB-host"
@@ -107,9 +112,13 @@
     echo 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
     exit 1
   fi
-  make_command+=" build-art-target-tests"
-  make_command+=" libnetd_client-target toybox sh libtombstoned_client"
-  make_command+=" debuggerd su"
+  make_command+=" build-art-target-gtests"
+  test $skip_run_tests_build == "yes" || make_command+=" build-art-target-run-tests"
+  make_command+=" debuggerd sh su toybox"
+  # Indirect dependencies in the platform, e.g. through heapprofd_client_api.
+  # These are built to go into system/lib(64) to be part of the system linker
+  # namespace.
+  make_command+=" libbacktrace libnetd_client-target libprocinfo libtombstoned_client libunwindstack"
   # testrunner in chroot requires the class files for conscrypt and ICU (cf.
   # https://r.android.com/1828052).
   make_command+=" conscrypt core-icu4j"