Enable TARGET_BUILD_UNBUNDLED in master-art (reland).

This is the way to disable assumptions in the build system that a full
system image is to be built.

Soong internally checks for the absence of frameworks/base to detect a
reduced master-art tree and disable some dependencies. That check is at
odds with TARGET_BUILD_UNBUNDLED=true, so for now let's enable
TARGET_BUILD_UNBUNDLED only on the same condition.

This relands https://r.android.com/1337182 with changes in two
testrunner scripts that were missed.

Test: art/tools/buildbot-build.sh --host
  on AOSP master and master-art
Test: art/tools/buildbot-build.sh --target
  on AOSP master and master-art
Test: m installclean && art/build/apex/runtests.sh
  on AOSP master and master-art
Test: rm -rf out && \
      art/test/testrunner/run_build_test_target.py art-linux-bionic-x64
  on AOSP master and master-art
Test: art/test/testrunner/run_build_test_target.py art-test
  on AOSP master and master-art
Test: art/test/testrunner/testrunner.py --target --64 --optimizing && \
      art/tools/run-gtests.sh
  in test chroot on device
  on AOSP master and master-art
Test: art/tools/golem/build-target.sh \
      --machine-type=android-armv8 --golem=art-jit
  on AOSP master and master-art
Bug: 159109002
Bug: 157549171
Change-Id: Ie98af1098ea1132d3db7ed0a8bf47b54e0848e57
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index 72bf74b..51acd94 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -44,6 +44,15 @@
 flattened_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)\
   || setup_die
 
+# Switch the build system to unbundled mode in the reduced manifest branch.
+# TODO(b/159109002): Clean this up.
+if [ ! -d $ANDROID_BUILD_TOP/frameworks/base ]; then
+  export TARGET_BUILD_UNBUNDLED=true
+  # Flattening is not supported in unbundled mode, regardless what
+  # TARGET_FLATTEN_APEX says.
+  flattened_apex_p=false
+fi
+
 have_debugfs_p=false
 if $flattened_apex_p; then :; else
   if [ ! -e "$ANDROID_HOST_OUT/bin/debugfs" ] ; then
diff --git a/test/testrunner/run_build_test_target.py b/test/testrunner/run_build_test_target.py
index 19f03c3..b9e0253 100755
--- a/test/testrunner/run_build_test_target.py
+++ b/test/testrunner/run_build_test_target.py
@@ -60,6 +60,10 @@
 n_threads = options.n_threads
 custom_env = target.get('env', {})
 custom_env['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true'
+# Switch the build system to unbundled mode in the reduced manifest branch.
+# TODO(b/159109002): Clean this up.
+if not os.path.isdir(env.ANDROID_BUILD_TOP + '/frameworks/base'):
+  custom_env['TARGET_BUILD_UNBUNDLED'] = 'true'
 print(custom_env)
 os.environ.update(custom_env)
 
diff --git a/test/testrunner/testrunner.py b/test/testrunner/testrunner.py
index df03dd3..61272a1 100755
--- a/test/testrunner/testrunner.py
+++ b/test/testrunner/testrunner.py
@@ -998,6 +998,10 @@
   """
   os.environ.update(build_target['env'])
   os.environ['SOONG_ALLOW_MISSING_DEPENDENCIES'] = 'true'
+  # Switch the build system to unbundled mode in the reduced manifest branch.
+  # TODO(b/159109002): Clean this up.
+  if not os.path.isdir(env.ANDROID_BUILD_TOP + '/frameworks/base'):
+    os.environ['TARGET_BUILD_UNBUNDLED'] = 'true'
   print_text('%s\n' % (str(os.environ)))
 
   target_options = vars(parser.parse_args(build_target['flags']))
diff --git a/tools/build_linux_bionic.sh b/tools/build_linux_bionic.sh
index 89e72b2..b9472ee 100755
--- a/tools/build_linux_bionic.sh
+++ b/tools/build_linux_bionic.sh
@@ -31,13 +31,21 @@
   exit 1
 fi
 
+soong_args=""
+
+# Switch the build system to unbundled mode in the reduced manifest branch.
+# TODO(b/159109002): Clean this up.
+if [ ! -d frameworks/base ]; then
+  soong_args="$soong_args TARGET_BUILD_UNBUNDLED=true"
+fi
+
 source build/envsetup.sh >&/dev/null # for get_build_var
 # Soong needs a bunch of variables set and will not run if they are missing.
 # The default values of these variables is only contained in make, so use
 # nothing to create the variables then remove all the other artifacts.
 # Lunch since it seems we cannot find the build-number otherwise.
 lunch aosp_x86-eng
-build/soong/soong_ui.bash --make-mode nothing
+build/soong/soong_ui.bash --make-mode $soong_args nothing
 
 if [ $? != 0 ]; then
   exit 1
@@ -86,4 +94,4 @@
 # Write a new build-number
 echo ${tmp_build_number}_SOONG_ONLY_BUILD > ${out_dir}/soong/build_number.txt
 
-build/soong/soong_ui.bash --make-mode --skip-make $@
+build/soong/soong_ui.bash --make-mode --skip-make $soong_args $@
diff --git a/tools/build_linux_bionic_tests.sh b/tools/build_linux_bionic_tests.sh
index c834dd5..a761325 100755
--- a/tools/build_linux_bionic_tests.sh
+++ b/tools/build_linux_bionic_tests.sh
@@ -26,6 +26,14 @@
   exit 1
 fi
 
+soong_args=""
+
+# Switch the build system to unbundled mode in the reduced manifest branch.
+# TODO(b/159109002): Clean this up.
+if [ ! -d frameworks/base ]; then
+  soong_args="$soong_args TARGET_BUILD_UNBUNDLED=true"
+fi
+
 source build/envsetup.sh >&/dev/null # for get_build_var
 
 out_dir=$(get_build_var OUT_DIR)
@@ -38,7 +46,7 @@
 
 # First build all the targets still in .mk files (also build normal glibc host
 # targets so we know what's needed to run the tests).
-build/soong/soong_ui.bash --make-mode "$@" test-art-host-run-test-dependencies build-art-host-tests
+build/soong/soong_ui.bash --make-mode $soong_args "$@" test-art-host-run-test-dependencies build-art-host-tests
 if [ $? != 0 ]; then
   exit 1
 fi
@@ -88,7 +96,7 @@
 
 echo building ${bionic_targets[*]}
 
-build/soong/soong_ui.bash --make-mode --skip-make "$@" ${bionic_targets[*]}
+build/soong/soong_ui.bash --make-mode --skip-make $soong_args "$@" ${bionic_targets[*]}
 ret=$?
 
 mv $tmp_soong_var $out_dir/soong/soong.variables
diff --git a/tools/buildbot-build.sh b/tools/buildbot-build.sh
index e352fab..3c39619 100755
--- a/tools/buildbot-build.sh
+++ b/tools/buildbot-build.sh
@@ -65,6 +65,12 @@
 # Allow to build successfully in master-art.
 extra_args="SOONG_ALLOW_MISSING_DEPENDENCIES=true"
 
+# Switch the build system to unbundled mode in the reduced manifest branch.
+# TODO(b/159109002): Clean this up.
+if [ ! -d frameworks/base ]; then
+  extra_args="$extra_args TARGET_BUILD_UNBUNDLED=true"
+fi
+
 apexes=(
   "com.android.art.testing"
   "com.android.conscrypt"
diff --git a/tools/golem/build-target.sh b/tools/golem/build-target.sh
index 45c9125..165afb4 100755
--- a/tools/golem/build-target.sh
+++ b/tools/golem/build-target.sh
@@ -269,6 +269,11 @@
   execute lunch "$lunch_target"
   # Golem uses master-art repository which is missing a lot of other libraries.
   setenv SOONG_ALLOW_MISSING_DEPENDENCIES true
+  # Let the build system know we're not aiming to do a full platform build.
+  # TODO(b/159109002): Clean this up.
+  if [ ! -d frameworks/base ]; then
+    setenv TARGET_BUILD_UNBUNDLED true
+  fi
   # Golem may be missing tools such as javac from its path.
   setenv_escape PATH "/usr/lib/jvm/java-8-openjdk-amd64/bin/:$PATH" '/usr/lib/jvm/java-8-openjdk-amd64/bin/:$PATH'
 else