blob: 010307177ef7153c085897d0fdf32e94580ac53f [file] [log] [blame]
Nicolas Geoffrayd2f6f772014-03-17 18:26:00 +00001#!/bin/bash
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002#
3# Copyright (C) 2011 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
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000017function follow_links() {
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010018 if [ z"$BASH_SOURCE" != z ]; then
19 file="$BASH_SOURCE"
20 else
21 file="$0"
22 fi
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000023 while [ -h "$file" ]; do
24 # On Mac OS, readlink -f doesn't work.
25 file="$(readlink "$file")"
26 done
27 echo "$file"
28}
29
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010030function find_libdir() {
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070031 if [ "$(readlink "$ANDROID_ROOT/bin/$DALVIKVM")" = "dalvikvm64" ]; then
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010032 echo "lib64"
33 else
34 echo "lib"
35 fi
36}
37
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010038invoke_with=
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070039DALVIKVM=dalvikvm
40LIBART=libart.so
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010041
42while true; do
43 if [ "$1" = "--invoke-with" ]; then
44 shift
45 invoke_with="$1"
46 shift
47 elif [ "$1" = "-d" ]; then
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070048 LIBART="libartd.so"
49 shift
50 elif [ "$1" = "--32" ]; then
51 DALVIKVM=dalvikvm32
52 shift
53 elif [ "$1" = "--64" ]; then
54 DALVIKVM=dalvikvm64
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010055 shift
56 elif expr "$1" : "--" >/dev/null 2>&1; then
57 echo "unknown option: $1" 1>&2
58 exit 1
59 else
60 break
61 fi
62done
63
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070064PROG_NAME="$(follow_links)"
65PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
66ANDROID_ROOT=$PROG_DIR/..
67ANDROID_DATA=$PWD/android-data$$
68LIBDIR=$(find_libdir)
69LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
70
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010071mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64}
Nicolas Geoffray89c4e282014-03-24 09:33:30 +000072ANDROID_DATA=$ANDROID_DATA \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010073 ANDROID_ROOT=$ANDROID_ROOT \
Nicolas Geoffrayfc3c67a2014-07-02 14:57:53 +010074 LD_LIBRARY_PATH=$LD_LIBRARY_PATH \
Brian Carlstrom87bb26f2014-09-08 11:13:47 -070075 $invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \
76 -XXlib:$LIBART \
Nicolas Geoffrayf63a0a52014-09-02 15:24:25 +010077 -Ximage:$ANDROID_ROOT/framework/core.art \
Elliott Hughesaddf1a82013-02-19 10:50:50 -080078 "$@"
Nicolas Geoffray89c4e282014-03-24 09:33:30 +000079EXIT_STATUS=$?
80rm -rf $ANDROID_DATA
81exit $EXIT_STATUS