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 | |
Mathieu Chartier | 6b63d88 | 2019-07-15 14:23:24 -0700 | [diff] [blame] | 17 | if [[ ${#@} != 1 ]] && [[ ${#@} != 2 ]]; then |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 18 | cat <<EOF |
| 19 | Usage |
Mathieu Chartier | 6b63d88 | 2019-07-15 14:23:24 -0700 | [diff] [blame] | 20 | host_bcp <image> [--use-first-dir] | xargs <art-host-tool> ... |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 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 |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 25 | and existing \$ANDROID_PRODUCT_OUT/apex/com.android.art* paths. |
Mathieu Chartier | 6b63d88 | 2019-07-15 14:23:24 -0700 | [diff] [blame] | 26 | If --use-first-dir is specified, the script will use the first apex dir instead |
| 27 | of resulting in an error. |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 28 | EOF |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | IMAGE=$1 |
Mathieu Chartier | 6b63d88 | 2019-07-15 14:23:24 -0700 | [diff] [blame] | 33 | USE_FIRST_DIR=false |
| 34 | |
| 35 | if [[ $2 == "--use-first-dir" ]]; then |
| 36 | USE_FIRST_DIR=true |
| 37 | fi |
| 38 | |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 39 | if [[ ! -e ${IMAGE} ]]; then |
Vladimir Marko | 7107e8c | 2019-06-25 11:18:03 +0100 | [diff] [blame] | 40 | IMAGE=${ANDROID_PRODUCT_OUT}/$1 |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 41 | if [[ ! -e ${IMAGE} ]]; then |
Vladimir Marko | 7107e8c | 2019-06-25 11:18:03 +0100 | [diff] [blame] | 42 | echo "Neither $1 nor ${ANDROID_PRODUCT_OUT}/$1 exists." |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 43 | exit 1 |
| 44 | fi |
| 45 | fi |
| 46 | BCPL=`grep -az -A1 -E '^bootclasspath$' ${IMAGE} 2>/dev/null | \ |
| 47 | xargs -0 echo | gawk '{print $2}'` |
| 48 | if [[ "x${BCPL}" == "x" ]]; then |
| 49 | echo "Failed to extract boot class path locations from $1." |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
Vladimir Marko | 7107e8c | 2019-06-25 11:18:03 +0100 | [diff] [blame] | 53 | MANIFEST=/apex_manifest.json |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 54 | ART_APEX=/apex/com.android.art |
| 55 | ART_APEX_SELECTED= |
| 56 | for m in `ls -1 -d ${ANDROID_PRODUCT_OUT}{,/system}${ART_APEX}*${MANIFEST} 2>/dev/null`; do |
Vladimir Marko | 7107e8c | 2019-06-25 11:18:03 +0100 | [diff] [blame] | 57 | d=${m:0:-${#MANIFEST}} |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 58 | if [[ "x${ART_APEX_SELECTED}" != "x" ]]; then |
Mathieu Chartier | 6b63d88 | 2019-07-15 14:23:24 -0700 | [diff] [blame] | 59 | if [[ $USE_FIRST_DIR == true ]]; then |
| 60 | break |
| 61 | fi |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 62 | echo "Multiple ART APEX dirs: ${ART_APEX_SELECTED}, ${d}." |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 63 | exit 1 |
| 64 | fi |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 65 | ART_APEX_SELECTED=${d} |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 66 | done |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 67 | if [[ "x${ART_APEX_SELECTED}" == "x" ]]; then |
Martin Stjernholm | e58624f | 2019-09-20 15:53:40 +0100 | [diff] [blame] | 68 | echo "No ART APEX dir." |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | BCP= |
| 73 | OLD_IFS=${IFS} |
| 74 | IFS=: |
| 75 | for COMPONENT in ${BCPL}; do |
| 76 | HEAD=${ANDROID_PRODUCT_OUT} |
| 77 | TAIL=${COMPONENT} |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 78 | if [[ ${COMPONENT:0:${#ART_APEX}} = ${ART_APEX} ]]; then |
| 79 | HEAD=${ART_APEX_SELECTED} |
| 80 | TAIL=${COMPONENT:${#ART_APEX}} |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 81 | fi |
Vladimir Marko | 7107e8c | 2019-06-25 11:18:03 +0100 | [diff] [blame] | 82 | if [[ ! -e $HEAD$TAIL ]]; then |
| 83 | echo "File does not exist: $HEAD$TAIL" |
| 84 | exit 1 |
| 85 | fi |
Vladimir Marko | e660f72 | 2019-03-29 13:09:28 +0000 | [diff] [blame] | 86 | BCP="${BCP}:${HEAD}${TAIL}" |
| 87 | done |
| 88 | IFS=${OLD_IFS} |
| 89 | BCP=${BCP:1} # Strip leading ':'. |
| 90 | |
| 91 | echo --runtime-arg -Xbootclasspath:${BCP} \ |
| 92 | --runtime-arg -Xbootclasspath-locations:${BCPL} |