1*795d594fSAndroid Build Coastguard Worker#!/bin/bash 2*795d594fSAndroid Build Coastguard Worker# 3*795d594fSAndroid Build Coastguard Worker# Copyright 2019 The Android Open Source Project 4*795d594fSAndroid Build Coastguard Worker# 5*795d594fSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*795d594fSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*795d594fSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*795d594fSAndroid Build Coastguard Worker# 9*795d594fSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*795d594fSAndroid Build Coastguard Worker# 11*795d594fSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*795d594fSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*795d594fSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*795d594fSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*795d594fSAndroid Build Coastguard Worker# limitations under the License. 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Workerif [[ ${#@} != 1 ]]; then 18*795d594fSAndroid Build Coastguard Worker cat <<EOF 19*795d594fSAndroid Build Coastguard WorkerUsage 20*795d594fSAndroid Build Coastguard Worker host_bcp <image> | xargs <art-host-tool> ... 21*795d594fSAndroid Build Coastguard WorkerExtracts boot class path locations from <image> and outputs the appropriate 22*795d594fSAndroid Build Coastguard Worker --runtime-arg -Xbootclasspath:... 23*795d594fSAndroid Build Coastguard Worker --runtime-arg -Xbootclasspath-locations:... 24*795d594fSAndroid Build Coastguard Workerarguments for many ART host tools based on the \$ANDROID_PRODUCT_OUT variable 25*795d594fSAndroid Build Coastguard Workerand existing \$ANDROID_PRODUCT_OUT/apex/* paths. 26*795d594fSAndroid Build Coastguard WorkerEOF 27*795d594fSAndroid Build Coastguard Worker exit 1 28*795d594fSAndroid Build Coastguard Workerfi 29*795d594fSAndroid Build Coastguard Worker 30*795d594fSAndroid Build Coastguard WorkerIMAGE=$1 31*795d594fSAndroid Build Coastguard Worker 32*795d594fSAndroid Build Coastguard Workerif [[ ! -e ${IMAGE} ]]; then 33*795d594fSAndroid Build Coastguard Worker IMAGE=${ANDROID_PRODUCT_OUT}/$1 34*795d594fSAndroid Build Coastguard Worker if [[ ! -e ${IMAGE} ]]; then 35*795d594fSAndroid Build Coastguard Worker echo "Neither $1 nor ${ANDROID_PRODUCT_OUT}/$1 exists." 36*795d594fSAndroid Build Coastguard Worker exit 1 37*795d594fSAndroid Build Coastguard Worker fi 38*795d594fSAndroid Build Coastguard Workerfi 39*795d594fSAndroid Build Coastguard WorkerBCPL=`grep -az -A1 -E '^bootclasspath$' ${IMAGE} 2>/dev/null | \ 40*795d594fSAndroid Build Coastguard Worker xargs -0 echo | gawk '{print $2}'` 41*795d594fSAndroid Build Coastguard Workerif [[ "x${BCPL}" == "x" ]]; then 42*795d594fSAndroid Build Coastguard Worker echo "Failed to extract boot class path locations from $1." 43*795d594fSAndroid Build Coastguard Worker exit 1 44*795d594fSAndroid Build Coastguard Workerfi 45*795d594fSAndroid Build Coastguard Worker 46*795d594fSAndroid Build Coastguard WorkerAPEX_INFO_LIST=${ANDROID_PRODUCT_OUT}/apex/apex-info-list.xml 47*795d594fSAndroid Build Coastguard Workerif [[ ! -e ${APEX_INFO_LIST} ]]; then 48*795d594fSAndroid Build Coastguard Worker echo "Failed to locate apex info at ${APEX_INFO_LIST}." 49*795d594fSAndroid Build Coastguard Worker exit 1 50*795d594fSAndroid Build Coastguard Workerfi 51*795d594fSAndroid Build Coastguard Worker 52*795d594fSAndroid Build Coastguard WorkerBCP= 53*795d594fSAndroid Build Coastguard WorkerOLD_IFS=${IFS} 54*795d594fSAndroid Build Coastguard WorkerIFS=: 55*795d594fSAndroid Build Coastguard WorkerAPEX_PREFIX=/apex/ 56*795d594fSAndroid Build Coastguard Workerfor COMPONENT in ${BCPL}; do 57*795d594fSAndroid Build Coastguard Worker HEAD=${ANDROID_PRODUCT_OUT} 58*795d594fSAndroid Build Coastguard Worker TAIL=${COMPONENT} 59*795d594fSAndroid Build Coastguard Worker # Apex module paths aren't symlinked on the host, so map from the symbolic 60*795d594fSAndroid Build Coastguard Worker # device path to the prebuilt (host) module path using the apex info table. 61*795d594fSAndroid Build Coastguard Worker if [[ ${COMPONENT:0:${#APEX_PREFIX}} = ${APEX_PREFIX} ]]; then 62*795d594fSAndroid Build Coastguard Worker # First extract the symbolic module name and its (internal) jar path. 63*795d594fSAndroid Build Coastguard Worker COMPONENT=${COMPONENT#${APEX_PREFIX}} 64*795d594fSAndroid Build Coastguard Worker MODULE_NAME=${COMPONENT%%/*} 65*795d594fSAndroid Build Coastguard Worker MODULE_JAR=${COMPONENT#*/} 66*795d594fSAndroid Build Coastguard Worker # Use the module name to look up the preinstalled module path.. 67*795d594fSAndroid Build Coastguard Worker HOST_MODULE=`xmllint --xpath "string(//apex-info[@moduleName=\"${MODULE_NAME}\"]/@preinstalledModulePath)" ${APEX_INFO_LIST}` 68*795d594fSAndroid Build Coastguard Worker # Extract the preinstalled module name from the full path (strip prefix/suffix). 69*795d594fSAndroid Build Coastguard Worker HOST_MODULE_NAME=${HOST_MODULE#*${APEX_PREFIX}} 70*795d594fSAndroid Build Coastguard Worker HOST_MODULE_NAME=${HOST_MODULE_NAME%.*apex} 71*795d594fSAndroid Build Coastguard Worker # Rebuild the host path using the preinstalled module name. 72*795d594fSAndroid Build Coastguard Worker TAIL="${APEX_PREFIX}${HOST_MODULE_NAME}/${MODULE_JAR}" 73*795d594fSAndroid Build Coastguard Worker fi 74*795d594fSAndroid Build Coastguard Worker if [[ ! -e $HEAD$TAIL ]]; then 75*795d594fSAndroid Build Coastguard Worker echo "File does not exist: $HEAD$TAIL" 76*795d594fSAndroid Build Coastguard Worker exit 1 77*795d594fSAndroid Build Coastguard Worker fi 78*795d594fSAndroid Build Coastguard Worker BCP="${BCP}:${HEAD}${TAIL}" 79*795d594fSAndroid Build Coastguard Workerdone 80*795d594fSAndroid Build Coastguard WorkerIFS=${OLD_IFS} 81*795d594fSAndroid Build Coastguard WorkerBCP=${BCP:1} # Strip leading ':'. 82*795d594fSAndroid Build Coastguard Worker 83*795d594fSAndroid Build Coastguard Workerecho --runtime-arg -Xbootclasspath:${BCP} \ 84*795d594fSAndroid Build Coastguard Worker --runtime-arg -Xbootclasspath-locations:${BCPL} 85