Android编译系统02-lunch

Android编译系统02-lunch

执行完. build/envsetup.sh之后,就选择执行lunch来选择所要编译的项目

lunch命令的实现如下:
  1. function lunch()
  2. {
  3.     //执行Uitype函数,在这里面是选择letv的UITYPE,这个是自己定义的。
  4. uitype
  5. if [ $? -ne 0 ];then
  6. echo "** Invalid uitype!!!"
  7. return 1
  8. fi
  9.     //定义answer局部变量,用来存储选择的项
  10. local answer
  11.     //如果带参数,比如lunch U4-eng-32,就直接把这个参数存在answer,如果不带参数,就通过用户自己选择
  12. if [ "$1" ] ; then
  13. answer=$1
  14. else
  15. print_lunch_menu
  16. echo -n "Which would you like? [aosp_arm-eng] "
  17. read answer
  18. fi
  19. local selection=
  20.     //根据用户选择,通过LUNCH_MENU_CHOICES数组找到对应的项,赋值给answer.最后赋值给selection
  21. if [ -z "$answer" ]
  22. then
  23. selection=aosp_arm-eng
  24. elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
  25. then
  26. if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
  27. then
  28. selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
  29. fi
  30. elif (echo -n $answer | grep -q -e "^[^-][^-]*-[^-][^-]*$")
  31. then
  32. selection=$answer
  33. elif (echo -n $answer | grep -q -e "^[^-][^-]*-[^-][^-]*-[^-][^-]*$")
  34. then
  35. selection=$answer
  36. fi
  37. if [ -z "$selection" ]
  38. then
  39. echo
  40. echo "Invalid lunch combo: $answer"
  41. return 1
  42. fi
  43.     //分析select变量,分享出product和variant,比如U4-user-32,product是U4,variant是eng。
  44. export TARGET_BUILD_APPS=
  45. local product=$(echo -n $selection | sed -e "s/-.*$//")
  46. check_product $product
  47. if [ $? -ne 0 ]
  48. then
  49. echo
  50. echo "** Don't have a product spec for: '$product'"
  51. echo "** Do you have the right repo manifest?"
  52. product=
  53. fi
  54. local variant=$(echo -n $selection | sed -e "s/^[^-]*-//" | sed -e "s/-.*$//")
  55. check_variant $variant
  56. if [ $? -ne 0 ]
  57. then
  58. echo
  59. echo "** Invalid variant: '$variant'"
  60. echo "** Must be one of ${VARIANT_CHOICES[@]}"
  61. variant=
  62. fi
  63. local android_build_type=$(echo -n $selection | sed -e "s/$product-$variant//" | sed -e"s/-//")
  64. if [ -z "$product" -o -z "$variant" ]
  65. then
  66. echo
  67. return 1
  68. fi
  69. //    把变量导出
  70. export TARGET_PRODUCT=$product
  71. export TARGET_BUILD_VARIANT=$variant
  72. export TARGET_BUILD_TYPE=release
  73. if [ -n "$android_build_type" ]
  74. then
  75. echo "ANDROID_BUILD_TYPE=$android_build_type"
  76. export ANDROID_BUILD_TYPE=$android_build_type
  77. fi
  78. echo
  79. //通过set_stuff_for_environment来设置一些值,等会看。
  80. set_stuff_for_environment
  81. //打印出配置之后的项
  82. printconfig
  83. }
在最开始时候,会调用uitype,即把你选择的UITYPE类型赋值给变量LETV_UI_TYPE,这个变量在各个模块都有调用,用于选择编译。
来看set_stuff_for_environment函数,这里面有设置JAVA_HOME, title等一些操作
  1. function set_stuff_for_environment()
  2. {
  3. settitle
  4. set_java_home
  5. setpaths
  6. set_sequence_number
  7. export ANDROID_BUILD_TOP=$(gettop)
  8. # With this environment variable new GCC can apply colors to warnings/errors
  9. export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
  10. export ASAN_OPTIONS=detect_leaks=0
  11. }
settitle会设置当面终端的的显示,如下:
 set_java_home
强制设置JAVA HOME为1.7,在这里面可以在不同的代码export不同的java_home
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
到此,基本上就完成项目的选择。接下来才是重头戏,make
TOP