1*344a7f5eSAndroid Build Coastguard Worker#!/bin/bash 2*344a7f5eSAndroid Build Coastguard Worker# 3*344a7f5eSAndroid Build Coastguard Worker# Copyright (C) 2017 The Android Open Source Project 4*344a7f5eSAndroid Build Coastguard Worker# 5*344a7f5eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*344a7f5eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*344a7f5eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*344a7f5eSAndroid Build Coastguard Worker# 9*344a7f5eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*344a7f5eSAndroid Build Coastguard Worker# 11*344a7f5eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*344a7f5eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*344a7f5eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*344a7f5eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*344a7f5eSAndroid Build Coastguard Worker# limitations under the License. 16*344a7f5eSAndroid Build Coastguard Worker 17*344a7f5eSAndroid Build Coastguard Worker# Set up prog to be the path of this script, including following symlinks, 18*344a7f5eSAndroid Build Coastguard Worker# and set up progdir to be the fully-qualified pathname of its directory. 19*344a7f5eSAndroid Build Coastguard Workerprog="$0" 20*344a7f5eSAndroid Build Coastguard Workerwhile [ -h "${prog}" ]; do 21*344a7f5eSAndroid Build Coastguard Worker newProg=`/bin/ls -ld "${prog}"` 22*344a7f5eSAndroid Build Coastguard Worker newProg=`expr "${newProg}" : ".* -> \(.*\)$"` 23*344a7f5eSAndroid Build Coastguard Worker if expr "x${newProg}" : 'x/' >/dev/null; then 24*344a7f5eSAndroid Build Coastguard Worker prog="${newProg}" 25*344a7f5eSAndroid Build Coastguard Worker else 26*344a7f5eSAndroid Build Coastguard Worker progdir=`dirname "${prog}"` 27*344a7f5eSAndroid Build Coastguard Worker prog="${progdir}/${newProg}" 28*344a7f5eSAndroid Build Coastguard Worker fi 29*344a7f5eSAndroid Build Coastguard Workerdone 30*344a7f5eSAndroid Build Coastguard Workeroldwd=`pwd` 31*344a7f5eSAndroid Build Coastguard Workerprogdir=`dirname "${prog}"` 32*344a7f5eSAndroid Build Coastguard Workercd "${progdir}" 33*344a7f5eSAndroid Build Coastguard Workerprogdir=`pwd` 34*344a7f5eSAndroid Build Coastguard Workerprog="${progdir}"/`basename "${prog}"` 35*344a7f5eSAndroid Build Coastguard Workercd "${oldwd}" 36*344a7f5eSAndroid Build Coastguard Worker 37*344a7f5eSAndroid Build Coastguard Workerjarfile=d8.jar 38*344a7f5eSAndroid Build Coastguard Workerlibdir="$progdir" 39*344a7f5eSAndroid Build Coastguard WorkermainClass="com.android.tools.r8.D8" 40*344a7f5eSAndroid Build Coastguard Worker 41*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 42*344a7f5eSAndroid Build Coastguard Worker # set d8.jar location for the SDK case 43*344a7f5eSAndroid Build Coastguard Worker libdir="$libdir/lib" 44*344a7f5eSAndroid Build Coastguard Workerfi 45*344a7f5eSAndroid Build Coastguard Worker 46*344a7f5eSAndroid Build Coastguard Worker 47*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 48*344a7f5eSAndroid Build Coastguard Worker # set d8.jar location for the Android tree case 49*344a7f5eSAndroid Build Coastguard Worker libdir=`dirname "$progdir"`/framework 50*344a7f5eSAndroid Build Coastguard Worker mainClass="com.android.tools.r8wrappers.D8Wrapper" 51*344a7f5eSAndroid Build Coastguard Workerfi 52*344a7f5eSAndroid Build Coastguard Worker 53*344a7f5eSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then 54*344a7f5eSAndroid Build Coastguard Worker echo `basename "$prog"`": can't find $jarfile" 55*344a7f5eSAndroid Build Coastguard Worker exit 1 56*344a7f5eSAndroid Build Coastguard Workerfi 57*344a7f5eSAndroid Build Coastguard Worker 58*344a7f5eSAndroid Build Coastguard Worker# By default, give d8 a max heap size of 2 gigs. This can be overridden 59*344a7f5eSAndroid Build Coastguard Worker# by using a "-J" option (see below). 60*344a7f5eSAndroid Build Coastguard WorkerdefaultMx="-Xmx2G" 61*344a7f5eSAndroid Build Coastguard Worker 62*344a7f5eSAndroid Build Coastguard Worker# The following will extract any initial parameters of the form 63*344a7f5eSAndroid Build Coastguard Worker# "-J<stuff>" from the command line and pass them to the Java 64*344a7f5eSAndroid Build Coastguard Worker# invocation (instead of to d8). This makes it possible for you to add 65*344a7f5eSAndroid Build Coastguard Worker# a command-line parameter such as "-JXmx256M" in your scripts, for 66*344a7f5eSAndroid Build Coastguard Worker# example. "java" (with no args) and "java -X" give a summary of 67*344a7f5eSAndroid Build Coastguard Worker# available options. 68*344a7f5eSAndroid Build Coastguard Worker 69*344a7f5eSAndroid Build Coastguard Workerdeclare -a javaOpts=() 70*344a7f5eSAndroid Build Coastguard Worker 71*344a7f5eSAndroid Build Coastguard Workerwhile expr "x$1" : 'x-J' >/dev/null; do 72*344a7f5eSAndroid Build Coastguard Worker opt=`expr "x$1" : 'x-J\(.*\)'` 73*344a7f5eSAndroid Build Coastguard Worker javaOpts+=("-${opt}") 74*344a7f5eSAndroid Build Coastguard Worker if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then 75*344a7f5eSAndroid Build Coastguard Worker defaultMx="no" 76*344a7f5eSAndroid Build Coastguard Worker fi 77*344a7f5eSAndroid Build Coastguard Worker shift 78*344a7f5eSAndroid Build Coastguard Workerdone 79*344a7f5eSAndroid Build Coastguard Worker 80*344a7f5eSAndroid Build Coastguard Workerif [ "${defaultMx}" != "no" ]; then 81*344a7f5eSAndroid Build Coastguard Worker javaOpts+=("${defaultMx}") 82*344a7f5eSAndroid Build Coastguard Workerfi 83*344a7f5eSAndroid Build Coastguard Worker 84*344a7f5eSAndroid Build Coastguard Workerif [ "$OSTYPE" = "cygwin" ]; then 85*344a7f5eSAndroid Build Coastguard Worker # For Cygwin, convert the jarfile path into native Windows style. 86*344a7f5eSAndroid Build Coastguard Worker jarpath=`cygpath -w "$libdir/$jarfile"` 87*344a7f5eSAndroid Build Coastguard Workerelse 88*344a7f5eSAndroid Build Coastguard Worker jarpath="$libdir/$jarfile" 89*344a7f5eSAndroid Build Coastguard Workerfi 90*344a7f5eSAndroid Build Coastguard Worker 91*344a7f5eSAndroid Build Coastguard Workerexec java "${javaOpts[@]}" -cp "$jarpath" "$mainClass" "$@" 92