• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17if [[ ${#@} != 1 ]]; then
18  cat <<EOF
19Usage
20  host_bcp <image> | xargs <art-host-tool> ...
21Extracts 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
25and existing \$ANDROID_PRODUCT_OUT/apex/* paths.
26EOF
27  exit 1
28fi
29
30IMAGE=$1
31
32if [[ ! -e ${IMAGE} ]]; then
33  IMAGE=${ANDROID_PRODUCT_OUT}/$1
34  if [[ ! -e ${IMAGE} ]]; then
35    echo "Neither $1 nor ${ANDROID_PRODUCT_OUT}/$1 exists."
36    exit 1
37  fi
38fi
39BCPL=`grep -az -A1 -E '^bootclasspath$' ${IMAGE} 2>/dev/null | \
40      xargs -0 echo | gawk '{print $2}'`
41if [[ "x${BCPL}" == "x" ]]; then
42  echo "Failed to extract boot class path locations from $1."
43  exit 1
44fi
45
46APEX_INFO_LIST=${ANDROID_PRODUCT_OUT}/apex/apex-info-list.xml
47if [[ ! -e ${APEX_INFO_LIST} ]]; then
48  echo "Failed to locate apex info at ${APEX_INFO_LIST}."
49  exit 1
50fi
51
52BCP=
53OLD_IFS=${IFS}
54IFS=:
55APEX_PREFIX=/apex/
56for COMPONENT in ${BCPL}; do
57  HEAD=${ANDROID_PRODUCT_OUT}
58  TAIL=${COMPONENT}
59  # Apex module paths aren't symlinked on the host, so map from the symbolic
60  # device path to the prebuilt (host) module path using the apex info table.
61  if [[ ${COMPONENT:0:${#APEX_PREFIX}} = ${APEX_PREFIX} ]]; then
62    # First extract the symbolic module name and its (internal) jar path.
63    COMPONENT=${COMPONENT#${APEX_PREFIX}}
64    MODULE_NAME=${COMPONENT%%/*}
65    MODULE_JAR=${COMPONENT#*/}
66    # Use the module name to look up the preinstalled module path..
67    HOST_MODULE=`xmllint --xpath "string(//apex-info[@moduleName=\"${MODULE_NAME}\"]/@preinstalledModulePath)" ${APEX_INFO_LIST}`
68    # Extract the preinstalled module name from the full path (strip prefix/suffix).
69    HOST_MODULE_NAME=${HOST_MODULE#*${APEX_PREFIX}}
70    HOST_MODULE_NAME=${HOST_MODULE_NAME%.*apex}
71    # Rebuild the host path using the preinstalled module name.
72    TAIL="${APEX_PREFIX}${HOST_MODULE_NAME}/${MODULE_JAR}"
73  fi
74  if [[ ! -e $HEAD$TAIL ]]; then
75    echo "File does not exist: $HEAD$TAIL"
76    exit 1
77  fi
78  BCP="${BCP}:${HEAD}${TAIL}"
79done
80IFS=${OLD_IFS}
81BCP=${BCP:1}  # Strip leading ':'.
82
83echo --runtime-arg -Xbootclasspath:${BCP} \
84     --runtime-arg -Xbootclasspath-locations:${BCPL}
85