Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2019 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 | if [[ ${#@} != 1 ]]; then |
| 18 | cat <<EOF |
| 19 | Usage |
| 20 | host_bcp <image> | xargs <art-host-tool> ... |
| 21 | Extracts boot class path locations from <image> and outputs the appropriate |
| 22 | --runtime-arg -Xbootclasspath:... |
| 23 | --runtime-arg -Xbootclasspath-locations:... |
| 24 | arguments for many ART host tools based on the \$ANDROID_PRODUCT_OUT variable |
| 25 | and existing \$ANDROID_PRODUCT_OUT/apex/com.android.runtime* paths. |
| 26 | EOF |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | IMAGE=$1 |
| 31 | if [[ ! -e ${IMAGE} ]]; then |
| 32 | IMAGE=${ANDROID_PRODUCT_OUT}$1 |
| 33 | if [[ ! -e ${IMAGE} ]]; then |
| 34 | echo "Neither $1 nor ${ANDROID_PRODUCT_OUT}$1 exists." |
| 35 | exit 1 |
| 36 | fi |
| 37 | fi |
| 38 | BCPL=`grep -az -A1 -E '^bootclasspath$' ${IMAGE} 2>/dev/null | \ |
| 39 | xargs -0 echo | gawk '{print $2}'` |
| 40 | if [[ "x${BCPL}" == "x" ]]; then |
| 41 | echo "Failed to extract boot class path locations from $1." |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | RUNTIME_APEX=/apex/com.android.runtime |
| 46 | RUNTIME_APEX_SELECTED= |
| 47 | for d in `ls -1 -d ${ANDROID_PRODUCT_OUT}${RUNTIME_APEX}* 2>/dev/null`; do |
| 48 | if [[ "x${RUNTIME_APEX_SELECTED}" != "x" ]]; then |
| 49 | echo "Multiple Runtime apex dirs: ${RUNTIME_APEX_SELECTED}, ${d}." |
| 50 | exit 1 |
| 51 | fi |
| 52 | RUNTIME_APEX_SELECTED=${d} |
| 53 | done |
| 54 | if [[ "x${RUNTIME_APEX_SELECTED}" == "x" ]]; then |
| 55 | echo "No Runtime apex dir." |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | BCP= |
| 60 | OLD_IFS=${IFS} |
| 61 | IFS=: |
| 62 | for COMPONENT in ${BCPL}; do |
| 63 | HEAD=${ANDROID_PRODUCT_OUT} |
| 64 | TAIL=${COMPONENT} |
| 65 | if [[ ${COMPONENT:0:${#RUNTIME_APEX}} = ${RUNTIME_APEX} ]]; then |
| 66 | HEAD=${RUNTIME_APEX_SELECTED} |
| 67 | TAIL=${COMPONENT:${#RUNTIME_APEX}} |
| 68 | fi |
| 69 | BCP="${BCP}:${HEAD}${TAIL}" |
| 70 | done |
| 71 | IFS=${OLD_IFS} |
| 72 | BCP=${BCP:1} # Strip leading ':'. |
| 73 | |
| 74 | echo --runtime-arg -Xbootclasspath:${BCP} \ |
| 75 | --runtime-arg -Xbootclasspath-locations:${BCPL} |