blob: ec1fc5fc884a4592cbfcdb8c5abde0e40a1102ad [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4green='\e[0;32m'
5red='\e[0;31m'
6eol='\e[0m'
7
8BASE_DIR=$PWD
9ABI_DIR=$BASE_DIR/scripts/abi
10ABI_XML_DIR=$BASE_DIR/scripts/abi/abi_xml
11ABI_RESULT_DIR=$BASE_DIR/scripts/abi/abi_xml
12ORI_ABI_XML=abi_ori.xml
13TARGET_ABI_XML=abi_target.xml
14ABI_REPORT=abi-report.out
15FINAL_ABI_REPORT=abi-report-final.out
16
17#include abi_white_list to bypass violations
18source $ABI_DIR/abi_white_list
19#Find Delete/Changed/Added and leaf type change
20check_arr=("\[D\]" "\[C\]" "\[A\]" "^'.*' changed:$")
21
22is_abi_violation_bypass=0
23declare -i abi_violation_count=0
24
25function 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
47if [ -z "$abi_result_path" ]
48then
49 echo "ABI_XML_DIR=$ABI_XML_DIR"
50 echo "ABI_RESULT_DIR=$ABI_RESULT_DIR"
51else
52 ABI_RESULT_DIR=$abi_result_path
53 echo "ABI_XML_DIR=$ABI_XML_DIR"
54 echo "ABI_RESULT_DIR=$ABI_RESULT_DIR"
55fi
56
57if [[ "$1" == "h" ]] || [[ "$1" == "help" ]]
58then
59 print_usage
60fi
61
62#remove temp files first
63rm -rf $ABI_RESULT_DIR/$FINAL_ABI_REPORT
64
65exec < $ABI_RESULT_DIR/$ABI_REPORT
66while read line
67do
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
94done
95
96if [[ $abi_violation_count == 0 ]]
97then
98 echo "ABI Monitor check PASS!!!"
99else
100 echo "ABI Monitor check FAILED!!!\
101Final abi_violation_count=$abi_violation_count!!!"
102echo "Please check report: $ABI_RESULT_DIR/$FINAL_ABI_REPORT for details."
103fi
104exit $abi_violation_count