xref: /aosp_15_r20/prebuilts/sdk/tools/linux/bin/d8 (revision 344a7f5ef16c479e7a7f54ee6567a9d112f9e72b)
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.
19prog="$0"
20while [ -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
29done
30oldwd=`pwd`
31progdir=`dirname "${prog}"`
32cd "${progdir}"
33progdir=`pwd`
34prog="${progdir}"/`basename "${prog}"`
35cd "${oldwd}"
36
37jarfile=d8.jar
38libdir="$progdir"
39mainClass="com.android.tools.r8.D8"
40
41if [ ! -r "$libdir/$jarfile" ]; then
42    # set d8.jar location for the SDK case
43    libdir="$libdir/lib"
44fi
45
46
47if [ ! -r "$libdir/$jarfile" ]; then
48    # set d8.jar location for the Android tree case
49    libdir=`dirname "$progdir"`/framework
50    mainClass="com.android.tools.r8wrappers.D8Wrapper"
51fi
52
53if [ ! -r "$libdir/$jarfile" ]; then
54    echo `basename "$prog"`": can't find $jarfile"
55    exit 1
56fi
57
58# By default, give d8 a max heap size of 2 gigs. This can be overridden
59# by using a "-J" option (see below).
60defaultMx="-Xmx2G"
61
62# The following will extract any initial parameters of the form
63# "-J<stuff>" from the command line and pass them to the Java
64# invocation (instead of to d8). This makes it possible for you to add
65# a command-line parameter such as "-JXmx256M" in your scripts, for
66# example. "java" (with no args) and "java -X" give a summary of
67# available options.
68
69declare -a javaOpts=()
70
71while expr "x$1" : 'x-J' >/dev/null; do
72    opt=`expr "x$1" : 'x-J\(.*\)'`
73    javaOpts+=("-${opt}")
74    if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then
75        defaultMx="no"
76    fi
77    shift
78done
79
80if [ "${defaultMx}" != "no" ]; then
81    javaOpts+=("${defaultMx}")
82fi
83
84if [ "$OSTYPE" = "cygwin" ]; then
85    # For Cygwin, convert the jarfile path into native Windows style.
86    jarpath=`cygpath -w "$libdir/$jarfile"`
87else
88    jarpath="$libdir/$jarfile"
89fi
90
91exec java "${javaOpts[@]}" -cp "$jarpath" "$mainClass" "$@"
92