Files
he/build.sh
T
2026-06-22 15:35:18 +08:00

191 lines
8.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
#跳转到当前脚本所在路径
cd "$(dirname "$(readlink -f "$0")")"
ECHO() {
local current_lineno=${BASH_LINENO[0]} # 获取调用ECHO的行号
local parent_lineno=$((current_lineno-1)) # 通常我们想要的是调用ECHO的行号,所以需要减1
# echo -e "\e[36;47mLine $parent_lineno:\e[0m $@" # 输出行号和传入的参数
# 使用printf格式化行号,确保总是6位数字,前面用空格填充
local formatted_lineno=$(printf "%6d" "$parent_lineno")
# echo "Line $formatted_lineno: $@" # 输出格式化的行号和传入的参数
echo -e "\e[36m[$formatted_lineno]: \e[0m$@" # 输出行号和传入的参数
}
function help {
echo -e "help: \t\t\t\t\t 脚本使用说明:"
echo -e "\t source build/envsetup.sh # 初始化编译环境"
echo -e "\t source lunch # 选择方案\n 编译指令:"
echo -e "\t m [all|clean|-h|help] # 等效之前的顶层build.sh # 整编, 不支持的命令默认显示帮助"
echo -e "\t m all # 等效之前的顶层build.sh all # 先clean再整编"
echo -e "\t mm [模块目录][all|clean] # 等效之前的当前目录build.sh # 模块编译,支持带参数,顶级目录除外"
echo -e "\t mmm [模块1] [模块2] ... [all|clean] # 等效之前的当前目录build.sh # 模块编译,支持带参数,顶级目录除外"
echo -e "\t m usb # 等效之前的当前目录build.sh -ro usb # 只打包usb升级文件"
echo -e "\t m bin [bin|nxml|force|all|patch] # 打包升级bin文件:\n\t\t\t\t\t\t# bin:只bin/ nxml:不打包xml文件,force:检查并全部打包(默认),all: 全打包不检查, patch:差分打包"
echo -e "\t m ota # 等效之前的当前目录build.sh -ro ota # 只打包云升级文件"
echo -e "\t m patch # 等效之前的当前目录build.sh -ro ota # 只打包云升级文件"
echo -e "\t m -r usb # 等效之前的当前目录build.sh -r usb # 整编译后,再打包usb升级文件"
echo -e "\t m -ro patch # 等效之前的当前目录build.sh -ro patch # 只打包差分云升级文件"
echo -e "\t________________________________"
echo -e "\t ./build.sh # 默认编译(不含spdlog,sqlite3及external_/)"
echo -e "\t ./build.sh all # 全部编译(all:含spdlog,sqlite3; ext: external_/含拷贝)"
echo -e "\t ./build.sh hmi # 只编译 ems_hmi程序,假设库文件已更新"
echo -e "\t ./build.sh -r # 编译全部,并release全部升级包"
echo -e "\t ./build.sh -ro usb # 编译全部,并release U盘升级包"
echo -e "\t ./build.sh -ro ota # 编译全部,并release 网络升级包(云平台)"
echo -e "\t ./build.sh -ro patch # 编译全部,并release 网络chafen升级包(云平台)"
echo -e "\t ./build.sh -ro # 直接release升级包,不编译"
echo -e "\t ./build/script/release_usb.sh # 直接release bin升级包,不编译"
echo -e "\t ./build/script/release_force.sh # 直接release bin完整升级包(检查完整性),不编译"
echo -e "\t ./build/script/release_all.sh # 直接release bin升级包(不检查完整性),不编译"
echo -e "\t ./build/script/release_binOnly.sh # 直接release bin升级包(只打包bin目录),不编译"
echo -e "\t ./logical/build.sh # 编译logical"
echo -e "\t ./lib_src/a_src/build.sh # 编译静态库"
echo -e "\t ./tools_code/prdebug/build.sh # 编译调试工具程序"
}
# help
if [[ "$1" == *-h* ]]; then ##if [ "$#" = 1 ] && [ "$1" = "-h" ]; then
help
exit 0 # 退出脚本
fi
# 获取脚本开始执行的时间
start_time=$(date +%s)
# 计算并打印脚本执行时间函数
function print_execution_time {
# 脚本结束执行的时间戳
end_time=$(date +%s)
# 计算执行时间差(秒)
execution_time=$((end_time - start_time))
# 将执行时间差转换为 HH:MM:SS 格式
execution_time_formatted=$(date -u -d @$execution_time +"%T")
# 判断正常还是异常退出
if [ $1 -eq 0 ];then
SET_COLOR="\e[32m "
else
SET_COLOR="\e[31m error at $(pwd) \n\e[1m"
fi
# 打印执行时间
mydir_name="$(d=$(pwd); echo ${d##*/})"
echo -e "${SET_COLOR} [$1] 执行时间:$execution_time_formatted ( $mydir_name )\e[0m "
}
# 捕获退出信号并调用函数
trap 'echo "$(print_execution_time $?)"' EXIT
# 获取脚本的名称
script_name=$(basename "$0")
# 检查是否被自身调用
#if [ "$0" = "$script_name" ]; then
# echo "脚本被自身调用,请检查无效路径"
# exit 1 # 退出脚本
#fi
# 添加可执行权限
find . -maxdepth 2 -type f -name "*.sh"|xargs chmod +x
current_project_path=$(pwd)
export current_project_name=`echo ${current_project_path##*/}`
echo "current_project_path = ${current_project_path}"
echo "====================== build shell at [ ${current_project_name} ] ========================="
pd_complier_type=${TARGET_PRODUCT}
if [ -z ${TARGET_PRODUCT} ];then
PROJECT_ROOT=$(while [ ! -f "build/envsetup.sh" ]; do [ "$(pwd)" = "/" ] && exit 1; cd ..; done; pwd)
if [ ! -z ${PROJECT_ROOT} ];then
source ${PROJECT_ROOT}/build/envsetup.sh && lunch LAST
if [ $? -eq 255 ];then exit 0; fi
pd_complier_type=${TARGET_PRODUCT}
fi
fi
echo -e " ready to build\e[34;1m ${pd_complier_type} \e[0m target [\e[34;1m ${current_project_name}\e[0m ] ......"
#unset LD_LIBRARY_PATH
export pd_complier_name="$(if [[ "${TARGET_PRODUCT}" =~ "imx"* ]]; then echo "complier_arm"; else echo "complier_x86"; fi)"
export arm_sysroot_path=${SYSROOT}
export arm_compile_flags=${CFLAGS}
check_dirs() { # check dir: process/ script/
local dir="$1"; if [[ -d "$dir/process" && -d "$dir/script" ]]; then echo "$dir"; exit 0;fi
local parent="${dir%/*}"; if [[ "$parent" != "$dir" ]]; then check_dirs "$parent"; else echo "$(pwd)"; fi
}
base_folder="$(echo ${PROJECT_ROOT}|tr -s '/')"
build_path=$(echo "$current_project_path" | sed "s|${base_folder}|${base_folder}/out/build/${pd_complier_type}/|g")
echo "====================================================build shell start [${current_project_name}]===================================================="
#if [ $# -eq 0 ] || [[ $1 == "clean" ]] || [[ $1 == "-c" ]];then
#
# echo " clean done."
#echo "====================================================build shell end [${current_project_name}]===================================================="
# exit 0
#fi
# 显示当前配置选择
echo "======================"
echo -e " ${pd_complier_type} "
echo "======================"
echo -e "PARAM [ ${@} ]"
if [[ $1 == *"-ro"* ]]; then # 如果$1包含"-ro",则执行相关操作
echo "执行打包,请确保已正常编译arm程序。"
else
case $1 in
""|build|clean|bin|all|usb|ota|patch|-r)
#执行 编译
cd lib_src/ && \
echo -e "\e[33;42;1mcd `pwd`/ \e[0m" && \
sh build.sh $@|| exit $? && \
cd ../
#==============================================================
# update or create .profile
#==============================================================
BOARD_TMP_DIR=./board_dir
PROFILE=${BOARD_TMP_DIR}/.profile
# create it here, update it via ./build/script/release.sh
if [ ! -f ${PROFILE} ];then
echo "##################################################" > ${PROFILE}
echo "# poweroad env config " >> ${PROFILE}
echo "# auto create or update by build.sh @date '+%F %T'" >> ${PROFILE}
echo "##################################################" >> ${PROFILE}
echo "export POWEROAD_DEVICE=ems" >> ${PROFILE}
echo "export POWEROAD_VERSION=ems_pro2023_v0.01.274" >> ${PROFILE}
echo "export POWEROAD_BUILD_TIME=\"2023-08-09 16:45:08\"" >> ${PROFILE}
echo "export POWEROAD_BUILD_TIME_UTC=1691570708" >> ${PROFILE}
echo "export POWEROAD_BUILDER=linux" >> ${PROFILE}
echo "export POWEROAD_CUSTOMER=PRHZ" >> ${PROFILE}
fi
if [ "$1" == "-r" ];then
process/build.sh $[@:2]
else
process/build.sh $@
fi
;;
-ro)
echo "to next"
;;
*)
echo -e "\e[35;1m UNKNOWN CMD:[$@] \e[0m"
help
;;
esac
fi
if [ "$1" == "-r" ] || [ "$1" == "-ro" ];then # "build.sh -r 带-r参数时增加打包"
cd build/script && \
echo -e "\nrelease USB upgrade package: [${@:2}] " && \
sh release.sh ${@:2} || exit $? && \
cd ../
fi