Android编译系统01-envsetup.sh

Android编译系统01-envsetup.sh

以Android M为例
编译Android,按照google官方的指引,完成code下载之后,就会先执行一下$ source build/envsetup.sh或者$ . build/envsetup.sh来初始化整个编译环境。最直观的一感觉就是多了一些命令,比较用来选择编译项目的lunch,分别可以在java源码中,或者CPP,C源码中进行grep的定制命令jgrep和cgrep,croot进入源码基层目录,等等这些命令。那么接下来就来分析这个脚本。

1,脚本先执行add_lunch_combo aosp相关的默认的一些lunch项
  1. add_lunch_combo aosp_arm-eng  
  2. add_lunch_combo aosp_arm64-eng
  3. add_lunch_combo aosp_mips-eng
  4. add_lunch_combo aosp_mips64-eng
  5. add_lunch_combo aosp_x86-eng
  6. add_lunch_combo aosp_x86_64-eng
add_lunch_combo函数也是在这个脚本里面,这个函数很简单,把后面带的参数,比如aosp_arm-eng等等全部写到LUNCH_MENU_CHOICES这个数组里面。
接下来就调用各个device和vendor下面一些厂商自己定义的vendorsetup.sh里面的add_lunch_combo把各自平台的编译选项加入到LUNCH_MENU_CHOICES数组里面,
  1. for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
  2. `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
  3. do
  4. echo "including $f"
  5. . $f //执行对应的vendorsetup.sh
  6. done
在vendorsetup.sh也是调用add_lunch_combo U4-eng-32 等等
这里面会打印出来including…,也就是执行.build/envsetup.sh里面的打印。
除此之外同时还会添加adb相关bash,执行并打印including sdk/bash_completion/adb.bash,是在这个函数里面实现的
  1. function addcompletions()
  2. {
  3. local T dir f
  4. # Keep us from trying to run in something that isn't bash.
  5. if [ -z "${BASH_VERSION}" ]; then
  6. return
  7. fi
  8. # Keep us from trying to run in bash that's too old.
  9. if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
  10. return
  11. fi
  12. dir="sdk/bash_completion"
  13. if [ -d ${dir} ]; then
  14. for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
  15. echo "including $f"
  16. . $f
  17. done
  18. fi
  19. }
2,除些之外还会执行一句:
complete -F _lunch lunch 
这是对lunch命令TAG补全键的定义,实现在_lunch里面,会打印出LUNCH_MENU_CHOICES数组里面的值。

3,执行完这个脚本之后,会增加很多命令,可以通过hmm打印出帮助信息,一个命令对应这个脚本里面的一个函数。
  1. xugangfeng@LETV-U0:~/sc/letv/U4$ hmm
  2. Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
  3. - lunch: lunch <product_name>-<build_variant>
  4. - tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
  5. - croot: Changes directory to the top of the tree.
  6. - m: Makes from the top of the tree.
  7. - mm: Builds all of the modules in the current directory, but not their dependencies.
  8. - mmm: Builds all of the modules in the supplied directories, but not their dependencies.
  9. To limit the modules being built use the syntax: mmm dir/:target1,target2.
  10. - mma: Builds all of the modules in the current directory, and their dependencies.
  11. - mmma: Builds all of the modules in the supplied directories, and their dependencies.
  12. - cgrep: Greps on all local C/C++ files.
  13. - ggrep: Greps on all local Gradle files.
  14. - jgrep: Greps on all local Java files.
  15. - resgrep: Greps on all local res/*.xml files.
  16. - mangrep: Greps on all local AndroidManifest.xml files.
  17. - sepgrep: Greps on all local sepolicy files.
  18. - sgrep: Greps on all local source files.
  19. - godir: Go to the directory containing a file.
  20. Environemnt options:
  21. - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
  22. ASAN_OPTIONS=detect_leaks=0 will be set by default until the
  23. build is leak-check clean.
  24. Look at the source to view more functions. The complete list is:
  25. addcompletions add_lunch_combo add_uitype_combo cgrep check_product check_uitype check_variant choosecombo chooseproduct choosetype choosevariant core coredump_enable coredump_setup cproj croot findmakefile get_abs_build_var getbugreports get_build_var getdriver getlastscreenshot get_make_command getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop ggrep godir hmm is isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m make mangrep mgrep mm mma mmm mmma pez pid printconfig print_lunch_menu print_uitype_menu qpid rcgrep resgrep runhat runtest sepgrep set_java_home setpaths set_sequence_number set_stuff_for_environment settitle sgrep smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump treegrep uitype
函数的具体实现就不说了,可行阅读函数。有调试的,也有编译的。其实mma是非常有用的编译命令,当所编译的模块有依赖其它库的时候,mm单独是编译不过的,需要使用mma是依赖就可以完成。
reference to:
TOP