Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (C) 2010 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 | # A library script to help other scripts run within an Android build environment, or while deployed |
| 19 | # on a target host. Intended to be used with the `source` bash built-in command. Defines the |
| 20 | # following environment variables: |
| 21 | # JAVA_VERSION, RDBG_FLAG, TF_PATH, TRADEFED_OPTS |
| 22 | # |
| 23 | # It will react to the following environment variables, if they are set: |
| 24 | # TF_DEBUG, TRADEFED_OPTS_FILE |
| 25 | |
| 26 | |
| 27 | checkPath() { |
| 28 | if ! type -P "$1" &> /dev/null; then |
Julien Desprez | d2bc1e1 | 2019-08-29 16:32:27 -0700 | [diff] [blame] | 29 | >&2 echo "Unable to find $1." |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 30 | exit |
| 31 | fi; |
| 32 | } |
| 33 | |
| 34 | checkFile() { |
| 35 | if [ ! -f "$1" ]; then |
Julien Desprez | d2bc1e1 | 2019-08-29 16:32:27 -0700 | [diff] [blame] | 36 | >&2 echo "Unable to locate $1" |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 37 | exit |
| 38 | fi; |
| 39 | } |
| 40 | |
Guang Zhu | 8fd08eb | 2019-08-13 10:58:33 -0700 | [diff] [blame] | 41 | # All to specify an alternative Java binary, other than the one on PATH |
| 42 | TF_JAVA="java" |
| 43 | if [ ! -z "${TF_JAVA_HOME}" ]; then |
| 44 | # following similar convention as JAVA_HOME |
| 45 | TF_JAVA=${TF_JAVA_HOME}/bin/java |
| 46 | fi |
| 47 | |
| 48 | checkPath ${TF_JAVA} |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 49 | |
| 50 | # check java version |
Guang Zhu | 8fd08eb | 2019-08-13 10:58:33 -0700 | [diff] [blame] | 51 | java_version_string=$(${TF_JAVA} -version 2>&1) |
Julien Desprez | 723fa9a | 2019-08-28 18:55:00 -0700 | [diff] [blame] | 52 | JAVA_VERSION=$(echo "$java_version_string" | grep 'version [ "]\(1\.8\|9\|11\).*[ "]') |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 53 | if [ "${JAVA_VERSION}" == "" ]; then |
Julien Desprez | d2bc1e1 | 2019-08-29 16:32:27 -0700 | [diff] [blame] | 54 | >&2 echo "Wrong java version. 1.8, 9 or 11 is required. Found $java_version_string" |
| 55 | >&2 echo "PATH value:" |
| 56 | >&2 echo "$PATH" |
Hector Tellez | 9f1f807 | 2018-03-27 17:11:32 -0700 | [diff] [blame] | 57 | exit 8 |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 58 | fi |
| 59 | |
Julien Desprez | 723fa9a | 2019-08-28 18:55:00 -0700 | [diff] [blame] | 60 | # check if java is above 9 and supports add-opens |
| 61 | JAVA_VERSION=$(echo "$java_version_string" | grep 'version [ "]\(9\|11\).*[ "]') |
| 62 | if [ "${JAVA_VERSION}" != "" ]; then |
| 63 | ADD_OPENS_FLAG="--add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.reflect.annotation=ALL-UNNAMED" |
| 64 | fi |
| 65 | |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 66 | # check debug flag and set up remote debugging |
| 67 | if [ -n "${TF_DEBUG}" ]; then |
| 68 | if [ -z "${TF_DEBUG_PORT}" ]; then |
| 69 | TF_DEBUG_PORT=10088 |
| 70 | fi |
| 71 | RDBG_FLAG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${TF_DEBUG_PORT}" |
| 72 | fi |
| 73 | |
| 74 | # first try to find TF jars in same dir as this script |
| 75 | CUR_DIR=$(dirname "$0") |
Julien Desprez | 5f39044 | 2015-11-20 23:20:44 +0000 | [diff] [blame] | 76 | TF_JAR_DIR=$(dirname "$0") |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 77 | if [ -f "${CUR_DIR}/tradefed.jar" ]; then |
| 78 | TF_PATH="${CUR_DIR}/*" |
| 79 | elif [ ! -z "${ANDROID_HOST_OUT}" ]; then |
| 80 | # in an Android build env, tradefed.jar should be in |
| 81 | # $ANDROID_HOST_OUT/tradefed/ |
| 82 | if [ -f "${ANDROID_HOST_OUT}/tradefed/tradefed.jar" ]; then |
| 83 | # We intentionally pass the asterisk through without shell expansion |
| 84 | TF_PATH="${ANDROID_HOST_OUT}/tradefed/*" |
Julien Desprez | 5f39044 | 2015-11-20 23:20:44 +0000 | [diff] [blame] | 85 | TF_JAR_DIR="${ANDROID_HOST_OUT}/tradefed/" |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 86 | fi |
| 87 | fi |
| 88 | |
| 89 | if [ -z "${TF_PATH}" ]; then |
Julien Desprez | d2bc1e1 | 2019-08-29 16:32:27 -0700 | [diff] [blame] | 90 | >&2 echo "ERROR: Could not find tradefed jar files" |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 91 | exit |
| 92 | fi |
| 93 | |
jdesprez | 6c7fb83 | 2017-04-10 17:30:50 -0700 | [diff] [blame] | 94 | # include any host-side test jars from suite |
| 95 | if [ ! -z "${ANDROID_HOST_OUT_TESTCASES}" ]; then |
| 96 | for folder in ${ANDROID_HOST_OUT_TESTCASES}/*; do |
jdesprez | 8689aa3 | 2018-03-15 09:36:13 -0700 | [diff] [blame] | 97 | for entry in "$folder"/*; do |
| 98 | if [[ "$entry" = *".jar"* ]]; then |
| 99 | TF_PATH=${TF_PATH}:$entry |
| 100 | fi |
jdesprez | 6c7fb83 | 2017-04-10 17:30:50 -0700 | [diff] [blame] | 101 | done |
| 102 | done |
| 103 | fi |
| 104 | |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 105 | # set any host specific options |
| 106 | # file format for file at $TRADEFED_OPTS_FILE is one line per host with the following format: |
| 107 | # <hostname>=<options> |
| 108 | # for example: |
| 109 | # hostname.domain.com=-Djava.io.tmpdir=/location/on/disk -Danother=false ... |
| 110 | # hostname2.domain.com=-Djava.io.tmpdir=/different/location -Danother=true ... |
| 111 | if [ -e "${TRADEFED_OPTS_FILE}" ]; then |
| 112 | # pull the line for this host and take everything after the first = |
| 113 | export TRADEFED_OPTS=`grep "^$HOSTNAME=" "$TRADEFED_OPTS_FILE" | cut -d '=' -f 2-` |
| 114 | fi |