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

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

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

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

编译版本,多个客户小幅度修改方案_第1张图片
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客户

编译版本,多个客户小幅度修改方案_第2张图片
Paste_Image.png

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

编译版本,多个客户小幅度修改方案_第3张图片
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 看看成功了没有
之后就可以正常编译了

本文给自己做个记录。

你可能感兴趣的:(编译版本,多个客户小幅度修改方案)