diff --git a/lite/tools/build_android.sh b/lite/tools/build_android.sh index aba5fb706cb62e5bc9b50127f16d07e0db55d595..90f604d97f212e2966326582eefbb8416cc269ad 100755 --- a/lite/tools/build_android.sh +++ b/lite/tools/build_android.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -x +set +x ##################################################################################################### # 1. global variables, you can change them according to your requirements ##################################################################################################### diff --git a/lite/tools/check_api_approvals.sh b/lite/tools/check_api_approvals.sh index 6100558d68abb2b4c82c1f367078e519972546ce..2f60a239161848f1aea923520b592122186884c0 100644 --- a/lite/tools/check_api_approvals.sh +++ b/lite/tools/check_api_approvals.sh @@ -5,13 +5,14 @@ if [ -z ${BRANCH} ]; then fi LITE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../.." && pwd )" - approval_line=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/Paddle-Lite/pulls/${GIT_PR_ID}/reviews?per_page=10000` -git_files=`git diff --numstat upstream/$BRANCH| wc -l` -git_count=`git diff --numstat upstream/$BRANCH| awk '{sum+=$1}END{print sum}'` failed_num=0 echo_list=() +# approval list +Superjomn=328693 +DannyIsFunny=45189361 + function add_failed(){ failed_num=`expr $failed_num + 1` echo_list="${echo_list[@]}$1" @@ -24,20 +25,96 @@ function check_approval(){ add_failed "${failed_num}. ${echo_line}" fi } +#################################################################################################### +# Check 1: You must have Superjomn's (Yunchunwei) approval for changing +# 20+ files or adding more than 1000+ lines of content +#################################################################################################### +function CheckModifiedFileNums() { + git_files=`git diff --numstat upstream/$BRANCH| wc -l` + git_count=`git diff --numstat upstream/$BRANCH| awk '{sum+=$1}END{print sum}'` + if [[ $git_files -gt 19 || $git_count -gt 999 ]];then + echo_line="You must have Superjomn's (Yunchunwei) approval for changing 20+ files or adding more than 1000+ lines of content.\n" + check_approval 1 $Superjomn + fi -if [[ $git_files -gt 19 || $git_count -gt 999 ]];then - echo_line="You must have Superjomn (Yunchunwei) approval for change 20+ files or add than 1000+ lines of content.\n" - check_approval 1 328693 -fi + if [ -n "${echo_list}" ];then + echo "****************" + echo -e "${echo_list[@]}" + echo "There are ${failed_num} approved errors." + echo "****************" + fi + + if [ -n "${echo_list}" ]; then + exit 1 + fi +} +#################################################################################################### +# Check 2: You must have Superjomn's (Yunchunwei) approval for increasing +# size of dynamic lib for 10+ kb +#################################################################################################### +function CheckLibSizeDiff() { + # step1: record lib size of current branch + lite/tools/build_android.sh --arch=armv8 --toolchain=gcc --android_stl=c++_static --with_log=OFF + current_size=`stat -c%s build.lite.android.armv8.gcc/inference_lite_lib.android.armv8/cxx/lib/libpaddle_light_api_shared.so` -if [ -n "${echo_list}" ];then - echo "****************" - echo -e "${echo_list[@]}" - echo "There are ${failed_num} approved errors." - echo "****************" -fi + # step2: record lib size of current develop branch + git checkout develop + git clean -f . && git checkout . + git fetch upstream && git merge upstream/develop + + lite/tools/build_android.sh --arch=armv8 --toolchain=gcc --android_stl=c++_static --with_log=OFF + develop_size=`stat -c%s build.lite.android.armv8.gcc/inference_lite_lib.android.armv8/cxx/lib/libpaddle_light_api_shared.so` + + # step3: if diff_size > 10485, special approval is needed + diff_size=$[$current_size - $develop_size] + if [ $diff_size -gt 10485 ]; then + echo_line="Your PR has increased basic inference lib for $diff_size Byte, exceeding maximum requirement of 10485 Byte (0.01M). You need Superjomn's (Yunchunwei) approval or you can contact DannyIsFunny(HuZhiqiang).\n" + check_approval 1 $Superjomn $DannyIsFunny + fi + + if [ -n "${echo_list}" ];then + echo "****************" + echo -e "${echo_list[@]}" + echo "There are ${failed_num} approved errors." + echo "****************" + fi + + if [ -n "${echo_list}" ]; then + exit 1 + fi +} + +#################################################################################################### +# Main functions +#################################################################################################### +function main { + if [ -z "$1" ]; then + # at least on argument is needed + echo "Error: at least on argument is needed!" + exit 1 + fi + + # Parse command line. + for i in "$@"; do + case $i in + check_modified_file_nums) + # modified files num can not exceed 20 + + CheckModifiedFileNums + exit 0 + ;; + check_lib_size_diff) + # size diff can not exceed 10K + + CheckLibSizeDiff + exit 0 + ;; + *) + # unknown option + echo "Error: unsupported input argument!" + exit 1 + ;; + esac + done +} -if [ -n "${echo_list}" ]; then - exit 1 -fi +main $@ diff --git a/lite/tools/ci_build.sh b/lite/tools/ci_build.sh index c61ecbf2a884ee2c340913223b664c274e53f64f..680c865c2c8999a29ff2b351dadfc797506c87f6 100755 --- a/lite/tools/ci_build.sh +++ b/lite/tools/ci_build.sh @@ -279,7 +279,7 @@ function test_server { } function assert_api_spec_approvals() { - /bin/bash ${LITE_ROOT}/lite/tools/check_api_approvals.sh + /bin/bash ${LITE_ROOT}/lite/tools/check_api_approvals.sh check_modified_file_nums if [ "$?" != 0 ];then exit 1 fi