编译版本,多个客户小幅度修改方案

场景:当同一个master版本需要出很多客户的时候,因为每个客户都会有自己的需求
有的客户只修改简单的,有的客户需要大幅度修改,对于大幅度修改可以进行新建分之,那么对于小幅度修改新建分支,很浪费内存。

本文对于小幅度修改提供方案

1.在master分支根目录新建差异化目录

Paste_Image.png

例如:rich_custom

2.修改编译脚本(build/envsetup.sh) 新增如下函数

unset selection
function reset_project()
{  
  if [ $# -ne 0 ]
    then
    echo "reset project "$1
    reset_project_para $1
  else
    echo "no specific project input! reset all project"
    lunch_project
    if [ "$selection" ]
    then
    echo "reset project "$selection
    reset_project_para $selection
    else
    echo "reset project all"
    reset_project_all
    fi
  fi
  echo "Finish!"
  return
}
function reset_project_para()
{
 for project in `ls rich_custom`
 do
    if [ $1 = $project ]
      then
       for file in `find rich_custom/$project`
       do
            if [ -f $file ];then
                gitfile=${file##*rich_custom/$project/}
                echo $gitfile
                git checkout -- $gitfile
                    if [ $? -eq 0 ]
                       then
                       echo "git checkout successfully!"
                       else
                       echo "git checkout  failed! $gitfile is not in git.Let's remove it"
                       rm -rf $gitfile
                    fi
            fi
            
       done 
      return
    fi
 done
     echo "$1 is not a valid project!"
}

function reset_project_all()
{
   #dir=$(ls -lR rich_custom/$1 |awk '/^f/ {print $NF}')
   project_exist="false"
  for project in `ls rich_custom`
do
    project_exist="true"
   for file in `find rich_custom/$project`
do
    if [ -f $file ];then
    gitfile=${file##*rich_custom/$project/}
    echo $gitfile
    git checkout -- $gitfile
        if [ $? -eq 0 ]
       then
       echo "git checkout successfully!"
       else
       echo "git checkout  failed! $gitfile is not in git.Let's remove it"
       rm -rf $gitfile
       fi
   fi
done 
done
  if [ $project_exist != "true" ]
     then
     echo "no project exist."
     return
    fi
   echo "reset_project!"
}

unset COPY_MENU_CHOICES
function add_project_combo()
{
    for i in $(ls -l rich_custom/ |awk '/^d/ {print $NF}')
   do
    local new_project=$i
    local c
    for c in ${COPY_MENU_CHOICES[@]} ; do
        if [ "$new_project" = "$c" ] ; then
            return
        fi
    done
    COPY_MENU_CHOICES=(${COPY_MENU_CHOICES[@]} $new_project)
  done  
    
}

function print_project_menu()
{
    local uname=$(uname)
    echo
    echo "You're building on" $uname
    echo
    echo "Lunch menu... pick a project:"

    local i=1
    local choice
    for choice in ${COPY_MENU_CHOICES[@]}
    do
        echo "     $i. $choice"
        i=$(($i+1))
    done

    echo
}

function lunch_project()
{
 add_project_combo
   local answer
   
    if [ "$1" ] ; then
        answer=$1
    else
        print_project_menu
        echo -n "Which would you like? [project] "
        read answer
    fi

    if [ -z "$answer" ]
    then
        selection=""
    elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
    then
        if [ $answer -le ${#COPY_MENU_CHOICES[@]} ]
        then
            selection=${COPY_MENU_CHOICES[$(($answer-1))]}
        fi
    elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
    then
        selection=$answer
    fi

    if [ -z "$selection" ]
    then
        echo
        echo "Invalid lunch project"
        return
    fi
}

function copy_project()
{   
    if [ "$1" ] 
    then
        selection=$1
    else
        lunch_project     
    fi 
 if [ "$selection" ]
    then
   #dir=$(ls -lR rich_custom/$selection |awk '/^f/ {print $NF}')
   for project in `ls rich_custom`
 do
    if [ $selection = $project ]
      then
       rsync -raI rich_custom/$selection/   ./
        if [ $? -eq 0 ]
        then
        echo "copy_project successfully!"
        echo "$selection is a valid project!"
        else
        echo "copy_project failed!"
        fi
       return
    fi
 done
  echo "it is not a valid project!" 
  else
     echo "it is not a valid project!"
  fi
}


修改不引用自定义目录的apk
main.mk(build/core)

...
subdir_makefiles := \
    $(shell build/tools/findleaves.py --prune=$(OUT_DIR) 
--prune=.repo 
--prune=.git 
--prune=rich_custom           //add
 $(subdirs) Android.mk)
...

3:新键目录,例如一个叫A客户,一个是B客户

Paste_Image.png

4: 比如A客户修改了Launcher布局

Paste_Image.png

5:用法

当普通的编译初始化完成之后,就可以使用copy_project 和reset_project了

Paste_Image.png

出现copy_project successfully! 就成功了

然后 git status看看 到底修改后copy成功了没有,然后就可以进行正常编译了

6:如果想要出B客户的版本
那么先reset_project 之后在 重新copy_project B
reset_project 完了可以git status 看看成功了没有
之后就可以正常编译了

本文给自己做个记录。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,973评论 19 139
  • 爱情,是人类最美好的感情,当两颗心经历了长久的跋涉而最终走到了一起,像镜子一样相互照应,彼此如一,毫无猜忌,当他们...
    穆柯名阅读 353评论 0 0
  • 雪夜风华 檐下坠珠山添雪, 寒梅独秀著娉婷。 三生三世寻木主, 地久天长伴月生。 这是为柱胜和雪婷同学写的,灵感...
    猫眼小先生阅读 176评论 0 0
  • 方家养了棵铁树,高大约一米,羽状复叶展开直径也大约一米。这棵铁树长得极慢,据方爸说在他小时候就有这么大了,几十年过...
    悬诀阅读 684评论 0 2
  • 那些落下的、沉寂的,就会自我消亡。也不消重新拾起。
    M_152阅读 86评论 0 0