1# Copyright 2017, The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import os 16import re 17import tempfile 18import subprocess 19 20# begin import $ANDROID_BUILD_TOP/art/tools/build/var_cache.py 21_THIS_DIR = os.path.dirname(os.path.realpath(__file__)) 22_TOP = os.path.join(_THIS_DIR, "../../..") 23_VAR_CACHE_DIR = os.path.join(_TOP, "art/tools/build/") 24 25import sys 26sys.path.append(_VAR_CACHE_DIR) 27import var_cache 28# end import var_cache.py 29 30_env = dict(os.environ) 31 32def _getEnvBoolean(var, default): 33 val = _env.get(var) 34 if val: 35 if val == "True" or val == "true": 36 return True 37 if val == "False" or val == "false": 38 return False 39 return default 40 41def _get_build_var(var_name): 42 return var_cache.get_build_var(var_name) 43 44def _get_build_var_boolean(var, default): 45 val = _get_build_var(var) 46 if val: 47 if val == "True" or val == "true": 48 return True 49 if val == "False" or val == "false": 50 return False 51 return default 52 53def get_env(key): 54 return _env.get(key) 55 56def _get_android_build_top(): 57 path_to_top = _env.get('ANDROID_BUILD_TOP') 58 if not path_to_top: 59 # nothing set. try to guess it based on the relative path of this env.py file. 60 this_file_path = os.path.realpath(__file__) 61 path_to_top = os.path.join(os.path.dirname(this_file_path), '../../../') 62 path_to_top = os.path.realpath(path_to_top) 63 64 if not os.path.exists(os.path.join(path_to_top, 'build/envsetup.sh')): 65 raise AssertionError("env.py must be located inside an android source tree") 66 67 return path_to_top 68 69ANDROID_BUILD_TOP = _get_android_build_top() 70 71# Directory used for temporary test files on the host. 72ART_HOST_TEST_DIR = tempfile.mkdtemp(prefix = 'test-art-') 73 74# Directory used to store files build by the run-test script. 75ART_TEST_RUN_TEST_BUILD_PATH = _env.get('ART_TEST_RUN_TEST_BUILD_PATH') 76 77# Keep going after encountering a test failure? 78ART_TEST_KEEP_GOING = _getEnvBoolean('ART_TEST_KEEP_GOING', True) 79 80# Do you want failed tests to have their artifacts cleaned up? 81ART_TEST_RUN_TEST_ALWAYS_CLEAN = _getEnvBoolean('ART_TEST_RUN_TEST_ALWAYS_CLEAN', True) 82 83ART_TEST_BISECTION = _getEnvBoolean('ART_TEST_BISECTION', False) 84 85# Do you want run-tests with the host/target's second arch? 86ART_TEST_RUN_TEST_2ND_ARCH = _getEnvBoolean('ART_TEST_RUN_TEST_2ND_ARCH', True) 87 88HOST_2ND_ARCH_PREFIX = _get_build_var('HOST_2ND_ARCH_PREFIX') 89 90ART_TEST_CHROOT = _env.get('ART_TEST_CHROOT') 91ART_TEST_ANDROID_ROOT = _env.get('ART_TEST_ANDROID_ROOT') 92ART_TEST_ANDROID_ART_ROOT = _env.get('ART_TEST_ANDROID_ART_ROOT') 93ART_TEST_ANDROID_I18N_ROOT = _env.get('ART_TEST_ANDROID_I18N_ROOT') 94ART_TEST_ANDROID_TZDATA_ROOT = _env.get('ART_TEST_ANDROID_TZDATA_ROOT') 95 96ART_TEST_WITH_STRACE = _getEnvBoolean('ART_TEST_DEBUG_GC', False) 97 98EXTRA_DISABLED_TESTS = set(_env.get("ART_TEST_RUN_TEST_SKIP", "").split()) 99 100ART_TEST_RUN_TEST_BUILD = _getEnvBoolean('ART_TEST_RUN_TEST_BUILD', False) 101 102TARGET_2ND_ARCH = _get_build_var('TARGET_2ND_ARCH') 103TARGET_ARCH = _get_build_var('TARGET_ARCH') 104 105# Note: ART_2ND_PHONY_TEST_TARGET_SUFFIX is 2ND_ART_PHONY_TEST_TARGET_SUFFIX in .mk files 106# Note: ART_2ND_PHONY_TEST_HOST_SUFFIX is 2ND_ART_PHONY_HOST_TARGET_SUFFIX in .mk files 107# Python does not let us have variable names starting with a digit, so it has differ. 108 109if TARGET_2ND_ARCH: 110 if "64" in TARGET_ARCH: 111 ART_PHONY_TEST_TARGET_SUFFIX = "64" 112 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "32" 113 else: 114 ART_PHONY_TEST_TARGET_SUFFIX = "32" 115 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "" 116else: 117 if "64" in TARGET_ARCH: 118 ART_PHONY_TEST_TARGET_SUFFIX = "64" 119 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "" 120 else: 121 ART_PHONY_TEST_TARGET_SUFFIX = "32" 122 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "" 123 124HOST_PREFER_32_BIT = _get_build_var('HOST_PREFER_32_BIT') 125if HOST_PREFER_32_BIT == "true": 126 ART_PHONY_TEST_HOST_SUFFIX = "32" 127 ART_2ND_PHONY_TEST_HOST_SUFFIX = "" 128else: 129 ART_PHONY_TEST_HOST_SUFFIX = "64" 130 ART_2ND_PHONY_TEST_HOST_SUFFIX = "32" 131 132HOST_OUT_EXECUTABLES = os.path.join(ANDROID_BUILD_TOP, 133 _get_build_var("HOST_OUT_EXECUTABLES")) 134 135# Set up default values for $DX, $SMALI, etc to the $HOST_OUT_EXECUTABLES/$name path. 136for tool in ['dx', 'smali', 'jasmin', 'd8']: 137 os.environ.setdefault(tool.upper(), HOST_OUT_EXECUTABLES + '/' + tool) 138 139ANDROID_JAVA_TOOLCHAIN = os.path.join(ANDROID_BUILD_TOP, 140 _get_build_var('ANDROID_JAVA_TOOLCHAIN')) 141 142# include platform prebuilt java, javac, etc in $PATH. 143os.environ['PATH'] = ANDROID_JAVA_TOOLCHAIN + ':' + os.environ['PATH'] 144 145DIST_DIR = _get_build_var('DIST_DIR') 146SOONG_OUT_DIR = _get_build_var('SOONG_OUT_DIR') 147 148ART_TEST_RUN_ON_ARM_FVP = _getEnvBoolean('ART_TEST_RUN_ON_ARM_FVP', False) 149