Android8,source与lunch流程解析
source 流程
# build/make/envsetup.sh
----
# Execute the contents of any vendorsetup.sh files we can find.
for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \`test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
doecho "including $f". $f # 查找device、vendor、product下所有vendorsetup.sh并执行
done
unset faddcompletions # 增加支持补全的命令...dir="sdk/bash_completion"if [ -d ${dir} ]; thenfor f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do // 目前仅有adb相关;echo "including $f". $fdoneficomplete -C "bit --tab" bit
由上可知,source build/envsetup.sh 动作未完成了如下两个主要工作:
- 导入了很多函数,命令;
- 加载Target,为后续lunch做准备;
其中关于如何加入新Target,有需要说明:
- 所有可lunch的选项被收集到数组:LUNCH_MENU_CHOICES
- 仅可使用add_lunch_combo增加新目标到LUNCH_MENU_CHOICES;
- 在vendorsetup.sh文件中调用add_lunch_combo,才可以在后续的lunch中被显示;
lunch流程
function lunch()print_lunch_menuecho -n "Which would you like? [aosp_arm-eng] " // 打印lunch的目标;read answerselection=${LUNCH_MENU_CHOICES[$(($answer-1))]} // 选中目标product=${selection%%-*} # Trim everything after first dashvariant_and_version=${selection#*-} # Trim everything up to first dashTARGET_PRODUCT=$product \TARGET_BUILD_VARIANT=$variant \TARGET_PLATFORM_VERSION=$version \build_build_var_cache build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \command make --no-print-directory -f build/core/config.mk dump-many-vars \ // 指定Makefile文件,目标为dump-many-varsDUMP_MANY_VARS="$cached_vars" \ // 信息DUMP_MANY_ABS_VARS="$cached_abs_vars" \DUMP_VAR_PREFIX="var_cache_" \ // 指定前缀DUMP_ABS_VAR_PREFIX="abs_var_cache_"` // build/core/config.mk...include $(BUILD_SYSTEM)/dumpvar.mk // 再引入dumpvar.mk文件...dump-many-vars : // 终端上可见的打印@$(foreach v, $(filter-out report_config, $(DUMP_MANY_VARS)),\echo "$(DUMP_VAR_PREFIX)$(v)='$($(v))'";)ifneq ($(filter report_config, $(DUMP_MANY_VARS)),)@# Construct a special variable for report_config.@# Escape \` to defer the execution of report_config_sh to preserve the line breaks.@echo "$(DUMP_VAR_PREFIX)report_config=\`$(report_config_sh)\`"endif@$(foreach v, $(sort $(DUMP_MANY_ABS_VARS)),\echo "$(DUMP_ABS_VAR_PREFIX)$(v)='$(abspath $($(v)))'";)eval "4build_dicts_script" // 执行命令,收集编译参数export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT) // 导出目标信息到终端export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)export TARGET_BUILD_TYPE=release set_stuff_for_environmentsettitle // 终端的名字set_java_homesetpaths // 安卓相关路径信息set_sequence_number // 未知export ANDROID_BUILD_TOP=$(gettop)# With this environment variable new GCC can apply colors to warnings/errorsexport GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' // GCC 编译时,各信息的颜色显示;export ASAN_OPTIONS=detect_leaks=0 printconfig // lunch后的可见打印,即是build_build_var_cache步骤收集的编译参数report_configdestroy_build_var_cache // 移除编译参数缓存
编译参数初始化与获取
lunch过程中变量有如下区分:
- 通过export,直接导出到终端(source方式);