1#!/bin/bash 2set -e 3# Make sure that entries are not added for packages that are already fully handled using 4# annotations. 5LOCAL_DIR="$( dirname ${BASH_SOURCE} )" 6# Each team should add a <team>_PACKAGES and <team>_EMAIL with the list of packages and 7# the team email to use in the event of this detecting an entry in a <team> package. Also 8# add <team> to the TEAMS list. 9LIBCORE_PACKAGES="\ 10 android.system \ 11 android.test \ 12 com.android.bouncycastle \ 13 com.android.okhttp \ 14 com.sun \ 15 dalvik \ 16 java \ 17 javax \ 18 junit \ 19 libcore \ 20 org.apache.harmony \ 21 org.json \ 22 org.w3c.dom \ 23 org.xml.sax \ 24 org.xmlpull.v1 \ 25 sun \ 26 " 27LIBCORE_EMAIL=libcore-team@android.com 28 29I18N_PACKAGES="\ 30 android.icu \ 31 " 32 33I18N_EMAIL=$LIBCORE_EMAIL 34 35CONSCRYPT_PACKAGES="\ 36 com.android.org.conscrypt \ 37 " 38 39CONSCRYPT_EMAIL=$LIBCORE_EMAIL 40 41# List of teams. 42TEAMS="LIBCORE I18N CONSCRYPT" 43 44SHA=$1 45 46# Generate the list of packages and convert to a regular expression. 47PACKAGES=$(for t in $TEAMS; do echo $(eval echo \${${t}_PACKAGES}); done) 48RE=$(echo ${PACKAGES} | sed "s/ /|/g") 49EXIT_CODE=0 50for file in $(git show --name-only --pretty=format: $SHA | grep "boot/hiddenapi/hiddenapi-.*txt"); do 51 ENTRIES=$(grep -E "^\+L(${RE})/" <(git diff ${SHA}~1 ${SHA} $file) | sed "s|^\+||" || echo) 52 if [[ -n "${ENTRIES}" ]]; then 53 echo -e "\e[1m\e[31m$file $SHA contains the following entries\e[0m" 54 echo -e "\e[1m\e[31mfor packages that are handled using UnsupportedAppUsage. Please remove\e[0m" 55 echo -e "\e[1m\e[31mthese entries and add annotations instead.\e[0m" 56 # Partition the entries by team and provide contact details to aid in fixing the issue. 57 for t in ${TEAMS} 58 do 59 PACKAGES=$(eval echo \${${t}_PACKAGES}) 60 TEAM_RE=$(echo ${PACKAGES} | sed "s/ /|/g") 61 TEAM_ENTRIES=$(grep -E "^L(${TEAM_RE})/" <(echo "${ENTRIES}") || echo) 62 if [[ -n "${TEAM_ENTRIES}" ]]; then 63 EMAIL=$(eval echo \${${t}_EMAIL}) 64 echo -e "\e[33mContact ${EMAIL} for help with the following:\e[0m" 65 for i in ${TEAM_ENTRIES} 66 do 67 echo -e "\e[33m ${i}\e[0m" 68 done 69 fi 70 done 71 EXIT_CODE=1 72 fi 73done 74exit $EXIT_CODE 75