1,source build/envsetup.sh
source 是用来运行 shell 脚本的命令 功能和 "." 和相同,
因此 也可以写作: . build/envsetup.sh
运行效果结果如下:
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$
那么上面的结果是如何产生的呢?运行envsetup.sh的发生了什么呢?我们自己添加的客户分支是如何加入到 lunch 的选项中去的呢?
a,关于envsetup
envsetup 为我们提供了很多的shell脚本函数,
例如 envsetup 开头的第一个函数 hmm,
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
}
在运行
envsetup
.sh以后 就可以使用 hmm命令了,此时终端会输出命令帮助提示。
简单来说,envsetup.sh 给我们提供了一组自定义的 shell命令,而lunch 就是这些自定义命令中的一个。
2,lunch 命令
我们依然来看 envsetup.sh,在envsetup.sh 中可以找到 lunch 定义
function lunch()
{
local answer
if [ "$1" ] ; then #lunch可以接受一个输入参数,例如 lunch xxx-userdebug 此时直接选择了xxx。
answer=$1