summaryrefslogtreecommitdiffstats
path: root/runtime/common_runtime_test.h
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2014-06-25 17:22:59 -0700
committerAndreas Gampe <agampe@google.com>2014-06-25 17:22:59 -0700
commit86f5662a9374ee03bcd2b440a67f1e90eaac70c0 (patch)
tree5a09b0035d971cc18c2b53824041dfc6fe26db60 /runtime/common_runtime_test.h
parentb849f6dd638fd1246724160cd5c01ab1a5ff33bd (diff)
downloadart-86f5662a9374ee03bcd2b440a67f1e90eaac70c0.tar.gz
art-86f5662a9374ee03bcd2b440a67f1e90eaac70c0.tar.bz2
art-86f5662a9374ee03bcd2b440a67f1e90eaac70c0.zip
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
Diffstat (limited to 'runtime/common_runtime_test.h')
-rw-r--r--runtime/common_runtime_test.h44
1 files changed, 27 insertions, 17 deletions
diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h
index 044d08b540..c6991d4937 100644
--- a/runtime/common_runtime_test.h
+++ b/runtime/common_runtime_test.h
@@ -114,32 +114,42 @@ class CommonRuntimeTest : public testing::Test {
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);
}
}