xxx@xxx:~/xxx/kitkat$ . build/envsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including sdk/bash_completion/adb.bash
buddy@RD3-199:~/C_BQ_T628VX_01/kitkat-mstar-master$
function hmm() {
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
- mma: Builds all of the modules in the current directory, and their dependencies.
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
Look at the source to view more functions. The complete list is:
EOF
T=$(gettop) #gettop也是envsetup.sh 中定義的一個 函數,有興趣的童鞋可以看一下具體實現
local A
A=""
for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
A="$A $i"
done
echo $A
}
function lunch()
{
local answer
if [ "$1" ] ; then #lunch可以接受一個輸入參數,例如 lunch xxx-userdebug 此時直接選擇了xxx。
answer=$1
else # 如果沒有輸入參數,則打印選擇菜單,並等待選擇輸入
print_lunch_menu
echo -n "Which would you like? [aosp_arm-eng] "
read answer
fi
local selection=
if [ -z "$answer" ] #如果answer爲空
then
selection=aosp_arm-eng #默認選擇
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
fi
if [ -z "$selection" ]
then
echo
echo "Invalid lunch combo: $answer"
return 1
fi
export TARGET_BUILD_APPS=
#提取"-"位置以前的字符串 這裏是“
xxx”
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/^[^\-]*-//")
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_BUILD_TYPE=release
echo
set_stuff_for_environment
printconfig
}
function print_lunch_menu()
{
local uname=$(uname)
echo
echo "You're building on" $uname
echo
echo "Lunch menu... pick a combo:"
local i=1
local choice
for choice in ${LUNCH_MENU_CHOICES[@]} #這裏輸出的就是我們看到的 lunch 命令的輸出結果
do
echo " $i. $choice"
i=$(($i+1))
done
echo
}
# Clear this variable. It will be built up again when the vendorsetup.sh
# files are included at the end of this file.
unset LUNCH_MENU_CHOICES
#這函數就是向lunch命令添加選擇項 客戶分支裏 vendorsetup.sh 裏的那一行代碼的用途就是添加lunch選擇項
function add_lunch_combo()
{
local new_combo=$1
local c
for c in ${LUNCH_MENU_CHOICES[@]} ; do
if [ "$new_combo" = "$c" ] ; then
return
fi
done
LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
}
# add the default one here
add_lunch_combo aosp_arm-eng
add_lunch_combo aosp_x86-eng
add_lunch_combo aosp_mips-eng
add_lunch_combo vbox_x86-eng
# check to see if the supplied product is one we can build
function check_product()
{
T=$(gettop)
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
return
fi
#設置環境變量
CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
TARGET_PRODUCT=$1 \
TARGET_BUILD_VARIANT= \
TARGET_BUILD_TYPE= \
TARGET_BUILD_APPS= \
get_build_var TARGET_DEVICE > /dev/null #
get_build_var # hide successful answers, but allow the errors to show
}
# Get the exact value of a build variable.
function get_build_var()
{
T=$(gettop)
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
return
fi
#執行config.mk配置相關的內容,
#進一步依次執行envsetup.mk,到product_config.mk,
#最終獲得TARGET_DEVICE變量的內容。
CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
}
#三種模式 user userdebug eng
VARIANT_CHOICES=(user userdebug eng)
# check to see if the supplied variant is valid
function check_variant()
{
for v in ${VARIANT_CHOICES[@]}
do
if [ "$v" = "$1" ]
then
return 0
fi
done
return 1
}
#1.eng,那麼其編譯進去的內容包括:
· Intended for platform-level debugging
· Installs modules tagged with: eng, debug, user, and/or development
· Installs non-APK modules that have no tags specified
· Installs APKs according to the product definition files, in addition to tagged APKs
· Sets ro.secure=1
· Sets ro.debuggable=0
· Sets ro.kernel.android.checkjni=1
· adbd is enabled by default
#2.user,那麼其編譯進去的內容包括:
· Intended to be the final release
· Installs modules tagged as user
· Installs non-APK modules that have no tags specified
· Installs APKs according to the product definition files (tags are ignored for APK modules)
· Sets ro.secure=1
· Sets ro.debuggable=0
· adbd is disabled by default
#3.userdebug,那麼其編譯進去的內容包括:
the same as user, except:
· Intended for limited debugging
· Installs modules tagged with debug
· Sets ro.debuggable=1
· adbd is enabled by default
function set_stuff_for_environment()
{
settitle
set_java_home
setpaths
set_sequence_number
# MStar Android Patch Begin
set_ota
# MStar Android Patch End
export ANDROID_BUILD_TOP=$(gettop)
}
# Execute the contents of any vendorsetup.sh files we can find.
# 檢測 device 目錄和vendor 目錄是否存在 ,並且找到 目錄下的vendorsetup.sh .最多目錄層次四層
for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
`test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
do
echo "including $f"
. $f # 找到vendorsetup.sh 並執行,
done
unset f
addcompletions
function addcompletions()
{
local T dir f
# Keep us from trying to run in something that isn't bash.
if [ -z "${BASH_VERSION}" ]; then
return
fi
# Keep us from trying to run in bash that's too old.
if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
return
fi
dir="sdk/bash_completion"
if [ -d ${dir} ]; then
# 掃描 /sdk/bash_completion 目錄並允許 .bash 文件
for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
echo "including $f"
. $f #運行bash文件
done
fi
}