1 #!/usr/bin/env bash 2 3 # Copyright (C) 2016 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 18 19 ### 20 ### Change the BOOTCLASSPATH to pick up bootlib classes. 21 ### Export ANDROID_DATA=something else (it should have dalvik-cache dir in it) 22 ### Point the image to something else that's not existing. 23 ### 24 ### Actually run dalvikvm now... 25 ### 26 27 if [[ -z $ANDROID_BUILD_TOP ]]; then 28 echo "Run source build/envsetup.sh first" >& 2 29 exit 1 30 fi 31 32 invoke_with= 33 DALVIKVM=dalvikvm 34 LIBART=libart.so 35 36 function follow_links() { 37 if [ z"$BASH_SOURCE" != z ]; then 38 file="$BASH_SOURCE" 39 else 40 file="$0" 41 fi 42 while [ -h "$file" ]; do 43 # On Mac OS, readlink -f doesn't work. 44 file="$(readlink "$file")" 45 done 46 echo "$file" 47 } 48 49 function find_libdir() { 50 # Use realpath instead of readlink because Android does not have a readlink. 51 if [ "$(realpath "$ANDROID_ROOT/bin/$DALVIKVM")" = "$(realpath "$ANDROID_ROOT/bin/dalvikvm64")" ]; then 52 echo "lib64" 53 else 54 echo "lib" 55 fi 56 } 57 58 function join { local IFS="$1"; shift; echo "$*"; } 59 60 PROG_NAME="$(follow_links)" 61 PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" 62 63 if [[ -z $ANDROID_ROOT ]]; then 64 # Already set to /system for actual android devices 65 ANDROID_ROOT="$ANDROID_HOST_OUT" 66 fi 67 LIBDIR="$(find_libdir)" 68 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBDIR" 69 DEBUG_OPTION="" 70 71 DELETE_ANDROID_DATA=false 72 # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own, 73 # and ensure we delete it at the end. 74 if [ "$ANDROID_DATA" = "/data" ] || [ "$ANDROID_DATA" = "" ]; then 75 # TODO: use /data/tmp/... for android, and mktemp for host 76 #ANDROID_DATA=$PWD/android-data$$ 77 ANDROID_DATA="$(mktemp -q -d -t "$(basename "$0").XXXXXX")" 78 IMAGE_DIRECTORY="$ANDROID_DATA/image" 79 mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64} 80 mkdir -p $IMAGE_DIRECTORY 81 DELETE_ANDROID_DATA=true 82 fi 83 84 # Clean up the temporary files we made earlier on. 85 function finish { 86 if $DELETE_ANDROID_DATA; then 87 [[ -d $ANDROID_DATA ]] && rm -rf "$ANDROID_DATA" 88 fi 89 } 90 91 trap finish EXIT 92 93 # Dummy image location name. Art ignores the bootclasspath setting if a boot image 94 # already exists, so we force it to create a new boot image with our correct bootclasspath. 95 IMAGE_LOCATION="$IMAGE_DIRECTORY/core-extrabootclasspath.art" 96 97 # TODO: Get this list from somewhere else, a makefile perhaps? 98 BOOT_DEXJARS=( 99 bouncycastle-hostdex.jar 100 apache-xml-hostdex.jar 101 core-tests-hostdex.jar 102 core-libart-hostdex.jar 103 core-lambda-stubs-hostdex.jar 104 conscrypt-hostdex.jar 105 core-ojtests-hostdex.jar # This is the *one* addition that makes our OJ tests actually run. The rest of these are standard jars on the bootclasspath. 106 core-oj-hostdex.jar 107 okhttp-hostdex.jar) 108 109 BOOT_DEXJAR_PREFIX="$ANDROID_ROOT/framework" 110 111 BOOT_DEXJARS_ABS=() 112 for dexjar in ${BOOT_DEXJARS[@]}; do 113 BOOT_DEXJARS_ABS=(${BOOT_DEXJARS_ABS[@]} $BOOT_DEXJAR_PREFIX/$dexjar) 114 done 115 116 export BOOTCLASSPATH=$(join ":" "${BOOT_DEXJARS_ABS[@]}") # a,b,c 117 118 echo "BOOTCLASSPATH=$BOOTCLASSPATH" 119 echo "PROG_NAME=$PROG_NAME" 120 echo "PROG_DIR=$PROG_DIR" 121 echo "ANDROID_ROOT=$ANDROID_ROOT" 122 echo "LIBDIR=$LIBDIR" 123 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" 124 echo "DEBUG_OPTION=$DEBUG_OPTION" 125 126 echo "export BOOTCLASSPATH=$BOOTCLASSPATH" 127 echo export ANDROID_ROOT="$ANDROID_ROOT" 128 ANDROID_DATA=$ANDROID_DATA \ 129 ANDROID_ROOT=$ANDROID_ROOT \ 130 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \ 131 PATH=$ANDROID_ROOT/bin:$PATH \ 132 LD_USE_LOAD_BIAS=1 \ 133 $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \ 134 -XXlib:$LIBART \ 135 -Xnorelocate \ 136 -Ximage:$IMAGE_LOCATION \ 137 $DEBUG_OPTION \ 138 "$@" 139 140 141 temp_dir="$(mktemp -q -d -t "$(basename "$0").XXXXXX")" 142