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# Keep going after encountering a test failure? 75ART_TEST_KEEP_GOING = _getEnvBoolean('ART_TEST_KEEP_GOING', True) 76 77# Do you want failed tests to have their artifacts cleaned up? 78ART_TEST_RUN_TEST_ALWAYS_CLEAN = _getEnvBoolean('ART_TEST_RUN_TEST_ALWAYS_CLEAN', True) 79 80ART_TEST_BISECTION = _getEnvBoolean('ART_TEST_BISECTION', False) 81 82DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get('DEX2OAT_HOST_INSTRUCTION_SET_FEATURES') 83 84# Do you want run-tests with the host/target's second arch? 85ART_TEST_RUN_TEST_2ND_ARCH = _getEnvBoolean('ART_TEST_RUN_TEST_2ND_ARCH', True) 86 87HOST_2ND_ARCH_PREFIX = _get_build_var('HOST_2ND_ARCH_PREFIX') 88HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get( 89 HOST_2ND_ARCH_PREFIX + 'DEX2OAT_HOST_INSTRUCTION_SET_FEATURES') 90 91ART_TEST_CHROOT = _env.get('ART_TEST_CHROOT') 92ART_TEST_ANDROID_ROOT = _env.get('ART_TEST_ANDROID_ROOT') 93ART_TEST_ANDROID_ART_ROOT = _env.get('ART_TEST_ANDROID_ART_ROOT') 94ART_TEST_ANDROID_I18N_ROOT = _env.get('ART_TEST_ANDROID_I18N_ROOT') 95ART_TEST_ANDROID_TZDATA_ROOT = _env.get('ART_TEST_ANDROID_TZDATA_ROOT') 96 97ART_TEST_WITH_STRACE = _getEnvBoolean('ART_TEST_DEBUG_GC', False) 98 99EXTRA_DISABLED_TESTS = set(_env.get("ART_TEST_RUN_TEST_SKIP", "").split()) 100 101ART_TEST_RUN_TEST_BUILD = _getEnvBoolean('ART_TEST_RUN_TEST_BUILD', False) 102 103TARGET_2ND_ARCH = _get_build_var('TARGET_2ND_ARCH') 104TARGET_ARCH = _get_build_var('TARGET_ARCH') 105 106# Note: ART_2ND_PHONY_TEST_TARGET_SUFFIX is 2ND_ART_PHONY_TEST_TARGET_SUFFIX in .mk files 107# Note: ART_2ND_PHONY_TEST_HOST_SUFFIX is 2ND_ART_PHONY_HOST_TARGET_SUFFIX in .mk files 108# Python does not let us have variable names starting with a digit, so it has differ. 109 110if TARGET_2ND_ARCH: 111 if "64" in TARGET_ARCH: 112 ART_PHONY_TEST_TARGET_SUFFIX = "64" 113 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "32" 114 else: 115 ART_PHONY_TEST_TARGET_SUFFIX = "32" 116 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "" 117else: 118 if "64" in TARGET_ARCH: 119 ART_PHONY_TEST_TARGET_SUFFIX = "64" 120 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "" 121 else: 122 ART_PHONY_TEST_TARGET_SUFFIX = "32" 123 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "" 124 125HOST_PREFER_32_BIT = _get_build_var('HOST_PREFER_32_BIT') 126if HOST_PREFER_32_BIT == "true": 127 ART_PHONY_TEST_HOST_SUFFIX = "32" 128 ART_2ND_PHONY_TEST_HOST_SUFFIX = "" 129else: 130 ART_PHONY_TEST_HOST_SUFFIX = "64" 131 ART_2ND_PHONY_TEST_HOST_SUFFIX = "32" 132 133HOST_OUT_EXECUTABLES = os.path.join(ANDROID_BUILD_TOP, 134 _get_build_var("HOST_OUT_EXECUTABLES")) 135 136# Set up default values for $DX, $SMALI, etc to the $HOST_OUT_EXECUTABLES/$name path. 137for tool in ['dx', 'smali', 'jasmin', 'd8']: 138 os.environ.setdefault(tool.upper(), HOST_OUT_EXECUTABLES + '/' + tool) 139 140ANDROID_JAVA_TOOLCHAIN = os.path.join(ANDROID_BUILD_TOP, 141 _get_build_var('ANDROID_JAVA_TOOLCHAIN')) 142 143# include platform prebuilt java, javac, etc in $PATH. 144os.environ['PATH'] = ANDROID_JAVA_TOOLCHAIN + ':' + os.environ['PATH'] 145 146DIST_DIR = _get_build_var('DIST_DIR') 147SOONG_OUT_DIR = _get_build_var('SOONG_OUT_DIR') 148