blob: 26231cdca19e4aed1ec2edf96e7c898ec4a20851 [file] [log] [blame]
Vladimir Markoe660f722019-03-29 13:09:28 +00001#!/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 Chartier6b63d882019-07-15 14:23:24 -070017if [[ ${#@} != 1 ]] && [[ ${#@} != 2 ]]; then
Vladimir Markoe660f722019-03-29 13:09:28 +000018 cat <<EOF
19Usage
Mathieu Chartier6b63d882019-07-15 14:23:24 -070020 host_bcp <image> [--use-first-dir] | xargs <art-host-tool> ...
Vladimir Markoe660f722019-03-29 13:09:28 +000021Extracts boot class path locations from <image> and outputs the appropriate
22 --runtime-arg -Xbootclasspath:...
23 --runtime-arg -Xbootclasspath-locations:...
24arguments for many ART host tools based on the \$ANDROID_PRODUCT_OUT variable
Martin Stjernholmad909af2019-07-16 17:02:44 +010025and existing \$ANDROID_PRODUCT_OUT/apex/com.android.art* paths.
Mathieu Chartier6b63d882019-07-15 14:23:24 -070026If --use-first-dir is specified, the script will use the first apex dir instead
27of resulting in an error.
Vladimir Markoe660f722019-03-29 13:09:28 +000028EOF
29 exit 1
30fi
31
32IMAGE=$1
Mathieu Chartier6b63d882019-07-15 14:23:24 -070033USE_FIRST_DIR=false
34
35if [[ $2 == "--use-first-dir" ]]; then
36 USE_FIRST_DIR=true
37fi
38
Vladimir Markoe660f722019-03-29 13:09:28 +000039if [[ ! -e ${IMAGE} ]]; then
Vladimir Marko7107e8c2019-06-25 11:18:03 +010040 IMAGE=${ANDROID_PRODUCT_OUT}/$1
Vladimir Markoe660f722019-03-29 13:09:28 +000041 if [[ ! -e ${IMAGE} ]]; then
Vladimir Marko7107e8c2019-06-25 11:18:03 +010042 echo "Neither $1 nor ${ANDROID_PRODUCT_OUT}/$1 exists."
Vladimir Markoe660f722019-03-29 13:09:28 +000043 exit 1
44 fi
45fi
46BCPL=`grep -az -A1 -E '^bootclasspath$' ${IMAGE} 2>/dev/null | \
47 xargs -0 echo | gawk '{print $2}'`
48if [[ "x${BCPL}" == "x" ]]; then
49 echo "Failed to extract boot class path locations from $1."
50 exit 1
51fi
52
Jooyung Hanafaa4572019-11-12 13:03:50 +090053MANIFEST=/apex_manifest.pb
Martin Stjernholmad909af2019-07-16 17:02:44 +010054ART_APEX=/apex/com.android.art
55ART_APEX_SELECTED=
56for m in `ls -1 -d ${ANDROID_PRODUCT_OUT}{,/system}${ART_APEX}*${MANIFEST} 2>/dev/null`; do
Vladimir Marko7107e8c2019-06-25 11:18:03 +010057 d=${m:0:-${#MANIFEST}}
Martin Stjernholmad909af2019-07-16 17:02:44 +010058 if [[ "x${ART_APEX_SELECTED}" != "x" ]]; then
Mathieu Chartier6b63d882019-07-15 14:23:24 -070059 if [[ $USE_FIRST_DIR == true ]]; then
60 break
61 fi
Martin Stjernholme58624f2019-09-20 15:53:40 +010062 echo "Multiple ART APEX dirs: ${ART_APEX_SELECTED}, ${d}."
Vladimir Markoe660f722019-03-29 13:09:28 +000063 exit 1
64 fi
Martin Stjernholmad909af2019-07-16 17:02:44 +010065 ART_APEX_SELECTED=${d}
Vladimir Markoe660f722019-03-29 13:09:28 +000066done
Martin Stjernholmad909af2019-07-16 17:02:44 +010067if [[ "x${ART_APEX_SELECTED}" == "x" ]]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +010068 echo "No ART APEX dir."
Vladimir Markoe660f722019-03-29 13:09:28 +000069 exit 1
70fi
71
72BCP=
73OLD_IFS=${IFS}
74IFS=:
75for COMPONENT in ${BCPL}; do
76 HEAD=${ANDROID_PRODUCT_OUT}
77 TAIL=${COMPONENT}
Martin Stjernholmad909af2019-07-16 17:02:44 +010078 if [[ ${COMPONENT:0:${#ART_APEX}} = ${ART_APEX} ]]; then
79 HEAD=${ART_APEX_SELECTED}
80 TAIL=${COMPONENT:${#ART_APEX}}
Vladimir Markoe660f722019-03-29 13:09:28 +000081 fi
Vladimir Marko7107e8c2019-06-25 11:18:03 +010082 if [[ ! -e $HEAD$TAIL ]]; then
83 echo "File does not exist: $HEAD$TAIL"
84 exit 1
85 fi
Vladimir Markoe660f722019-03-29 13:09:28 +000086 BCP="${BCP}:${HEAD}${TAIL}"
87done
88IFS=${OLD_IFS}
89BCP=${BCP:1} # Strip leading ':'.
90
91echo --runtime-arg -Xbootclasspath:${BCP} \
92 --runtime-arg -Xbootclasspath-locations:${BCPL}