Add support for ANDROID_TZDATA_ROOT
Soon, code in the Android Core Library / ICU4C library will depend on the
ANDROID_TZDATA_ROOT environment variable being set. On device this points
to the root of the com.android.tzdata module.
Unlike ANDROID_RUNTIME_ROOT, ANDROID_TZDATA_ROOT it doesn't have to point to
anything that exists because the code will fall back to looking in
ANDROID_RUNTIME_ROOT if it can't find the files it is looking for. Most
of the changes in this commit are plumbing to make sure the environment
variable is set to benign defaults or passed through to the runtime.
This commit has been put together by looking for usages of
ANDROID_RUNTIME_ROOT and duplicating the logic.
Bug: 128422035
Test: build only
Change-Id: I2fd73fe16f5022742aaf634be158765cac8759e6
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index e602fa6..ac0ba47 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -433,6 +433,11 @@
ART_GTEST_TARGET_ANDROID_RUNTIME_ROOT := $(ART_TEST_ANDROID_RUNTIME_ROOT)
endif
+ART_GTEST_TARGET_ANDROID_TZDATA_ROOT := '/apex/com.android.tzdata'
+ifneq ($(ART_TEST_ANDROID_TZDATA_ROOT),)
+ ART_GTEST_TARGET_ANDROID_TZDATA_ROOT := $(ART_TEST_ANDROID_TZDATA_ROOT)
+endif
+
# Define a make rule for a target device gtest.
# $(1): gtest name - the name of the test we're building such as leb128_test.
# $(2): path relative to $OUT to the test binary
@@ -483,6 +488,7 @@
($(ADB) shell "$$(PRIVATE_MAYBE_CHROOT_COMMAND) env $(GCOV_ENV) LD_LIBRARY_PATH=$(4) \
ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
ANDROID_RUNTIME_ROOT=$(ART_GTEST_TARGET_ANDROID_RUNTIME_ROOT) \
+ ANDROID_TZDATA_ROOT=$(ART_GTEST_TARGET_ANDROID_TZDATA_ROOT) \
$$(PRIVATE_TARGET_EXE) \
&& touch $$(PRIVATE_GTEST_WITNESS)" \
&& ($(ADB) pull $$(PRIVATE_GTEST_WITNESS) /tmp/ && $$(call ART_TEST_PASSED,$$@)) \
@@ -734,6 +740,7 @@
ART_TEST_TARGET_GTEST_RULES :=
ART_GTEST_TARGET_ANDROID_ROOT :=
ART_GTEST_TARGET_ANDROID_RUNTIME_ROOT :=
+ART_GTEST_TARGET_ANDROID_TZDATA_ROOT :=
ART_GTEST_class_linker_test_DEX_DEPS :=
ART_GTEST_class_table_test_DEX_DEPS :=
ART_GTEST_compiler_driver_test_DEX_DEPS :=
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index 916f072..ed74947 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -158,6 +158,17 @@
setenv("ANDROID_RUNTIME_ROOT", android_runtime_root.c_str(), 1);
}
+ // Environment variable ANDROID_TZDATA_ROOT is set on the device, but not
+ // necessarily on the host. It needs to be set so that various libraries
+ // like icu4c can find their data files.
+ const char* android_tzdata_root_from_env = getenv("ANDROID_TZDATA_ROOT");
+ if (android_tzdata_root_from_env == nullptr) {
+ // Use ${ANDROID_HOST_OUT}/com.android.tzdata for ANDROID_TZDATA_ROOT.
+ std::string android_tzdata_root = android_host_out_from_env;
+ android_tzdata_root += "/com.android.tzdata";
+ setenv("ANDROID_TZDATA_ROOT", android_tzdata_root.c_str(), 1);
+ }
+
setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>.
}
}
diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h
index 3e2340f..f8cab92 100644
--- a/libartbase/base/common_art_test.h
+++ b/libartbase/base/common_art_test.h
@@ -85,8 +85,8 @@
CommonArtTestImpl() = default;
virtual ~CommonArtTestImpl() = default;
- // Set up ANDROID_BUILD_TOP, ANDROID_HOST_OUT, ANDROID_ROOT and ANDROID_RUNTIME_ROOT
- // environment variables using sensible defaults if not already set.
+ // Set up ANDROID_BUILD_TOP, ANDROID_HOST_OUT, ANDROID_ROOT, ANDROID_RUNTIME_ROOT,
+ // and ANDROID_TZDATA_ROOT environment variables using sensible defaults if not already set.
static void SetUpAndroidRootEnvVars();
// Set up the ANDROID_DATA environment variable, creating the directory if required.
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 0fe148f..e9380d3 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -10,6 +10,7 @@
ANDROID_ROOT="/system"
ANDROID_RUNTIME_ROOT="/apex/com.android.runtime"
+ANDROID_TZDATA_ROOT="/apex/com.android.tzdata"
ARCHITECTURES_32="(arm|x86|mips|none)"
ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
@@ -219,6 +220,7 @@
HOST="y"
ANDROID_ROOT="${ANDROID_HOST_OUT}"
ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
+ ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
shift
elif [ "x$1" = "x--bionic" ]; then
BIONIC="y"
@@ -286,6 +288,7 @@
HOST="y"
ANDROID_ROOT="${ANDROID_HOST_OUT}"
ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
+ ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
shift
elif [ "x$1" = "x--gdb" ]; then
USE_GDB="y"
@@ -349,6 +352,10 @@
shift
ANDROID_RUNTIME_ROOT="$1"
shift
+ elif [ "x$1" = "x--android-tzdata-root" ]; then
+ shift
+ ANDROID_TZDATA_ROOT="$1"
+ shift
elif [ "x$1" = "x--instruction-set-features" ]; then
shift
INSTRUCTION_SET_FEATURES="$1"
@@ -993,6 +1000,7 @@
export DEX_LOCATION=$DEX_LOCATION && \
export ANDROID_ROOT=$ANDROID_ROOT && \
export ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT && \
+ export ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT && \
export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
mkdir -p ${mkdir_locations} && \
@@ -1038,6 +1046,7 @@
export ANDROID_DATA="$DEX_LOCATION"
export ANDROID_ROOT="${ANDROID_ROOT}"
export ANDROID_RUNTIME_ROOT="${ANDROID_RUNTIME_ROOT}"
+ export ANDROID_TZDATA_ROOT="${ANDROID_TZDATA_ROOT}"
if [ "$USE_ZIPAPEX" = "y" ]; then
# Put the zipapex files in front of the ld-library-path
export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
diff --git a/test/testrunner/env.py b/test/testrunner/env.py
index c2d5e7d..a8360cb 100644
--- a/test/testrunner/env.py
+++ b/test/testrunner/env.py
@@ -91,6 +91,7 @@
ART_TEST_CHROOT = _env.get('ART_TEST_CHROOT')
ART_TEST_ANDROID_ROOT = _env.get('ART_TEST_ANDROID_ROOT')
ART_TEST_ANDROID_RUNTIME_ROOT = _env.get('ART_TEST_ANDROID_RUNTIME_ROOT')
+ART_TEST_ANDROID_TZDATA_ROOT = _env.get('ART_TEST_ANDROID_TZDATA_ROOT')
ART_TEST_WITH_STRACE = _getEnvBoolean('ART_TEST_DEBUG_GC', False)
diff --git a/test/testrunner/testrunner.py b/test/testrunner/testrunner.py
index 0456fdb..54701af 100755
--- a/test/testrunner/testrunner.py
+++ b/test/testrunner/testrunner.py
@@ -400,8 +400,8 @@
elif target == 'jvm':
options_test += ' --jvm'
- # Honor ART_TEST_CHROOT, ART_TEST_ANDROID_ROOT and ART_TEST_ANDROID_RUNTIME_ROOT,
- # but only for target tests.
+ # Honor ART_TEST_CHROOT, ART_TEST_ANDROID_ROOT, ART_TEST_ANDROID_RUNTIME_ROOT,
+ # and ART_TEST_ANDROID_TZDATA_ROOT but only for target tests.
if target == 'target':
if env.ART_TEST_CHROOT:
options_test += ' --chroot ' + env.ART_TEST_CHROOT
@@ -409,6 +409,8 @@
options_test += ' --android-root ' + env.ART_TEST_ANDROID_ROOT
if env.ART_TEST_ANDROID_RUNTIME_ROOT:
options_test += ' --android-runtime-root ' + env.ART_TEST_ANDROID_RUNTIME_ROOT
+ if env.ART_TEST_ANDROID_TZDATA_ROOT:
+ options_test += ' --android-tzdata-root ' + env.ART_TEST_ANDROID_TZDATA_ROOT
if run == 'ndebug':
options_test += ' -O'
diff --git a/tools/art b/tools/art
index 58a8150..9e39464 100644
--- a/tools/art
+++ b/tools/art
@@ -200,6 +200,7 @@
verbose_run ANDROID_DATA=$ANDROID_DATA \
ANDROID_ROOT=$ANDROID_ROOT \
ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT \
+ ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT \
LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
PATH=$ANDROID_ROOT/bin:$PATH \
LD_USE_LOAD_BIAS=1 \
@@ -275,6 +276,7 @@
verbose_run ANDROID_DATA="$ANDROID_DATA" \
ANDROID_ROOT="$ANDROID_ROOT" \
ANDROID_RUNTIME_ROOT="$ANDROID_RUNTIME_ROOT" \
+ ANDROID_TZDATA_ROOT="$ANDROID_TZDATA_ROOT" \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
PATH="$ANDROID_ROOT/bin:$PATH" \
LD_USE_LOAD_BIAS=1 \
@@ -435,6 +437,13 @@
fi
fi
+# If ANDROID_TZDATA_ROOT is not set point it to somewhere safe. Android code
+# currently treats the module as optional so it does not require the path exists.
+if [ -z "$ANDROID_TZDATA_ROOT" ]; then
+ # Safe stubbed location that we don't need to exist.
+ ANDROID_TZDATA_ROOT="$ANDROID_ROOT/com.android.tzdata_doesnotexist"
+fi
+
ART_BINARY_PATH=$ANDROID_ROOT/bin/$ART_BINARY
if [ ! -x "$ART_BINARY_PATH" ]; then
diff --git a/tools/common/common.py b/tools/common/common.py
index 6206dfb..4171dfe 100755
--- a/tools/common/common.py
+++ b/tools/common/common.py
@@ -300,12 +300,14 @@
lib = 'lib64' if x64 else 'lib'
android_root = GetEnvVariableOrError('ANDROID_HOST_OUT')
android_runtime_root = android_root + '/com.android.runtime'
+ android_tzdata_root = android_root + '/com.android.tzdata'
library_path = android_root + '/' + lib
path = android_root + '/bin'
self._shell_env = os.environ.copy()
self._shell_env['ANDROID_DATA'] = self._env_path
self._shell_env['ANDROID_ROOT'] = android_root
self._shell_env['ANDROID_RUNTIME_ROOT'] = android_runtime_root
+ self._shell_env['ANDROID_TZDATA_ROOT'] = android_tzdata_root
self._shell_env['LD_LIBRARY_PATH'] = library_path
self._shell_env['DYLD_LIBRARY_PATH'] = library_path
self._shell_env['PATH'] = (path + ':' + self._shell_env['PATH'])
diff --git a/tools/run-gtests.sh b/tools/run-gtests.sh
index 602eac3..7360ddd 100755
--- a/tools/run-gtests.sh
+++ b/tools/run-gtests.sh
@@ -34,7 +34,7 @@
for i in $all_tests; do
echo $i
- ${ADB} shell "chroot $ART_TEST_CHROOT env LD_LIBRARY_PATH= ANDROID_ROOT='/system' ANDROID_RUNTIME_ROOT=/system $i" || fail $i
+ ${ADB} shell "chroot $ART_TEST_CHROOT env LD_LIBRARY_PATH= ANDROID_ROOT='/system' ANDROID_RUNTIME_ROOT=/system ANDROID_TZDATA_ROOT='/system' $i" || fail $i
done
if [ -n "$failing_tests" ]; then