1#!/bin/bash 2# 3# Copyright 2018 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# make us exit on a failure 18set -e 19 20export ASM_JAR="${ANDROID_BUILD_TOP}/prebuilts/misc/common/asm/asm-6.0.jar" 21 22export ORIGINAL_JAVAC="$JAVAC" 23 24function javac_wrapper { 25 set -e 26 27 # Add annotation src files to our compiler inputs. 28 local asrcs=util-src/annotations/*.java 29 30 # Compile. 31 $ORIGINAL_JAVAC "$@" $asrcs 32 33 # Move original classes to intermediate location. 34 mv classes intermediate-classes 35 mkdir classes 36 37 # Transform intermediate classes. 38 local transformer_args="-cp ${ASM_JAR}:$PWD/transformer.jar transformer.ConstantTransformer" 39 for class in intermediate-classes/*.class ; do 40 local transformed_class=classes/$(basename ${class}) 41 ${JAVA:-java} ${transformer_args} ${class} ${transformed_class} 42 done 43} 44 45export -f javac_wrapper 46export JAVAC=javac_wrapper 47 48###################################################################### 49 50# Build the transformer to apply to compiled classes. 51mkdir classes 52${ORIGINAL_JAVAC:-javac} ${JAVAC_ARGS} -cp "${ASM_JAR}" -d classes $(find util-src -name '*.java') 53jar -cf transformer.jar -C classes transformer/ -C classes annotations/ 54rm -rf classes 55 56# Use API level 28 for DEX file support constant method handles. 57./default-build "$@" --api-level 28 58