function help() # 显示帮助信息 function get_abs_build_var() # 获取绝对变量 function get_build_var() # 获取绝对变量 function check_product() # 检查product function check_variant() # 检查变量 function setpaths() # 设置文件路径 function printconfig() # 打印配置 function set_stuff_for_environment() # 设置环境变量 function set_sequence_number() # 设置序号 function settitle() # 设置标题 function choosetype() # 设置type function chooseproduct() # 设置product function choosevariant() # 设置variant function tapas() # 功能同choosecombo function choosecombo() # 设置编译参数 function add_lunch_combo() # 添加lunch项目 function print_lunch_menu() # 打印lunch列表 function lunch() # 配置lunch function m() # make from top function findmakefile() # 查找makefile function mm() # make from current directory function mmm() # make the supplied directories function croot() # 回到根目录 function cproj() function pid() function systemstack() function gdbclient() function jgrep() # 查找java文件 function cgrep() # 查找c/cpp文件 function resgrep() function tracedmdump() function runhat() function getbugreports() function startviewserver() function stopviewserver() function isviewserverstarted() function smoketest() function runtest() function godir () # 跳到指定目录 405
# add_lunch_combo函数被多次调用,就是它来添加Android编译选项 # Clear this variable. It will be built up again when the vendorsetup.sh 406 # files are included at the end of this file. # 清空LUNCH_MENU_CHOICES变量,用来存在编译选项 407 unset LUNCH_MENU_CHOICES 408 function add_lunch_combo() 409 { 410 local new_combo=$1 # 获得add_lunch_combo被调用时的参数 411 local c # 依次遍历LUNCH_MENU_CHOICES里的值,其实该函数第一次调用时,该值为空 412 for c in ${LUNCH_MENU_CHOICES[@]} ; do 413 if [ "$new_combo" = "$c" ] ; then # 如果参数里的值已经存在于LUNCH_MENU_CHOICES变量里,则返回 414 return 415 fi 416 done # 如果参数的值不存在,则添加到LUNCH_MENU_CHOICES变量里 417 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) 418 }
# 这是系统自动增加了一个默认的编译项 generic-eng 420 # add the default one here 421 add_lunch_combo generic-eng # 调用上面的add_lunch_combo函数,将generic-eng作为参数传递过去 422 423 # if we‘re on linux, add the simulator. There is a special case 424 # in lunch to deal with the simulator 425 if [ "$(uname)" = "Linux" ] ; then 426 add_lunch_combo simulator 427 fi
# 下面的代码很重要,它要从vendor目录下查找vendorsetup.sh文件,如果查到了,就加载它 1037 # Execute the contents of any vendorsetup.sh files we can find. 1038 for f in `/bin/ls vendorbuild/vendorsetup.sh 2> /dev/null` 1039 do 1040 echo "including $f" 1041 . $f # 执行找到的脚本,其实里面就是厂商自己定义的编译选项 1042 done 1043 unset f
if [ "$1" ] ; then # lunch后面直接带参数 answer=$1 else # lunch后面不带参数,则打印处所有的target product和variant菜单提供用户选择 print_lunch_menu echo -n "Which would you like? [generic-eng] " read answer fi
local selection=
if [ -z "$answer" ] then # 如果用户在菜单中没有选择,直接回车,则为系统缺省的generic-eng selection=generic-eng elif [ "$answer" = "simulator" ] then # 如果是模拟器 selection=simulator elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") then # 如果answer是选择菜单的数字,则获取该数字对应的字符串 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] then selection=${LUNCH_MENU_CHOICES[$(($answer-$_arrayoffset))]} fi # 如果 answer字符串匹配 *-*模式(*的开头不能为-) elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") then selection=$answer fi
if [ -z "$selection" ] then echo echo "Invalid lunch combo: $answer" return 1 fi
# special case the simulator if [ "$selection" = "simulator" ] then # 模拟器模式 export TARGET_PRODUCT=sim export TARGET_BUILD_VARIANT=eng export TARGET_SIMULATOR=true export TARGET_BUILD_TYPE=debug else
# 将 product-variant模式中的product分离出来 local product=$(echo -n $selection | sed -e "s/-.*$//")
# 检查之,调用关系 check_product()->get_build_var()->build/core/config.mk比较罗嗦,不展开了 check_product $product if [ $? -ne 0 ] then echo echo "** Don‘t have a product spec for: ‘$product‘" echo "** Do you have the right repo manifest?" product= fi
# 将 product-variant模式中的variant分离出来 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
# 检查之,看看是否在 (user userdebug eng) 范围内 check_variant $variant if [ $? -ne 0 ] then echo echo "** Invalid variant: ‘$variant‘" echo "** Must be one of ${VARIANT_CHOICES[@]}" variant= fi
if [ -z "$product" -o -z "$variant" ] then echo return 1 fi # 导出环境变量,这里很重要,因为后面的编译系统都是依赖于这里定义的几个变量的 export TARGET_PRODUCT=$product export TARGET_BUILD_VARIANT=$variant export TARGET_SIMULATOR=false export TARGET_BUILD_TYPE=release fi # !simulator