blob: 187ba3a01ff9b7c185f9acc4c0040aa9569a0b52 [file] [log] [blame]
Igor Murashkin25538872017-02-28 16:38:58 -08001#!/bin/bash
2#
3# Copyright (C) 2017 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17#
18# Export some environment variables used by ART's Android.mk/Android.bp
19# build systems to configure ART [to use a different implementation].
20#
21# Currently only varies on ART_USE_READ_BARRIER for a concurrent/non-concurrent
22# flavor of the ART garbage collector.
23#
24# Only meant for golem use since when building ART directly, one can/should set
25# these environment flags themselves.
26#
27# These environment flags are not really meant here to be for "correctness",
28# but rather telling the ART C++ to use alternative algorithms.
29# In other words, the same exact binary build with a different "target"
30# should run in the same context (e.g. it does not change arch or the OS it's built for).
31#
32
33setenv() {
34 local name="$1"
35 local value="$2"
36
37 export $name="$value"
38 echo export $name="$value"
39}
40
41# Enforce specified target-name is one of these.
42# Perhaps we should be less strict?
43ALL_TARGETS=(art-interpreter art-opt art-jit art-jit-cc art-opt-cc art-opt-debuggable art-vdex)
44
45usage() {
46 echo >&2 "Usage: $(basename $0) (--list-targets | <target-name>)"
47 echo >&2
48 echo >&2 "Exports the necessary ART environment variables"
49 echo >&2 "to pass to the Golem build to correctly configure ART."
50 echo >&2 "--------------------------------------------------------"
51 echo >&2 "Required Arguments:"
52 echo >&2 " <target-name> Specify the golem target to get environment variables for."
53 echo >&2
54 echo >&2 "Optional Flags":
55 echo >&2 " --list-targets Display all the targets. Do not require the main target-name."
56 echo >&2 " --help Print this help listing."
57 echo >&2
58 echo >&2 "Available Targets:"
59
60 list_targets 2 " "
61}
62
63list_targets() {
64 local out_fd="${1:-1}" # defaults to 1 if no param was set
65 local prefix="$2"
66
67 for target in "${ALL_TARGETS[@]}"; do
68 echo >&$out_fd "${prefix}${target}"
69 done
70}
71
72
73# Check if $1 element is in array $2
74contains_element() {
75 local e
76 for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
77 return 1
78}
79
80main() {
81 if [[ $# -lt 1 ]]; then
82 usage
83 exit 1
84 fi
85
86 if [[ "$1" == "--help" ]]; then
87 usage
88 exit 1
89 fi
90
91 if [[ "$1" == "--list-targets" ]]; then
92 list_targets
93 exit 0
94 fi
95
96 local selected_target="$1"
97 if ! contains_element "$selected_target" "${ALL_TARGETS[@]}"; then
98 echo "ERROR: Invalid target value '$selected_target'" >&2
99 exit 1
100 fi
101
102 case "$selected_target" in
103 *-cc)
104 setenv ART_USE_READ_BARRIER true
105 ;;
106 *)
107 setenv ART_USE_READ_BARRIER false
108 ;;
109 esac
110
111 # Make smaller .tar.gz files by excluding debug targets.
112 setenv ART_BUILD_TARGET_DEBUG false
113 setenv ART_BUILD_HOST_DEBUG false
114 setenv USE_DEX2OAT_DEBUG false
115}
116
117main "$@"