Define `ANDROID_RUNTIME_ROOT` as `$ANDROID_ROOT` on target in the `art` script.

This is a temporary workaround meant to help ICU find ICU .dat files
in "/system/icu/etc" on target, until the Runtime APEX is available in
target testing on the ART Buildbot.

On host, continue to define `ANDROID_RUNTIME_ROOT` as
"$ANDROID_ROOT/com.android.apex".

Test: Rely on the ART Buildbot.
Bug: 121117762
Bug: 119293618
Bug: 113373927

Change-Id: Ie5e4448d2ec12e2ee499b66811fce5a076bb0bf4
diff --git a/tools/art b/tools/art
index 6e43863..9efc470 100644
--- a/tools/art
+++ b/tools/art
@@ -199,6 +199,7 @@
     # (see run_art function)
     verbose_run ANDROID_DATA=$ANDROID_DATA                    \
           ANDROID_ROOT=$ANDROID_ROOT                          \
+          ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT          \
           LD_LIBRARY_PATH=$LD_LIBRARY_PATH                    \
           PATH=$ANDROID_ROOT/bin:$PATH                        \
           LD_USE_LOAD_BIAS=1                                  \
@@ -399,7 +400,36 @@
 
 PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
 ANDROID_ROOT="$(cd $PROG_DIR/..; pwd -P)"
-ANDROID_RUNTIME_ROOT=$ANDROID_ROOT/com.android.runtime
+# This script is used on host and target (device). However, the (expected)
+# default value `ANDROID_RUNTIME_ROOT` is not the same on host and target:
+# - on host, `ANDROID_RUNTIME_ROOT` is expected to be "$ANDROID_ROOT/com.android.apex";
+# - on target, `ANDROID_RUNTIME_ROOT` is expected to be "$ANDROID_ROOT/../apex/com.android.apex".
+#
+# We use the presence/absence of the `$ANDROID_ROOT/../apex` directory to
+# determine whether we are on target or host (this is brittle, but simple).
+if [ -d "$ANDROID_ROOT/../apex" ]; then
+  # Target case.
+  #
+  # We should be setting `ANDROID_RUNTIME_ROOT` to
+  # "$ANDROID_ROOT/../apex/com.android.runtime" here. However, the Runtime APEX
+  # is not (yet) supported by the ART Buildbot setup (see b/121117762); and yet
+  # ICU code depends on `ANDROID_RUNTIME_ROOT` to find ICU .dat files.
+  #
+  # As a temporary workaround, we:
+  # - make the ART Buildbot build script (art/tools/buildbot-build.sh) also
+  #   generate the ICU .dat files in `/system/etc/icu` on device (these files
+  #   are normally only put in the Runtime APEX on device);
+  # - set `ANDROID_RUNTIME_ROOT` to `$ANDROID_ROOT` (i.e. "/system") here.
+  #
+  # TODO(b/121117762): Set `ANDROID_RUNTIME_ROOT` to
+  # "$ANDROID_ROOT/../apex/com.android.runtime" when the Runtime APEX is fully
+  # supported on the ART Buildbot and Golem.
+  ANDROID_RUNTIME_ROOT=$ANDROID_ROOT
+else
+  # Host case.
+  ANDROID_RUNTIME_ROOT="$ANDROID_ROOT/com.android.runtime"
+fi
+
 ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY
 
 if [ ! -x "$ART_BINARY_PATH" ]; then