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 |
| 29 | echo "Unable to find $1 in path." |
| 30 | exit |
| 31 | fi; |
| 32 | } |
| 33 | |
| 34 | checkFile() { |
| 35 | if [ ! -f "$1" ]; then |
| 36 | echo "Unable to locate $1" |
| 37 | exit |
| 38 | fi; |
| 39 | } |
| 40 | |
| 41 | checkPath java |
| 42 | |
| 43 | # check java version |
| 44 | java_version_string=$(java -version 2>&1) |
Moon Kim | 141e49f | 2015-07-09 10:19:32 -0700 | [diff] [blame] | 45 | JAVA_VERSION=$(echo "$java_version_string" | grep '[ "]1\.[78][\. "$$]') |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 46 | if [ "${JAVA_VERSION}" == "" ]; then |
Moon Kim | 141e49f | 2015-07-09 10:19:32 -0700 | [diff] [blame] | 47 | echo "Wrong java version. 1.7 or 1.8 is required." |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 48 | exit |
| 49 | fi |
| 50 | |
| 51 | # check debug flag and set up remote debugging |
| 52 | if [ -n "${TF_DEBUG}" ]; then |
| 53 | if [ -z "${TF_DEBUG_PORT}" ]; then |
| 54 | TF_DEBUG_PORT=10088 |
| 55 | fi |
| 56 | RDBG_FLAG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${TF_DEBUG_PORT}" |
| 57 | fi |
| 58 | |
| 59 | # first try to find TF jars in same dir as this script |
| 60 | CUR_DIR=$(dirname "$0") |
Julien Desprez | 5f39044 | 2015-11-20 23:20:44 +0000 | [diff] [blame] | 61 | TF_JAR_DIR=$(dirname "$0") |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 62 | if [ -f "${CUR_DIR}/tradefed.jar" ]; then |
| 63 | TF_PATH="${CUR_DIR}/*" |
| 64 | elif [ ! -z "${ANDROID_HOST_OUT}" ]; then |
| 65 | # in an Android build env, tradefed.jar should be in |
| 66 | # $ANDROID_HOST_OUT/tradefed/ |
| 67 | if [ -f "${ANDROID_HOST_OUT}/tradefed/tradefed.jar" ]; then |
| 68 | # We intentionally pass the asterisk through without shell expansion |
| 69 | TF_PATH="${ANDROID_HOST_OUT}/tradefed/*" |
Julien Desprez | 5f39044 | 2015-11-20 23:20:44 +0000 | [diff] [blame] | 70 | TF_JAR_DIR="${ANDROID_HOST_OUT}/tradefed/" |
Omari Stephens | 6e3c34d | 2015-04-14 18:40:33 -0700 | [diff] [blame] | 71 | fi |
| 72 | fi |
| 73 | |
| 74 | if [ -z "${TF_PATH}" ]; then |
| 75 | echo "ERROR: Could not find tradefed jar files" |
| 76 | exit |
| 77 | fi |
| 78 | |
| 79 | # set any host specific options |
| 80 | # file format for file at $TRADEFED_OPTS_FILE is one line per host with the following format: |
| 81 | # <hostname>=<options> |
| 82 | # for example: |
| 83 | # hostname.domain.com=-Djava.io.tmpdir=/location/on/disk -Danother=false ... |
| 84 | # hostname2.domain.com=-Djava.io.tmpdir=/different/location -Danother=true ... |
| 85 | if [ -e "${TRADEFED_OPTS_FILE}" ]; then |
| 86 | # pull the line for this host and take everything after the first = |
| 87 | export TRADEFED_OPTS=`grep "^$HOSTNAME=" "$TRADEFED_OPTS_FILE" | cut -d '=' -f 2-` |
| 88 | fi |