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