1 #!/bin/bash 2 3 # Copyright (C) 2019 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 if [ "$1" == "--help" -o "$1" == "-h" ]; then 18 echo "Usage: apilint [FILTERS...]" 19 echo " Shows lint from currently open files (as diffed from HEAD), i.e. errors" 20 echo " you will receive if you upload this CL." 21 echo 22 echo "Usage: apilint --all [FILTERS...]" 23 echo " Shows all lint errors present in the current working directory, regardless" 24 echo " of when they were added." 25 echo 26 echo "Usage: apilint --level API_LEVEL [FILTERS...]" 27 echo " Shows lint as it stands in API_LEVEL" 28 echo 29 echo "Usage: apilint --shal SHA [FILTERS...]" 30 echo " Shows lint from locally commited git change SHA." 31 echo 32 echo "Usage: apilint --unreleased [FILTERS...]" 33 echo " Shows all lint errors in the current working directory directory added since" 34 echo " the last released SDK version." 35 echo 36 echo "FILTERS" 37 echo " List of class or package names by which to filter the results." 38 echo 39 exit 40 fi 41 42 if [ \( -z "$ANDROID_BUILD_TOP" \) \ 43 -a \( ! -f frameworks/base/api/current.txt \) \ 44 -a \( ! -f frameworks/base/api/system-current.txt \) \ 45 ]; then 46 echo "apilint must be run either with ANDROID_BUILD_TOP set or from the" 1>&2 47 echo "root of the android source tree" 1>&2 48 exit 1 49 fi 50 51 if [ ${ANDROID_BUILD_TOP:0:1} != "/" ]; then 52 echo "ANDROID_BUILD_TOP must be an absolute path, not: $ANDROID_BUILD_TOP" 1>&2 53 exit 1 54 fi 55 56 if [ -z "$ANDROID_BUILD_TOP" ]; then 57 ANDROID_BUILD_TOP=$(pwd) 58 fi 59 60 FW_BASE=$ANDROID_BUILD_TOP/frameworks/base 61 62 MODE=open 63 64 OPTIONS=$(getopt -n apilint -o "" -l "all,sha:,unreleased" -- "$@") 65 66 [ $? -eq 0 ] || { 67 exit 1 68 } 69 70 eval set -- "$OPTIONS" 71 while true; do 72 case "$1" in 73 --all) 74 MODE=all 75 ;; 76 --sha) 77 shift; # The arg is next in position args 78 MODE=sha 79 SHA=$1 80 ;; 81 --unreleased) 82 MODE=unreleased 83 ;; 84 --) 85 shift 86 break 87 ;; 88 esac 89 shift 90 done 91 FILTERS= 92 for var in "$@" 93 do 94 FILTERS="$FILTERS --filter $var" 95 done 96 97 if [ $MODE = "all" ]; then 98 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 99 --title "SDK" \ 100 $FILTERS \ 101 $ANDROID_BUILD_TOP/frameworks/base/api/current.txt 102 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 103 --title "SystemApi" \ 104 $FILTERS \ 105 --base-current $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \ 106 $ANDROID_BUILD_TOP/frameworks/base/api/system-current.txt 107 elif [ $MODE = "open" ]; then 108 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 109 --title "SDK" \ 110 $FILTERS \ 111 $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \ 112 <(cd $FW_BASE ; git show HEAD:api/current.txt) 113 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 114 --title "SystemApi" \ 115 $FILTERS \ 116 --base-current $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \ 117 --base-previous <(cd $FW_BASE ; git show HEAD:api/current.txt) \ 118 $ANDROID_BUILD_TOP/frameworks/base/api/system-current.txt \ 119 <(cd $FW_BASE ; git show HEAD:api/system-current.txt) 120 elif [ $MODE = "sha" ]; then 121 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 122 --title "SDK" \ 123 $FILTERS \ 124 <(cd $FW_BASE ; git show $SHA:api/current.txt) \ 125 <(cd $FW_BASE ; git show $SHA^:api/current.txt) 126 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 127 --title "SystemApi" \ 128 $FILTERS \ 129 --base-current <(cd $FW_BASE ; git show $SHA:api/current.txt) \ 130 --base-previous <(cd $FW_BASE ; git show $SHA^:api/current.txt) \ 131 <(cd $FW_BASE ; git show $SHA:api/system-current.txt) \ 132 <(cd $FW_BASE ; git show $SHA^:api/system-current.txt) 133 elif [ $MODE = "unreleased" ]; then 134 LAST_SDK=$(ls $ANDROID_BUILD_TOP/prebuilts/sdk | grep "^[0-9][0-9]*$" | sort -n | tail -n 1) 135 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 136 --title "SDK" \ 137 $FILTERS \ 138 $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \ 139 $ANDROID_BUILD_TOP/prebuilts/sdk/$LAST_SDK/public/api/android.txt 140 python2.7 -B $ANDROID_BUILD_TOP/frameworks/base/tools/apilint/apilint.py \ 141 --title "SystemApi" \ 142 $FILTERS \ 143 --base-current $ANDROID_BUILD_TOP/frameworks/base/api/current.txt \ 144 --base-previous $ANDROID_BUILD_TOP/prebuilts/sdk/$LAST_SDK/public/api/android.txt \ 145 $ANDROID_BUILD_TOP/frameworks/base/api/system-current.txt \ 146 $ANDROID_BUILD_TOP/prebuilts/sdk/$LAST_SDK/system/api/android.txt 147 fi 148