Home | History | Annotate | Download | only in 143-interface-methods
      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 JAVAC_SOURCE=1.8
     18 JAVAC_TARGET=1.8
     19 
     20 JAVAC_FLAGS="-source ${JAVAC_SOURCE} -target ${JAVAC_TARGET}"
     21 
     22 # Suppress warning over bootclass path from Java 9 compiler (if used).
     23 JAVAC_FLAGS="${JAVAC_FLAGS} -Xlint:-options"
     24 
     25 # Check interface method defintions cause warnings and {default,static}
     26 # interface method invocations fail hard.
     27 declare -A SUPPORT_THRESHOLD
     28 SUPPORT_THRESHOLD["DefaultDefinition.class"]=0
     29 SUPPORT_THRESHOLD["InvokeStatic.class"]=24
     30 SUPPORT_THRESHOLD["InvokeDefault.class"]=24
     31 SUPPORT_THRESHOLD["StaticDefinition.class"]=0
     32 
     33 CLASS_FILES=${!SUPPORT_THRESHOLD[@]}
     34 SOURCE_FILES=${CLASS_FILES//class/java}
     35 
     36 ${JAVAC} ${JAVAC_FLAGS} ${SOURCE_FILES}
     37 
     38 for API_LEVEL in 19 20 21 22 23 24 25; do
     39   echo --------------------- Testing $API_LEVEL ------------------------
     40   for c in $CLASS_FILES; do
     41     echo $c
     42     dx --dex --dump-width=500 --dump-to=$c.log --min-sdk-version=$API_LEVEL $c
     43     if [ $? = 0 ]; then
     44       if [[ $API_LEVEL -lt ${SUPPORT_THRESHOLD[$c]} ]]; then
     45         echo Unexpected success for $c at API level $API_LEVEL 1>&2
     46         cat $c.log
     47         exit 0
     48       fi
     49     else
     50       if [[ $API_LEVEL -ge ${SUPPORT_THRESHOLD[$c]} ]]; then
     51         echo Unexpected failure for $c at API level $API_LEVEL 1>&2
     52         exit 0
     53       fi
     54     fi
     55   done
     56 done
     57 
     58 # Now repeat with --allowAllInterfaceMethodInvokes which turns hard
     59 # failures for {default,static} interface invokes to warnings.
     60 EXTRA_DX_FLAG=--allow-all-interface-method-invokes
     61 
     62 SUPPORT_THRESHOLD["DefaultDefinition.class"]=0
     63 SUPPORT_THRESHOLD["InvokeStatic.class"]=21
     64 SUPPORT_THRESHOLD["InvokeDefault.class"]=0
     65 SUPPORT_THRESHOLD["StaticDefinition.class"]=0
     66 
     67 CLASS_FILES=${!SUPPORT_THRESHOLD[@]}
     68 SOURCE_FILES=${CLASS_FILES//class/java}
     69 
     70 ${JAVAC} ${JAVAC_FLAGS} ${SOURCE_FILES}
     71 
     72 for API_LEVEL in 19 20 21 22 23 24 25; do
     73   echo --------------------- Testing $API_LEVEL ------------------------
     74   for c in $CLASS_FILES; do
     75     echo $c
     76     dx --dex --dump-width=500 --dump-to=$c.log --min-sdk-version=$API_LEVEL $EXTRA_DX_FLAG $c
     77     if [ $? = 0 ]; then
     78       if [[ $API_LEVEL -lt ${SUPPORT_THRESHOLD[$c]} ]]; then
     79         echo Unexpected success for $c at API level $API_LEVEL 1>&2
     80         cat $c.log
     81         exit 0
     82       fi
     83     else
     84       if [[ $API_LEVEL -ge ${SUPPORT_THRESHOLD[$c]} ]]; then
     85         echo Unexpected failure for $c at API level $API_LEVEL 1>&2
     86         exit 0
     87       fi
     88     fi
     89   done
     90 done
     91