Android编译系统02-lunch
执行完. build/envsetup.sh之后,就选择执行lunch来选择所要编译的项目
lunch命令的实现如下:
function lunch()
{
//执行Uitype函数,在这里面是选择letv的UITYPE,这个是自己定义的。
uitype
if [ $? -ne 0 ];then
echo "** Invalid uitype!!!"
return 1
fi
//定义answer局部变量,用来存储选择的项
local answer
//如果带参数,比如lunch U4-eng-32,就直接把这个参数存在answer,如果不带参数,就通过用户自己选择
if [ "$1" ] ; then
answer=$1
else
print_lunch_menu
echo -n "Which would you like? [aosp_arm-eng] "
read answer
fi
local selection=
//根据用户选择,通过LUNCH_MENU_CHOICES数组找到对应的项,赋值给answer.最后赋值给selection
if [ -z "$answer" ]
then
selection=aosp_arm-eng
elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
then
if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
then
selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
fi
elif (echo -n $answer | grep -q -e "^[^-][^-]*-[^-][^-]*$")
then
selection=$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
//分析select变量,分享出product和variant,比如U4-user-32,product是U4,variant是eng。
export TARGET_BUILD_APPS=
local product=$(echo -n $selection | sed -e "s/-.*$//")
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
local variant=$(echo -n $selection | sed -e "s/^[^-]*-//" | sed -e "s/-.*$//")
check_variant $variant
if [ $? -ne 0 ]
then
echo
echo "** Invalid variant: '$variant'"
echo "** Must be one of ${VARIANT_CHOICES[@]}"
variant=
fi
local android_build_type=$(echo -n $selection | sed -e "s/$product-$variant//" | sed -e"s/-//")
if [ -z "$product" -o -z "$variant" ]
then
echo
return 1
fi
//
把变量导出export TARGET_PRODUCT=$product
export TARGET_BUILD_VARIANT=$variant
export TARGET_BUILD_TYPE=release
if [ -n "$android_build_type" ]
then
echo "ANDROID_BUILD_TYPE=$android_build_type"
export ANDROID_BUILD_TYPE=$android_build_type
fi
echo
//通过
set_stuff_for_environment来设置一些值,等会看。set_stuff_for_environment
- //打印出配置之后的项
printconfig
}
在最开始时候,会调用uitype,即把你选择的UITYPE类型赋值给变量LETV_UI_TYPE,这个变量在各个模块都有调用,用于选择编译。
来看set_stuff_for_environment函数,这里面有设置JAVA_HOME, title等一些操作
function set_stuff_for_environment()
{
settitle
set_java_home
setpaths
set_sequence_number
export ANDROID_BUILD_TOP=$(gettop)
# With this environment variable new GCC can apply colors to warnings/errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
export ASAN_OPTIONS=detect_leaks=0
}
settitle会设置当面终端的的显示,如下:

set_java_home
强制设置JAVA HOME为1.7,在这里面可以在不同的代码export不同的java_home
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
到此,基本上就完成项目的选择。接下来才是重头戏,make