ART: Use ANDROID_HOST_OUT for ANDROID_ROOT in Runtime tests

On the host, if ANDROID_ROOT is not set, first try ANDROID_HOST_OUT.
This will ensure that builds with OUT_DIR_COMMON_BASE will run the
gtests correctly, as icu will use ANDROID_ROOT to look for a file.

Change-Id: I8988901be32249c1c79f96b36947a647df5de041
diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h
index 044d08b..c6991d4 100644
--- a/runtime/common_runtime_test.h
+++ b/runtime/common_runtime_test.h
@@ -114,32 +114,42 @@
  public:
   static void SetEnvironmentVariables(std::string& android_data) {
     if (IsHost()) {
-      // $ANDROID_ROOT is set on the device, but not on the host.
-      // We need to set this so that icu4c can find its locale data.
-      std::string root;
-      const char* android_build_top = getenv("ANDROID_BUILD_TOP");
-      if (android_build_top != nullptr) {
-        root += android_build_top;
-      } else {
-        // Not set by build server, so default to current directory
-        char* cwd = getcwd(nullptr, 0);
-        setenv("ANDROID_BUILD_TOP", cwd, 1);
-        root += cwd;
-        free(cwd);
-      }
+      // $ANDROID_ROOT is set on the device, but not necessarily on the host.
+      // But it needs to be set so that icu4c can find its locale data.
+      const char* android_root_from_env = getenv("ANDROID_ROOT");
+      if (android_root_from_env == nullptr) {
+        // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set.
+        const char* android_host_out = getenv("ANDROID_HOST_OUT");
+        if (android_host_out != nullptr) {
+          setenv("ANDROID_ROOT", android_host_out, 1);
+        } else {
+          // Build it from ANDROID_BUILD_TOP or cwd
+          std::string root;
+          const char* android_build_top = getenv("ANDROID_BUILD_TOP");
+          if (android_build_top != nullptr) {
+            root += android_build_top;
+          } else {
+            // Not set by build server, so default to current directory
+            char* cwd = getcwd(nullptr, 0);
+            setenv("ANDROID_BUILD_TOP", cwd, 1);
+            root += cwd;
+            free(cwd);
+          }
 #if defined(__linux__)
-      root += "/out/host/linux-x86";
+          root += "/out/host/linux-x86";
 #elif defined(__APPLE__)
-      root += "/out/host/darwin-x86";
+          root += "/out/host/darwin-x86";
 #else
 #error unsupported OS
 #endif
-      setenv("ANDROID_ROOT", root.c_str(), 1);
+          setenv("ANDROID_ROOT", root.c_str(), 1);
+        }
+      }
       setenv("LD_LIBRARY_PATH", ":", 0);  // Required by java.lang.System.<clinit>.
 
       // Not set by build server, so default
       if (getenv("ANDROID_HOST_OUT") == nullptr) {
-        setenv("ANDROID_HOST_OUT", root.c_str(), 1);
+        setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1);
       }
     }