Yohann Roussel | 4055b81 | 2017-10-23 11:46:43 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2017 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 | # Set up prog to be the path of this script, including following symlinks, |
| 18 | # and set up progdir to be the fully-qualified pathname of its directory. |
| 19 | prog="$0" |
| 20 | while [ -h "${prog}" ]; do |
| 21 | newProg=`/bin/ls -ld "${prog}"` |
| 22 | newProg=`expr "${newProg}" : ".* -> \(.*\)$"` |
| 23 | if expr "x${newProg}" : 'x/' >/dev/null; then |
| 24 | prog="${newProg}" |
| 25 | else |
| 26 | progdir=`dirname "${prog}"` |
| 27 | prog="${progdir}/${newProg}" |
| 28 | fi |
| 29 | done |
| 30 | oldwd=`pwd` |
| 31 | progdir=`dirname "${prog}"` |
| 32 | cd "${progdir}" |
| 33 | progdir=`pwd` |
| 34 | prog="${progdir}"/`basename "${prog}"` |
| 35 | cd "${oldwd}" |
| 36 | |
| 37 | jarfile=r8-compat-proguard.jar |
| 38 | libdir="$progdir" |
| 39 | |
| 40 | if [ ! -r "$libdir/$jarfile" ]; then |
| 41 | # set r8.jar location for the SDK case |
| 42 | libdir="$libdir/lib" |
| 43 | fi |
| 44 | |
| 45 | |
| 46 | if [ ! -r "$libdir/$jarfile" ]; then |
| 47 | # set r8.jar location for the Android tree case |
| 48 | libdir=`dirname "$progdir"`/framework |
| 49 | fi |
| 50 | |
| 51 | if [ ! -r "$libdir/$jarfile" ]; then |
| 52 | echo `basename "$prog"`": can't find $jarfile" |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
Søren Gjesse | 6999357 | 2018-09-12 17:02:53 +0200 | [diff] [blame] | 56 | # By default, give r8 a max heap size of 2 gigs. This can be overridden |
Yohann Roussel | 4055b81 | 2017-10-23 11:46:43 +0200 | [diff] [blame] | 57 | # by using a "-J" option (see below). |
Søren Gjesse | 6999357 | 2018-09-12 17:02:53 +0200 | [diff] [blame] | 58 | defaultMx="-Xmx2G" |
Yohann Roussel | 4055b81 | 2017-10-23 11:46:43 +0200 | [diff] [blame] | 59 | |
| 60 | # The following will extract any initial parameters of the form |
| 61 | # "-J<stuff>" from the command line and pass them to the Java |
| 62 | # invocation (instead of to r8). This makes it possible for you to add |
| 63 | # a command-line parameter such as "-JXmx256M" in your scripts, for |
| 64 | # example. "java" (with no args) and "java -X" give a summary of |
| 65 | # available options. |
| 66 | |
Sasha Smundak | e616c2c | 2019-07-08 17:21:09 -0700 | [diff] [blame] | 67 | declare -a javaOpts=() |
Yohann Roussel | 4055b81 | 2017-10-23 11:46:43 +0200 | [diff] [blame] | 68 | |
| 69 | while expr "x$1" : 'x-J' >/dev/null; do |
| 70 | opt=`expr "x$1" : 'x-J\(.*\)'` |
Sasha Smundak | e616c2c | 2019-07-08 17:21:09 -0700 | [diff] [blame] | 71 | javaOpts+=("-${opt}") |
Yohann Roussel | 4055b81 | 2017-10-23 11:46:43 +0200 | [diff] [blame] | 72 | if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then |
| 73 | defaultMx="no" |
| 74 | fi |
| 75 | shift |
| 76 | done |
| 77 | |
| 78 | if [ "${defaultMx}" != "no" ]; then |
Sasha Smundak | e616c2c | 2019-07-08 17:21:09 -0700 | [diff] [blame] | 79 | javaOpts+=("${defaultMx}") |
Yohann Roussel | 4055b81 | 2017-10-23 11:46:43 +0200 | [diff] [blame] | 80 | fi |
| 81 | |
| 82 | if [ "$OSTYPE" = "cygwin" ]; then |
| 83 | # For Cygwin, convert the jarfile path into native Windows style. |
| 84 | jarpath=`cygpath -w "$libdir/$jarfile"` |
| 85 | else |
| 86 | jarpath="$libdir/$jarfile" |
| 87 | fi |
| 88 | |
Søren Gjesse | 52a5690 | 2019-12-10 16:26:09 +0000 | [diff] [blame] | 89 | exec java "${javaOpts[@]}" -cp "$jarpath" com.android.tools.r8.compatproguard.CompatProguard "$@" |