quick_build.sh脚本详解
(2017-08-03 16:59:58)分类: Linux |
一、 quick_build.sh作用
1.对平台原始命令打包,统一编译命令,即使更换平台也不需要改变编译命令及使用习惯。 2.编译前对代码进行预处理,让脚本帮我们完成机械重复的工作,使我们的工作变的简单,节省时间,提高效率。 3.输出编译log,以免log被冲掉。 4.根据项目设置变量,方便客制化。
二、 quick_build.sh详细解析
以E200L项目完整编译命令为例:./quick_build.sh E200L n user 1.原始编译命令: source build/envsetup.sh //准备编译环境 lunch full_[项目名] –[版本类型] //选择需要编译的项目 make –j4 //以四核的速度开始编译 2.我们的逻辑: 拿到参数 处理参数 预处理代码 解析我们自己的config文件 准备编译所需的变量(版本号等) 准备GMS包 开始编译 编译后release版本 3.代码详解 只介绍主函数和流程,其他代码请阅读脚本 #设置编译用的cpu核数(由于大家共用服务器,请不要全速编译) CPUCORE=8 function main() { #把参数加入数组 ################################################################## #Check parameters ################################################################## command_array=($1 $2 $3 $4 $5) #建立Log路径 if [! -d $LOG_PATH ];then mkdir $LOG_PATH fi #通过for循环轮询参数,所以参数没有顺序之分 #设置必要的参数 #PRODUCT:项目名 #VARIANT:user、debug or eng #ACTION:new remake … #ORIGINAL:不需要快速编译kernel 、pl 、lk #COPYFILES:是否拷贝wind文件 #MODULE:单独编译的模块 for command in ${command_array[*]}; do ### set PRODUCT case $command in ginr6753_65c_l1) if [ x$PRODUCT != x"" ];then continue; fi PRODUCT=ginr6753_65c_l1 RELEASEPATH=ginr6753_65c_l1 continue ;; E200L|E200L_CTA) if [ x$PRODUCT != x"" ];then continue; fi PRODUCT=E200L CONFIG_NAME=$command RELEASEPATH=E200L continue ;; esac ### set VARIANT if [ x$command == x"user" ] ;then if [ x$VARIANT != x"" ];then continue; fi VARIANT=user elif [ x$command == x"debug" ] ;then if [ x$VARIANT != x"" ];then continue; fi VARIANT=userdebug elif [ x$command == x"eng" ] ;then if [ x$VARIANT != x"" ];then continue; fi VARIANT=eng elif [ x$command == x"userroot" ] ;then if [ x$VARIANT != x"" ];then continue; fi VARIANT=userroot ### set ACTION elif [ x$command == x"r" ] || [ x$command == x"remake" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=remake elif [ x$command == x"n" ] || [ x$command == x"new" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=new elif [ x$command == x"c" ] || [ x$command == x"clean" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=clean RELEASE_PARAM=none elif [ x$command == x"mmma" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=mmma RELEASE_PARAM=none elif [ x$command == x"mmm" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=mmm RELEASE_PARAM=none elif [ x$command == x"api" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=update-api RELEASE_PARAM=none elif [ x$command == x"boot" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=bootimage RELEASE_PARAM=boot elif [ x$command == x"system" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=systemimage RELEASE_PARAM=system elif [ x$command == x"userdata" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=userdataimage RELEASE_PARAM=userdata elif [ x$command == x"boot-nodeps" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=bootimage-nodeps RELEASE_PARAM=boot elif [ x$command == x"snod" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=snod RELEASE_PARAM=system elif [ x$command == x"userdata-nodeps" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=userdataimage-nodeps RELEASE_PARAM=userdata elif [ x$command == x"ramdisk-nodeps" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=ramdisk-nodeps RELEASE_PARAM=boot elif [ x$command == x"cache" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=cacheimage RELEASE_PARAM=none elif [ x$command == x"otapackage" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=otapackage RELEASE_PARAM=none elif [ x$command == x"otadiff" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=otadiff RELEASE_PARAM=none elif [ x$command == x"cts" ];then if [ x$ACTION != x"" ];then continue; fi ACTION=cts RELEASE_PARAM=none ### set ORIGINAL elif [ x$command == x"o" ];then if [ x$ORIGINAL != x"" ];then continue; fi ORIGINAL=yes ### set COPYFILES elif [ x$command == x"nc" ];then if [ x$COPYFILES != x"" ];then continue; fi COPYFILES=no ### set MODULE elif [ x$command == x"pl" ];then if [ x$MODULE != x"" ];then continue; fi MODULE=pl RELEASE_PARAM=pl elif [ x$command == x"k" ] || [ x$command == x"kernel" ];then if [ x$MODULE != x"" ];then continue; fi MODULE=k RELEASE_PARAM=boot elif [ x$command == x"lk" ];then if [ x$MODULE != x"" ];then continue; fi MODULE=lk RELEASE_PARAM=lk #elif [ x$command == x"dr" ];then #if [ x$MODULE != x"" ];then continue; fi #MODULE=dr #RELEASE_PARAM=system else if [ x$MODULE != x"" ];then continue; fi MODULE=$command fi done #处理默认参数,把为空的参数赋默认值 if [ x$VARIANT == x"" ];then VARIANT=eng; fi if [ x$ORIGINAL == x"" ];then ORIGINAL=no; fi if [ x$ACTION == x"clean" ];then RELEASE_PARAM=none; fi if [ x$COPYFILES == x"" ];then if [ x$ACTION == x"new" ] && [ x$MODULE == x"" ];then COPYFILES=yes; else COPYFILES=no; fi fi echo "********This build project CONFIG_NAME is $CONFIG_NAME********" echo "PRODUCT=$PRODUCT VARIANT=$VARIANT ACTION=$ACTION MODULE=$MODULE COPYFILES=$COPYFILES ORIGINAL=$ORIGINAL" echo "Log Path $LOG_PATH" #如果重要的参数为空,报错 if [ x$PRODUCT == x"" ];then echo -e "\033[31m !!!!!! No Such Product !!!! \033[0m" exit 1 fi if [ x$ACTION == x"" ];then echo -e "\033[31m !!!!!! No Such Action !!!! \033[0m" exit 1 fi ################################################################## #Prepare ################################################################## #检查剩余空间 Check_Space CUSTOM_FILES_PATH="./wind/custom_files" #拷贝wind下的代码 if [ x$COPYFILES == x"yes" ];then copy_custom_files $PRODUCT; fi #解析项目config文件 build_Project_Config $CONFIG_NAME #解析kernel config文件 build_Kernel_Config $CONFIG_NAME #准备版本号等信息的文件 PROJECTNAME=`echo $CONFIG_NAME | sed -r 's/^[^_]*_//'` build_config $PROJECTNAME build_version export KERNEL_VER=zte-kernel #准备GMS包 ################################################################## #Add GMS ################################################################## if [ x"$ADDGMS" == x"true" ];then if [ x$ACTION == x"remake" ] || [ x$ACTION == x"new" ];then if [ x$MODULE == x"" ];then addGMS fi fi fi ################################################################### #Start build ################################################################### echo "Build started `date +%Y%m%d_%H%M%S` ..." echo;echo;echo;echo #准备编译环境 source build/envsetup.sh #选择要编译的项目以及模式 if [ x$VARIANT == x"userroot" ] ; then lunch full_$PRODUCT-user else lunch full_$PRODUCT-$VARIANT fi ##source mbldenv.sh ##source ./change_java.sh 1.7 #根据参数开始编译 case $ACTION in new | remake | clean) M=false; C=false; if [ x$ACTION == x"new" ];then M=true; C=true; elif [ x$ACTION == x"remake" ];then M=true; else C=true; fi case $MODULE in pl) if [ x$C == x"true" ];then clean_pl; result=$?; fi if [ x$M == x"true" ];then build_pl; result=$?; fi ;; k) if [ x$C == x"true" ];then clean_kernel; result=$?; fi if [ x$M == x"true" ];then build_kernel; result=$? if [ $result -eq 0 ];then make -j$CPUCORE bootimage-nodeps; result=$?; fi fi ;; lk) if [ x$C == x"true" ];then clean_lk; result=$?; fi if [ x$M == x"true" ];then build_lk; result=$?; fi ;; *) if [ x"$MODULE" == x"" ];then if [ x$C == x"true" ];then make clean; rm $LOG_PATH; fi if [ x$M == x"true" ];then if [ x$VARIANT == x"userroot" ] ; then echo "make userroot version" make MTK_BUILD_ROOT=yes -j$CPUCORE 2>&1 | tee $LOG_PATH/build.log; result=$?; else make -j$CPUCORE 2>&1 | tee $LOG_PATH/build.log; result=$?; fi fi else echo -e "\033[31m !!!!!! No Such module !!!! \033[0m" exit 1 fi ;; esac ;; mmma | mmm) $ACTION $MODULE 2>&1 | tee $LOG_PATH/$ACTION.log; result=$? ;; update-api | bootimage | systemimage | userdataimage | cacheimage | snod | bootimage-nodeps | userdataimage-nodeps | ramdisk-nodeps | otapackage | otadiff | cts) make -j$CPUCORE $ACTION 2>&1 | tee $LOG_PATH/$ACTION.log; result=$? ;; esac #编译结束release文件到版本通道 if [ $result -eq 0 ] && [ x$ACTION == x"mmma" -o x$ACTION == x"mmm" ];then echo "Start to release module ...." DIR=`echo $MODULE | sed -e 's/:.*//' -e 's:/$::'` NAME=${DIR##*/} TARGET=out/target/product/${PRODUCT}/obj/APPS/${NAME}_intermediates/package.apk if [ -f $TARGET ];then cp -f $TARGET /data/mine/test/MT6572/${MY_NAME}/${NAME}.apk fi elif [ $result -eq 0 ] && [ $RELEASE_PARAM != "none" ]; then echo "Build completed `date +%Y%m%d_%H%M%S` ..." echo "Start to release version ...." ./release_version.sh ${RELEASEPATH} ${RELEASE_PARAM} fi }
三、 quick_build.sh 常用的命令
以E200L为例: 完整编译参数为new 或 n(编译前clean out目录,不会清除修改的代码) 重编译参数为remake 或 r(编译前不clean out) 如果编译user版本必须加user参数 如果编译eng版本加与不加eng均可 脚本默认在new时会自动拷贝wind文件夹到根目录,如果不想拷贝需要加nc参数 在编译lk、kernel、pl时加参数o使用默认方式编译,不加o使用快速方式编译 #完整编译user版本 ./quick_build.sh E200L n user #完整编译user版本且不拷贝wind文件夹 ./quick_build.sh E200L n user nc #重新编译eng版本 ./quick_build.sh E200L r eng ./quick_build.sh E200L r #单独编译Setting模块 ./quick_build.sh E200L mmm package/app/Settings #clean out目录 ./quick_build.sh E200L c #更新framework api ./quick_build.sh E200L api #生成system ./quick_build.sh E200L system #生成userdata ./quick_build.sh E200L userdata #重新打包 ./quick_build.sh E200L snod #生成ota包 ./quick_build.sh E200L otapackage #快速编译pl模块 ./quick_build.sh E200L n pl #正常编译pl模块 ./quick_build.sh E200L n pl o #快速编译k模块 ./quick_build.sh E200L n k #正常编译k模块 ./quick_build.sh E200L n k o #快速编译lk模块 ./quick_build.sh E200L n lk #正常编译lk模块 ./quick_build.sh E200L n lk o 还有很多命令不一一列举,请详看脚本。 外发版本必须使用脚本,否则版本可能会出问题。