最近在搞MTK代码时,发现如果直接删除所有gitignore文件和.git文件夹时,会出现编译失败。但是由于我需要把代码上传到公司内部的git服务器,必须要删掉它们,所以解决build error只能通过改编译脚本来实现了。
可能每个人遇到的build error不一样,我遇到的是在编译external/chromium_org/third_party/angle/会去寻找.git/index文件。这个错误主要是和target平台脚本有关系,我这里用的是arm64位的芯片,所以我需要去改external/chromium_org/third_party/angle/src/commit_id.target.linux-arm.mk和external/chromium_org/third_party/angle/src/commit_id.target.linux-arm64.mk两个文件,把两个文件23行的$(LOCAL_PATH)/third_party/angle/.git/index $(GYP_TARGET_DEPENDENCIES)注释掉即可。现在终于可以编译过了,但是对android的编译系统产生了兴趣,就花一天学习一下shell,花一天研究一下envsetup.sh脚本。还是很有收获的。下面进入正题,让我们一起来解析一下envsetup.sh:
此脚本在build/envsetup.sh,代码比较多,我就不一一罗列代码了。
1、此脚本让我第一个有收获的地方是一段注释:
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|arm64|x86_64|mips64] [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.
To limit the modules being built use the syntax: mmm dir/:target1,target2.
- 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.
- ggrep: Greps on all local Gradle files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.
以前只对lunch、mm、mmm比较熟悉,看了一下此命令我觉得croot、cgrep、jgrep、resgrep、sgrep、godir对于开发者来说还是很有用的。
2、我看脚本的时候发现函数是需要获得android根目录,而根目录是用gettop获得的
function gettop
{
local TOPFILE=build/core/envsetup.mk
if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
# The following circumlocution ensures we remove symlinks from TOP.
(cd $TOP; PWD= /bin/pwd)
else
if [ -f $TOPFILE ] ; then
# The following circumlocution (repeated below as well) ensures
# that we record the true directory name and not one that is
# faked up with symlink names.
PWD= /bin/pwd
else
local HERE=$PWD
T=
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
\cd ..
T=`PWD= /bin/pwd -P`
done
\cd $HERE
if [ -f "$T/$TOPFILE" ]; then
echo $T
fi
fi
fi
}
函数中的build/core/envsetup.sh暂时先不分析了,现在可以获得android代码的根目录了。
3、evnsetup.sh脚本里的其他命令
function help() # 显示帮助信息
function get_abs_build_var() # Get the value of a build variable as an absolute path.
function get_build_var() # Get the exact value of a build variable.
function check_product() # check to see if the supplied product is one we can build
function check_variant() # check to see if the supplied variant is valid
function setpaths() # 设置编译链和生成文件路径
function printconfig() # 打印配置
function set_stuff_for_environment() # 设置环境变量
function set_sequence_number() # 设置序号
function settitle() # 设置标题
function choosetype() # 设置type
function chooseproduct() # 设置product
function choosevariant() # 设置variant
function tapas() # 功能同choosecombo
function choosecombo() # 设置编译参数
function add_lunch_combo() # 添加lunch项目
function print_lunch_menu() # 打印lunch列表
function lunch() # 配置lunch
function m() # make from top
function findmakefile() # 查找makefile
function mm() # make from current directory
function mmm() # make the supplied directories
function croot() # 回到根目录
function cproj()
function pid()
function systemstack()
function gdbclient()
function jgrep() # 查找java文件
function cgrep() # 查找c/cpp文件
function resgrep()
function tracedmdump()
function runhat()
function getbugreports()
function startviewserver()
function stopviewserver()
function isviewserverstarted()
function smoketest()
function runtest()
function godir () # 跳到指定目录
<pre name="code" class="javascript"><pre name="code" class="java"><pre name="code" class="plain">