• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17JAVAC_SOURCE=1.8
18JAVAC_TARGET=1.8
19
20JAVAC_FLAGS="-source ${JAVAC_SOURCE} -target ${JAVAC_TARGET}"
21
22# Suppress warning over bootclass path from Java 9 compiler (if used).
23JAVAC_FLAGS="${JAVAC_FLAGS} -Xlint:-options"
24
25# Check interface method defintions cause warnings and {default,static}
26# interface method invocations fail hard.
27declare -A SUPPORT_THRESHOLD
28SUPPORT_THRESHOLD["DefaultDefinition.class"]=0
29SUPPORT_THRESHOLD["InvokeStatic.class"]=24
30SUPPORT_THRESHOLD["InvokeDefault.class"]=24
31SUPPORT_THRESHOLD["StaticDefinition.class"]=0
32
33CLASS_FILES=${!SUPPORT_THRESHOLD[@]}
34SOURCE_FILES=${CLASS_FILES//class/java}
35
36${JAVAC} ${JAVAC_FLAGS} ${SOURCE_FILES}
37
38for 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
56done
57
58# Now repeat with --allowAllInterfaceMethodInvokes which turns hard
59# failures for {default,static} interface invokes to warnings.
60EXTRA_DX_FLAG=--allow-all-interface-method-invokes
61
62SUPPORT_THRESHOLD["DefaultDefinition.class"]=0
63SUPPORT_THRESHOLD["InvokeStatic.class"]=21
64SUPPORT_THRESHOLD["InvokeDefault.class"]=0
65SUPPORT_THRESHOLD["StaticDefinition.class"]=0
66
67CLASS_FILES=${!SUPPORT_THRESHOLD[@]}
68SOURCE_FILES=${CLASS_FILES//class/java}
69
70${JAVAC} ${JAVAC_FLAGS} ${SOURCE_FILES}
71
72for 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
90done
91