1#!/bin/bash 2# 3# Copyright (C) 2022 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# This file contains utils for constructing -Xbootclasspath and -Xbootclasspath-location 18# for dex2oat and dalvikvm from apex modules list. 19# 20# Those utils could be used outside of art/test/ to run ART in chroot setup. 21 22# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk 23# because that's what we use for compiling the boot.art image. 24# It may contain additional modules from TEST_CORE_JARS. 25readonly bpath_modules="core-oj core-libart okhttp bouncycastle apache-xml core-icu4j conscrypt" 26 27# Helper function to construct paths for apex modules (for both -Xbootclasspath and 28# -Xbootclasspath-location). 29# 30# Arguments. 31# ${1}: path prefix. 32get_apex_bootclasspath_impl() { 33 local -r bpath_prefix="$1" 34 local bpath_separator="" 35 local bpath="" 36 local bpath_jar="" 37 for bpath_module in ${bpath_modules}; do 38 local apex_module="com.android.art" 39 case "$bpath_module" in 40 (conscrypt) apex_module="com.android.conscrypt";; 41 (core-icu4j) apex_module="com.android.i18n";; 42 (*) apex_module="com.android.art";; 43 esac 44 bpath_jar="/apex/${apex_module}/javalib/${bpath_module}.jar" 45 bpath+="${bpath_separator}${bpath_prefix}${bpath_jar}" 46 bpath_separator=":" 47 done 48 echo "${bpath}" 49} 50 51# Gets a -Xbootclasspath paths with the apex modules. 52# 53# Arguments. 54# ${1}: host (y|n). 55get_apex_bootclasspath() { 56 local -r host="${1}" 57 local bpath_prefix="" 58 59 if [[ "${host}" == "y" ]]; then 60 bpath_prefix="${ANDROID_HOST_OUT}" 61 fi 62 63 get_apex_bootclasspath_impl "${bpath_prefix}" 64} 65 66# Gets a -Xbootclasspath-location paths with the apex modules. 67# 68# Arguments. 69# ${1}: host (y|n). 70get_apex_bootclasspath_locations() { 71 local -r host="${1}" 72 local bpath_location_prefix="" 73 74 if [[ "${host}" == "y" ]]; then 75 if [[ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" == "${ANDROID_BUILD_TOP}/" ]]; then 76 bpath_location_prefix="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}" 77 else 78 error_msg "ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"\ 79 "\nANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"\ 80 "\nANDROID_HOST_OUT=${ANDROID_HOST_OUT}" 81 exit 82 fi 83 fi 84 85 get_apex_bootclasspath_impl "${bpath_location_prefix}" 86} 87