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 | ABIGAIL_DIR=$BASE_DIR/../kernel/build/abi |
| 10 | ABIGAIL_BUILD_SCRIPT=$ABIGAIL_DIR/bootstrap_src_build |
| 11 | ABI_XML_DIR=$BASE_DIR/scripts/abi/abi_xml |
| 12 | ABI_RESULT_DIR=$BASE_DIR/scripts/abi/abi_xml |
| 13 | ORI_ABI_XML=abi_$src_defconfig.xml |
| 14 | TARGET_ABI_XML=abi_target.xml |
| 15 | ABI_REPORT=abi-report.out |
| 16 | FINAL_ABI_REPORT=abi-report-final.out |
| 17 | TARGET_KERNEL_DIR=$BASE_DIR/out |
| 18 | |
| 19 | echo "Get ABIGAIL_VERSION from $ABIGAIL_BUILD_SCRIPT" |
| 20 | ABIGAIL_VERSION=`grep "ABIGAIL_VERSION=" $ABIGAIL_BUILD_SCRIPT | cut -f2- -d=` |
| 21 | ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR/abigail-inst/$ABIGAIL_VERSION |
| 22 | echo "ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR_RELEASE" |
| 23 | |
| 24 | function print_usage(){ |
| 25 | echo -e "${green}Script for auto generate target_branch's ABI xml \ |
| 26 | based 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=\ |
| 35 | k79v1_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 \ |
| 39 | based on src_defconfig and compare with abi_{src_defconfig}.xml and save abi \ |
| 40 | monitor 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=\ |
| 52 | k79v1_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 | } |
| 63 | function 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 | |
| 74 | if [[ "$1" == "h" ]] || [[ "$1" == "help" ]] || [ -z "mode" ] |
| 75 | then |
| 76 | print_usage |
| 77 | fi |
| 78 | |
| 79 | if [ -z "$abi_result_path" ] |
| 80 | then |
| 81 | echo "ABI_XML_DIR=$ABI_XML_DIR" |
| 82 | echo "ABI_RESULT_DIR=$ABI_RESULT_DIR" |
| 83 | else |
| 84 | ABI_RESULT_DIR=$abi_result_path |
| 85 | echo "ABI_XML_DIR=$ABI_XML_DIR" |
| 86 | echo "ABI_RESULT_DIR=$ABI_RESULT_DIR" |
| 87 | fi |
| 88 | |
| 89 | if [ "$mode" == "d" ] |
| 90 | then |
| 91 | del_temp_files |
| 92 | fi |
| 93 | |
| 94 | if [ "$mode" == "m" ] |
| 95 | then |
| 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 \ |
| 113 | tree:$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 |
| 131 | fi |