#!/bin/bash
############################### Script configuration area start ###################################
CODE_PATH="repo init -u buic-scm:gm/manifest -b gm-imx8-phantom-gm-3.y -g all --repo-url=buic-scm:IIC_SW_Tools/git-repo --repo-branch=stable-conti --no-repo-verify"
BUILD_PROJECT=imx8-phantom-gm
############################### Script configuration area stop ####################################
############################### Script code area start ############################################
WsRootDir=`pwd`
SELF_NAME=$0
function delete_all()
{
notify_start "delete_all"
mkdir ./.backup
if [ -f ./A35_Auto_build_script.sh ]; then
cp ./A35_Auto_build_script.sh ./.backup/
fi
if [ -f ./Auto_build.log ]; then
cp ./Auto_build.log ./.backup/
fi
rm -rf *
if [ -d ./.repo ]; then
rm -rf ./.repo
fi
cp ./.backup/* ./
rm -rf ./.backup
notify_done "delete_all"
}
function download_code()
{
notify_start "download_code"
$CODE_PATH << EOF
EOF
repo sync -j4
repo sync -j4
return 1
}
function update_code()
{
notify_start "update_code"
if [ ! -d ./.repo ]; then
echo "$(date +%Y-%m-%d_%H:%M:%S) This code is not complete, Miss .repo">>Auto_build.log
return 0
fi
repo forall -c 'git clean -df'
repo forall -c 'git checkout .'
repo sync -j4
return 1
}
function build_code()
{
notify_start "build_code"
if [ ! -d ./.repo ]; then
echo "$(date +%Y-%m-%d_%H:%M:%S) This code is not complete, Miss .repo">>Auto_build.log
return 0
fi
make M=1 clobber CAS_TARGET_HW=$BUILD_PROJECT
make image-4k CAS_TARGET_HW=$BUILD_PROJECT
return 1
}
function notify_error()
{
echo "##############################################################################"
echo -e "\033[31m $1 ERROR!!! ERROR!!! ERROR!!! ERROR!!! ERROR!!! ERROR!!! ERROR!!!\033[0m"
echo "##############################################################################"
echo "$(date +%Y-%m-%d_%H:%M:%S) $1 ERROR">>Auto_build.log
}
function notify_start()
{
echo "/****************************************************************************/"
echo "/* $1 start"
echo "/****************************************************************************/"
echo "$(date +%Y-%m-%d_%H:%M:%S) $1 start">>Auto_build.log
}
function notify_done()
{
echo "/****************************************************************************/"
echo "/* $1 done"
echo "/****************************************************************************/"
echo "$(date +%Y-%m-%d_%H:%M:%S) $1 done">>Auto_build.log
}
function check_var()
{
case $1 in
1) result=1 ;;
2) result=1 ;;
3) result=1 ;;
4) result=1 ;;
*) result=0 ;;
esac
return $result
}
function is_exist()
{
case $1 in
$var_1) result=1 ;;
$var_2) result=1 ;;
$var_3) result=1 ;;
$var_4) result=1 ;;
*) result=0 ;;
esac
return $result
}
function main()
{
echo -e "\033[36m/****************************************************************************/\033[0m"
echo -e "\033[36m/* */\033[0m"
echo -e "\033[36m/* Auto Build */\033[0m"
echo -e "\033[36m/* ---V1.0 by zhangheting */\033[0m"
echo -e "\033[36m/* */\033[0m"
echo -e "\033[36m/****************************************************************************/\033[0m"
echo ""
echo -e "\033[32m##############################################################################\033[0m"
echo -e "\033[32m#code path : $CODE_PATH\033[0m"
echo -e "\033[32m#project : $BUILD_PROJECT\033[0m"
echo -e "\033[32m##############################################################################\033[0m"
echo ""
if [ ! -f Auto_build.log ]; then
:>Auto_build.log
fi
echo "">>Auto_build.log
echo "">>Auto_build.log
echo "#########################################################">>Auto_build.log
echo "$(date +%Y-%m-%d_%H:%M:%S) build time">>Auto_build.log
echo "1. only download code"
echo "2. clean and update code"
echo "3. only build code"
echo -e "\033[31m4. delete all\033[0m"
read "var_1" "var_2"
echo "input command : $var_1 -- $var_2">>Auto_build.log
check_var $var_1
res_var=$?
if [ $res_var = "0" ] ; then
var_1=""
fi
check_var $var_2
res_var=$?
if [ $res_var = "0" ] ; then
var_2=""
fi
echo "valid command : $var_1 -- $var_2">>Auto_build.log
is_exist 1
res_exist=$?
if [ $res_exist = "1" ] ; then
{
download_code
res_var=$?
if [ $res_var = "0" ] ; then
notify_error "download_code"
return;
fi
}
fi
is_exist 2
res_exist=$?
if [ $res_exist = "1" ] ; then
{
update_code
res_var=$?
if [ $res_var = "0" ] ; then
notify_error "update_code"
return;
fi
}
fi
is_exist 3
res_exist=$?
if [ $res_exist = "1" ] ; then
{
build_code
res_var=$?
if [ $res_var = "0" ] ; then
notify_error "build_code"
return;
fi
}
fi
is_exist 4
res_exist=$?
if [ $res_exist = "1" ] ; then
delete_all
fi
}
main $1 $2
############################### Script code area stop ############################################