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