xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | |
| 4 | green='\e[0;32m' |
| 5 | red='\e[0;31m' |
| 6 | eol='\e[0m' |
| 7 | |
| 8 | BASE_DIR=$PWD |
| 9 | ABI_DIR=$BASE_DIR/scripts/abi |
| 10 | ABI_XML_DIR=$BASE_DIR/scripts/abi/abi_xml |
| 11 | ABI_RESULT_DIR=$BASE_DIR/scripts/abi/abi_xml |
| 12 | ORI_ABI_XML=abi_ori.xml |
| 13 | TARGET_ABI_XML=abi_target.xml |
| 14 | ABI_REPORT=abi-report.out |
| 15 | FINAL_ABI_REPORT=abi-report-final.out |
| 16 | |
| 17 | #include abi_white_list to bypass violations |
| 18 | source $ABI_DIR/abi_white_list |
| 19 | #Find Delete/Changed/Added and leaf type change |
| 20 | check_arr=("\[D\]" "\[C\]" "\[A\]" "^'.*' changed:$") |
| 21 | |
| 22 | is_abi_violation_bypass=0 |
| 23 | declare -i abi_violation_count=0 |
| 24 | |
| 25 | function print_usage(){ |
| 26 | echo -e "${green}Script for auto generate \ |
| 27 | $ABI_RESULT_DIR/$FINAL_ABI_REPORT from $ABI_RESULT_DIR/$ABI_REPORT ${eol}" |
| 28 | echo "" |
| 29 | echo -e "${red}Command for local test:${eol}" |
| 30 | echo "" |
| 31 | echo -e "${green}Example:${eol} ${red}./scripts/abi/FinalABI.sh${eol}" |
| 32 | echo "" |
| 33 | echo -e "${green}Script for auto generate \ |
| 34 | $FINAL_ABI_REPORT by specified abi_result_path ${eol}" |
| 35 | echo "" |
| 36 | echo -e "${red}Command for local test:${eol}" |
| 37 | echo "[abi_result_path] ./scripts/abi/FinalABI.sh" |
| 38 | echo "" |
| 39 | echo -e "${green}Description:${eol}" |
| 40 | echo "[abi_result_path]: absolute path to generate fianl abi report" |
| 41 | echo "" |
| 42 | echo -e "${green}Example:${eol} ${red}abi_result_path=absolute_path \ |
| 43 | /scripts/abi/FinalABI.sh${eol}" |
| 44 | exit -1 |
| 45 | } |
| 46 | |
| 47 | if [ -z "$abi_result_path" ] |
| 48 | then |
| 49 | echo "ABI_XML_DIR=$ABI_XML_DIR" |
| 50 | echo "ABI_RESULT_DIR=$ABI_RESULT_DIR" |
| 51 | else |
| 52 | ABI_RESULT_DIR=$abi_result_path |
| 53 | echo "ABI_XML_DIR=$ABI_XML_DIR" |
| 54 | echo "ABI_RESULT_DIR=$ABI_RESULT_DIR" |
| 55 | fi |
| 56 | |
| 57 | if [[ "$1" == "h" ]] || [[ "$1" == "help" ]] |
| 58 | then |
| 59 | print_usage |
| 60 | fi |
| 61 | |
| 62 | #remove temp files first |
| 63 | rm -rf $ABI_RESULT_DIR/$FINAL_ABI_REPORT |
| 64 | |
| 65 | exec < $ABI_RESULT_DIR/$ABI_REPORT |
| 66 | while read line |
| 67 | do |
| 68 | for ((i=0; i < ${#check_arr[@]}; i++)) |
| 69 | do |
| 70 | if [[ $line =~ ${check_arr[$i]} ]] |
| 71 | then |
| 72 | is_abi_violation_bypass=0 |
| 73 | for ((j=0; j < ${#bypass_arr[@]}; j++)) |
| 74 | do |
| 75 | if [[ $line =~ ${bypass_arr[$j]} ]] |
| 76 | then |
| 77 | is_abi_violation_bypass=1 |
| 78 | break |
| 79 | fi |
| 80 | done |
| 81 | |
| 82 | if [[ $is_abi_violation_bypass == 0 ]] |
| 83 | then |
| 84 | abi_violation_count+=1 |
| 85 | fi |
| 86 | break |
| 87 | fi |
| 88 | done |
| 89 | #write $line to $FINAL_ABI_REPORT if $is_abi_violation = 0 |
| 90 | if [[ $is_abi_violation_bypass == 0 ]] |
| 91 | then |
| 92 | echo $line >> $ABI_RESULT_DIR/$FINAL_ABI_REPORT |
| 93 | fi |
| 94 | done |
| 95 | |
| 96 | if [[ $abi_violation_count == 0 ]] |
| 97 | then |
| 98 | echo "ABI Monitor check PASS!!!" |
| 99 | else |
| 100 | echo "ABI Monitor check FAILED!!!\ |
| 101 | Final abi_violation_count=$abi_violation_count!!!" |
| 102 | echo "Please check report: $ABI_RESULT_DIR/$FINAL_ABI_REPORT for details." |
| 103 | fi |
| 104 | exit $abi_violation_count |