blob: 6fc33bc555eb347555c233afac7bc5db46af0945 [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
9ABIGAIL_DIR=$BASE_DIR/../kernel/build/abi
10ABIGAIL_BUILD_SCRIPT=$ABIGAIL_DIR/bootstrap_src_build
11ABI_XML_DIR=$BASE_DIR/scripts/abi/abi_xml
12ABI_RESULT_DIR=$BASE_DIR/scripts/abi/abi_xml
13ORI_ABI_XML=abi_$src_defconfig.xml
14TARGET_ABI_XML=abi_target.xml
15ABI_REPORT=abi-report.out
16FINAL_ABI_REPORT=abi-report-final.out
17TARGET_KERNEL_DIR=$BASE_DIR/out
18
19echo "Get ABIGAIL_VERSION from $ABIGAIL_BUILD_SCRIPT"
20ABIGAIL_VERSION=`grep "ABIGAIL_VERSION=" $ABIGAIL_BUILD_SCRIPT | cut -f2- -d=`
21ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR/abigail-inst/$ABIGAIL_VERSION
22echo "ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR_RELEASE"
23
24function print_usage(){
25 echo -e "${green}Script for auto generate target_branch's ABI xml \
26based on src_defconfig and compare with abi_{src_defconfig}.xml${eol}"
27 echo ""
28 echo -e "${red}Command for local test:${eol}"
29 echo "[src_defconfig] mode=m ./scripts/abi/CompareABI.sh"
30 echo ""
31 echo -e "${green}Description:${eol}"
32 echo "[src_defconfig]: source project defconfig"
33 echo ""
34 echo -e "${green}Example:${eol} ${red}src_defconfig=\
35k79v1_64_gki_debug_defconfig mode=m \
36./scripts/abi/CompareABI.sh 2>&1 | tee buildABI.log${eol}"
37 echo ""
38 echo -e "${green}Script for auto generate target_branch's ABI xml \
39based on src_defconfig and compare with abi_{src_defconfig}.xml and save abi \
40monitor result to [abi_result_path]${eol}"
41 echo ""
42 echo -e "${red}Command for local test:${eol}"
43 echo "[src_defconfig] mode=m [abi_result_path] \
44./scripts/abi/CompareABI.sh"
45 echo ""
46 echo -e "${green}Description:${eol}"
47 echo "[src_defconfig]: source project defconfig"
48 echo ""
49 echo "[abi_result_path]: absolute path to put abi monitor result"
50 echo ""
51 echo -e "${green}Example:${eol} ${red}src_defconfig=\
52k79v1_64_gki_debug_defconfig mode=m abi_result_path=absolute_path \
53./scripts/abi/CompareABI.sh 2>&1 | tee buildABI.log${eol}"
54 echo ""
55 echo -e "${red}Command for delete temp files:${eol}"
56 echo "mode=d ./scripts/abi/CompareABI.sh"
57 echo ""
58 echo -e "${green}Description:${eol}"
59 echo ""
60 echo -e "${green}Example:${eol} ${red}mode=d \
61./scripts/abi/CompareABI.sh${eol}"
62}
63function del_temp_files(){
64 echo "Delete temp files $TARGET_KERNEL_DIR"
65 rm -rf $TARGET_KERNEL_DIR
66 echo "Delete temp files $ABI_RESULT_DIR/$TARGET_ABI_XML"
67 rm -rf $ABI_RESULT_DIR/$TARGET_ABI_XML
68 echo "Delete temp files $ABI_RESULT_DIR/$ABI_REPORT"
69 rm -rf $ABI_RESULT_DIR/$ABI_REPORT
70 echo "Delete temp files $ABI_RESULT_DIR/$FINAL_ABI_REPORT"
71 rm -rf $ABI_RESULT_DIR/$FINAL_ABI_REPORT
72}
73
74if [[ "$1" == "h" ]] || [[ "$1" == "help" ]] || [ -z "mode" ]
75then
76 print_usage
77fi
78
79if [ -z "$abi_result_path" ]
80then
81 echo "ABI_XML_DIR=$ABI_XML_DIR"
82 echo "ABI_RESULT_DIR=$ABI_RESULT_DIR"
83else
84 ABI_RESULT_DIR=$abi_result_path
85 echo "ABI_XML_DIR=$ABI_XML_DIR"
86 echo "ABI_RESULT_DIR=$ABI_RESULT_DIR"
87fi
88
89if [ "$mode" == "d" ]
90then
91 del_temp_files
92fi
93
94if [ "$mode" == "m" ]
95then
96 #Build libabigail first
97 $ABIGAIL_BUILD_SCRIPT
98 #remove temp files first
99 del_temp_files
100 echo "Generate .config from src_defconfig:$src_defconfig"
101 cd ..
102 export PATH=$PWD\
103/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/:\
104$PWD/prebuilts/clang/host/linux-x86/clang-r353983c/bin/:$PATH
105 cd $BASE_DIR
106 make ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- \
107 CROSS_COMPILE=aarch64-linux-android- CC=clang $src_defconfig O=out
108 mosesq make ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- \
109 CROSS_COMPILE=aarch64-linux-android- CC=clang O=out -j24 -k
110
111
112 echo "Generate ABI xml:$TARGET_ABI_XML from kernel \
113tree:$TARGET_KERNEL_DIR"
114 #Use abi_dump to generate $TARGET_ABI_XML
115 #export $ABIGAIL_DIR_RELEASE bin and lib
116 export PATH=${ABIGAIL_DIR_RELEASE}/bin:${PATH}
117 export LD_LIBRARY_PATH=${ABIGAIL_DIR_RELEASE}/lib:\
118${ABIGAIL_DIR_RELEASE}/lib/elfutils:${LD_LIBRARY_PATH}
119 cd $ABIGAIL_DIR
120 python dump_abi --linux-tree $TARGET_KERNEL_DIR --out-file \
121 $ABI_RESULT_DIR/$TARGET_ABI_XML
122 echo "Generate ABI report:$ABI_REPORT from \
123--baseline:$ABI_XML_DIR/$ORI_ABI_XML --new:$ABI_RESULT_DIR/$TARGET_ABI_XML"
124 python diff_abi --baseline $ABI_XML_DIR/$ORI_ABI_XML \
125 --new $ABI_RESULT_DIR/$TARGET_ABI_XML \
126 --report $ABI_RESULT_DIR/$ABI_REPORT
127
128 cd $BASE_DIR
129 echo "Generate $FINAL_ABI_REPORT"
130 abi_result_path=$abi_result_path ./scripts/abi/FinalABI.sh
131fi