1#!/bin/bash
2#
3# Copyright (C) 2020 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# This script compiles Java Language source files into arm64 odex files.
19#
20# Before running this script, do lunch and build for an arm64 device.
21#
22# Usage:
23#     compile-classes.sh Scratch.java
24
25set -e
26
27SCRATCH=`mktemp -d`
28DEX_FILE=classes.dex
29ODEX_FILE=classes.odex
30
31javac -d $SCRATCH $1
32d8 $SCRATCH/*.class
33
34$ANDROID_BUILD_TOP/art/tools/compile-jar.sh $DEX_FILE $ODEX_FILE arm64 \
35    --generate-debug-info \
36    --dump-cfg=classes.cfg
37
38rm -rf $SCRATCH
39
40echo
41echo "OAT file is at $ODEX_FILE"
42echo
43echo "View it with one of the following commands:"
44echo
45echo "    oatdump --oat-file=$ODEX_FILE"
46echo
47echo "    aarch64-linux-android-objdump -d $ODEX_FILE"
48echo
49echo "The CFG is dumped to output.cfg for inspection of individual compiler passes."
50echo
51