第一部分:拷贝文件(sdk->target)
project=AD-XK02-V1.0-10-MIPI-NOE-N91-IC9365-HW-SW0.1-20240901
change_gits_dir=(
'device/rockchip/common'
'device/rockchip/rk3126c'
'hardware/ril'
'hardware/interfaces'
)
sh_dir=vendor/patch/sh_dir
root_dir=`pwd`
source_dir=`pwd`
targat_dir=vendor/patch/$project
function create_project_dir(){
echo "----create_project_dir:$targat_dir------"
mkdir -p $targat_dir
}
function cp_mod_files(){
source_git_dir=$source_dir/$1
target_git_dir=$root_dir/$targat_dir/$1
tmp_git_dir=$1
echo "---git:"$tmp_git_dir"--change-file-list:"
cat $target_git_dir/.tmp/mod.txt | while read i
do
echo $tmp_git_dir/$i
mkdir -p $target_git_dir/`dirname $i`
if [ `basename $i` == "Android.bp" ]; then
cp -rf $source_git_dir/$i $target_git_dir/$i"-"
else
cp -rf $source_git_dir/$i $target_git_dir/$i
fi
done
}
function cp_projest_files(){
echo "----cp_projest_files-------"
for git_dir in ${change_gits_dir[*]}
do
folder=$root_dir/$targat_dir/$git_dir
cd $git_dir
mkdir -p $folder/.tmp
git log -1 | grep commit > $folder/.tmp/hash.txt
git status -s |grep M | sed 's/...//' > $folder/.tmp/mod.txt
cp_mod_files $git_dir
cd - >/dev/null
done
}
create_project_dir
cp_projest_files
tree $targat_dir | tee $targat_dir/files-tree.txt
第二部分 还原sdk内容
project=AD-XK02-V1.0-10-MIPI-NOE-N91-IC9365-HW-SW0.1-20240901
sh_dir=vendor/patch/sh_dir
root_dir=`pwd`
source_dir=`pwd`
targat_dir=vendor/patch/$project
change_git_dirs
echo "----------------1. find git_dir directory :"$targat_dir
function find_git_dirs(){
cd $targat_dir
if [ $? -ne 0 ]; then
echo -e "\e[31m 没有该$targat_dir !!! \e[0m"
exit 1
fi
change_git_dirs=`find -name \.tmp | sed 's/..//' | sed 's/.\{5\}$//'`
cd - >/dev/null
}
echo "----------------2. checkout_mod_files projest directory change file-list:-----------------"
function checkout_projest_files(){
target_git_dir=$root_dir/$targat_dir
for git_dir in ${change_git_dirs[*]}
do
hash=$target_git_dir/$git_dir/.tmp/hash.txt
mod=$target_git_dir/$git_dir/.tmp/mod.txt
echo "------git_dir:"$git_dir"------"
cd $git_dir
if [ -f $hash -a -f $mod ]; then
cat $mod | while read i
do
echo $i
git checkout -- $i
if [ $? -eq 0 ]; then
echo "git chekout -- $i--okay"
else
echo -e "\e[31m git chekout -- $i--error \e[0m"
rm -rf $i
fi
done
else
if [ -f $hash ]; then
echo -e "\e[31m $mod:文件不存在!!! \e[0m"
else
echo -e "\e[31m $hash:文件不存在!!! \e[0m"
fi
fi
cd - >/dev/null
echo "--------------------------"
echo
done
}
echo "----------------3. end-----------------"
find_git_dirs
checkout_projest_files
第三部分 打入补丁(target->sdk)
project=AD-XK02-V1.0-10-MIPI-NOE-N91-IC9365-HW-SW0.1-20240901
sh_dir=vendor/patch/sh_dir
root_dir=`pwd`
source_dir=`pwd`
targat_dir=vendor/patch/$project
change_git_dirs=""
function find_git_dirs(){
cd $targat_dir
if [ $? -ne 0 ]; then
echo -e "\e[31m 没有该$targat_dir !!! \e[0m"
exit 1
fi
change_git_dirs=`find -name \.tmp | sed 's/..//' | sed 's/.\{5\}$//'`
cd - >/dev/null
}
function chek_patch_commitid(){
hash_old=`cat $1`
hash_new=`git log -1 | grep commit`
if [ "$hash_old" == "$hash_new" ]; then
echo "git 最近一次提交一致"
return 0
else
echo "git 最近的提交和补丁不一致,是否继续,继续:y,退出:n"
read -r -p "Are You Sure? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
return 0
;;
[nN][oO]|[nN])
echo "No"
return 2
;;
*)
echo "Invalid input..."
return 2
;;
esac
fi
}
function patch_projest_files(){
for git_dir in ${change_git_dirs[*]}
do
hash=$root_dir/$targat_dir/$git_dir/.tmp/hash.txt
mod=$root_dir/$targat_dir/$git_dir/.tmp/mod.txt
echo "------git_dir:"$git_dir"------"
cd $git_dir
if [ -f $hash -a -f $mod ]; then
chek_patch_commitid $hash
if [ $? -eq 2 ]; then
echo -e "\e[31m 不合并$git_dir的patch:: `cat $hash` !!! \e[0m"
cd - >/dev/null
continue
fi
cat $mod | while read i
do
echo $i
targat_file=$root_dir/$targat_dir/$git_dir/$i
if [ `basename $i` == "Android.bp" ]; then
targat_file=$root_dir/$targat_dir/$git_dir/$i"-"
fi
if [ -e $targat_file ]; then
echo "succeed find file:"$i
cp -rf $targat_file $source_dir/$git_dir/$i
else
echo -e "\e[31m $git_dir/$i:文件不存在!!! \e[0m"
fi
done
else
if [ -f $hash ]; then
echo -e "\e[31m $mod:文件不存在!!! \e[0m"
echo -e "\e[31m 不合并$git_dir的patch !!! \e[0m"
else
echo -e "\e[31m $hash:文件不存在!!! \e[0m"
echo -e "\e[31m 不合并$git_dir的patch !!! \e[0m"
fi
fi
cd - >/dev/null
echo "--------------------------"
echo
done
}
find_git_dirs
patch_projest_files
第四部分 前面三个相结合
project=test-20240901
change_gits_dir=(
'device/rockchip/common'
'device/rockchip/rk3126c'
'hardware/ril'
'hardware/interfaces'
)
sh_dir=vendor/patch/sh_dir
root_dir=`pwd`
source_dir=`pwd`
targat_dir=vendor/patch/$project
found_git_dirs=""
function remind_cords(){
echo "$0 gen #拷贝目前的修改文件"
echo "$0 pat #打入已有的工程文件"
echo "$0 che #退回已有的工程文件"
}
function create_project_dir(){
echo "----create_project_dir:$targat_dir------"
mkdir -p $targat_dir
}
function find_git_dirs(){
cd $targat_dir
if [ $? -ne 0 ]; then
echo -e "\e[31m 没有该$targat_dir !!! \e[0m"
exit 1
fi
found_git_dirs=`find -name \.tmp | sed 's/..//' | sed 's/.\{5\}$//'`
cd - >/dev/null
}
function chek_patch_commitid(){
hash_old=`cat $1`
hash_new=`git log -1 | grep commit`
echo "hash_new:"$hash_new
echo "hash_old:"$hash_old
if [ "$hash_old" == "$hash_new" ]; then
echo "git 最近一次提交一致"
return 0
else
echo "git 最近的提交和补丁不一致,是否继续,继续:y,退出:n"
read -r -p "Are You Sure? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
return 0
;;
[nN][oO]|[nN])
echo "No"
return 2
;;
*)
echo "Invalid input..."
return 2
;;
esac
fi
}
function cp_mod_files(){
source_git_dir=$source_dir/$1
target_git_dir=$root_dir/$targat_dir/$1
tmp_git_dir=$1
echo "---git:"$tmp_git_dir"--change-file-list:"
cat $target_git_dir/.tmp/mod.txt | while read i
do
echo $tmp_git_dir/$i
mkdir -p $target_git_dir/`dirname $i`
if [ `basename $i` == "Android.bp" ]; then
cp -rf $source_git_dir/$i $target_git_dir/$i"-"
else
cp -rf $source_git_dir/$i $target_git_dir/$i
fi
done
cat $target_git_dir/.tmp/add.txt | while read i
do
echo $tmp_git_dir/$i
cp -r $source_git_dir/$i $target_git_dir/
done
}
function cp_projest_files(){
echo "----cp_projest_files-------"
for git_dir in ${change_gits_dir[*]}
do
folder=$root_dir/$targat_dir/$git_dir
cd $git_dir
mkdir -p $folder/.tmp
git log -1 | grep commit > $folder/.tmp/hash.txt
git status -s |grep M | sed 's/...//' > $folder/.tmp/mod.txt
git status -s |grep "??" | sed 's/...//' > $folder/.tmp/add.txt
cp_mod_files $git_dir
cd - >/dev/null
done
}
function patch_projest_files(){
for git_dir in ${found_git_dirs[*]}
do
hash=$root_dir/$targat_dir/$git_dir/.tmp/hash.txt
mod=$root_dir/$targat_dir/$git_dir/.tmp/mod.txt
add=$root_dir/$targat_dir/$git_dir/.tmp/add.txt
echo "------git_dir:"$git_dir"------"
cd $git_dir
if [ -f $hash -a -f $mod ]; then
chek_patch_commitid $hash
if [ $? -eq 2 ]; then
echo -e "\e[31m 不合并$git_dir的patch:: `cat $hash` !!! \e[0m"
cd - >/dev/null
continue
fi
cat $mod | while read i
do
echo $i
targat_file=$root_dir/$targat_dir/$git_dir/$i
if [ `basename $i` == "Android.bp" ]; then
targat_file=$root_dir/$targat_dir/$git_dir/$i"-"
fi
if [ -e $targat_file ]; then
echo "succeed find file:"$i
cp -rf $targat_file $source_dir/$git_dir/$i
else
echo -e "\e[31m $git_dir/$i:文件不存在!!! \e[0m"
fi
done
cat $add | while read i
do
echo $i
targat_file=$root_dir/$targat_dir/$git_dir/$i
if [ `basename $i` == "Android.bp" ]; then
targat_file=$root_dir/$targat_dir/$git_dir/$i"-"
fi
if [ -e $targat_file ]; then
echo "succeed add file:"$i
cp -rf $targat_file $source_dir/$git_dir/$i
else
echo -e "\e[31m $git_dir/$i:文件不存在!!! \e[0m"
fi
done
else
if [ -f $hash ]; then
echo -e "\e[31m $mod:文件不存在!!! \e[0m"
echo -e "\e[31m 不合并$git_dir的patch !!! \e[0m"
else
echo -e "\e[31m $hash:文件不存在!!! \e[0m"
echo -e "\e[31m 不合并$git_dir的patch !!! \e[0m"
fi
fi
cd - >/dev/null
echo "--------------------------"
echo
done
}
function checkout_projest_files(){
target_git_dir=$root_dir/$targat_dir
for git_dir in ${found_git_dirs[*]}
do
hash=$target_git_dir/$git_dir/.tmp/hash.txt
mod=$target_git_dir/$git_dir/.tmp/mod.txt
add=$target_git_dir/$git_dir/.tmp/add.txt
echo "------git_dir:"$git_dir"------"
cd $git_dir
if [ -f $hash -a -f $mod ]; then
cat $mod | while read i
do
echo $i
git checkout -- $i
if [ $? -eq 0 ]; then
chmod 777 $i
else
echo -e "\e[31m git chekout -- $i--error \e[0m"
rm -rf $i
fi
done
cat $add | while read i
do
echo $i
rm -rf $i
done
else
if [ -f $hash ]; then
echo -e "\e[31m $mod:文件不存在!!! \e[0m"
else
echo -e "\e[31m $hash:文件不存在!!! \e[0m"
fi
fi
cd - >/dev/null
echo "--------------------------"
echo
done
}
function main(){
case $1 in
"gen")
echo "generate"
echo "新建工程目录:$project --start----"
create_project_dir
cp_projest_files
tree $targat_dir > $targat_dir/files-tree.txt
cat $targat_dir/files-tree.txt
echo "新建工程目录:$project ----end-----"
;;
"pat")
echo "patch"
echo "打入工程文件:$project --start----"
find_git_dirs
patch_projest_files
cat $targat_dir/files-tree.txt
echo "打入工程文件:$project ----end-----"
;;
"che")
echo "checkout"
echo "去掉工程文件:$project --start----"
find_git_dirs
checkout_projest_files
cat $targat_dir/files-tree.txt
echo "去掉工程文件:$project ----end-----"
;;
*)
echo "无效参数"
exit 1
;;
esac
}
if [ $
echo "--------------------------"
echo "$0 只需要传递的参数一个 eg:【gen】【pat】【che】"
remind_cords
echo "--------------------------"
elif [ $
echo "--------------------------"
echo "$0 需要传递一个参数 eg:【gen】【pat】【che】"
remind_cords
echo "--------------------------"
else
main $1
fi
第五部分 加上了检查修改的git_dir的权限
project=temp
change_gits_dir=(
'u-boot'
'kernel'
'device/rockchip/common'
'hardware/ril'
'hardware/interfaces'
'frameworks/base'
'frameworks/opt/telephony'
'hardware/rockchip/camera/'
)
is_create_sh=0
root_dir=`pwd`
source_dir=`pwd`
targat_dir=vendor/patch/$project
found_git_dirs=""
vendor_patch_cp_sh=$root_dir/$targat_dir/$project".sh"
vendor_patch_che_sh=$root_dir/$targat_dir/$project"_checkout.sh"
function remind_cords(){
echo "$0 gen #拷贝目前的修改文件"
echo "$0 pat #打入已有的工程文件"
echo "$0 che #退回已有的工程文件"
}
function fix_dispaly_id(){
dispaly_id=$project-"\$PLATFORM_VERSION"-`date +%Y%m%d`
cd $root_dir/build/tools/
git checkout -- buildinfo.sh
cd - >/dev/null
sed -i "s/\$BUILD_DISPLAY_ID/$dispaly_id/g" build/tools/buildinfo.sh
echo "----fix_dispaly_id:$dispaly_id------"
}
function checkid_git_files(){
echo "----checkid_git_files--start-----"
rts=${
for git_dir in ${change_gits_dir[*]}
do
echo "----$git_dir-----"
cd $git_dir
rt=`git status -s | grep \ M | wc -l`
if [ $rt -ne 0 ];then
echo -e "\e[31m 该目录$git_dir不干净,不可打入补丁!!! \e[0m"
git status ./
read -r -p "Are You Continue? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
cd - >/dev/null
continue
;;
[nN][oO]|[nN])
echo "No"
exit 1
;;
*)
echo "Invalid input..."
exit 1
;;
esac
else
rts=$(( rts - 1))
fi
echo "----------------"
cd - >/dev/null
done
if [ $rts -eq 0