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|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. Look at the source to view more functions. The complete list is:
EOF
# gettop是脚本内函数,功能:返回当前android代码树的顶层路径。前提是当前路径位于android代码树中
T=$(gettop)
# A变量 局部变量化
local A
A=""
# 查看envsetup.sh内容,且行首开始空格、制表符任意次,替换function为匹配的子串(函数名),按字符排升序、去掉重复
for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\/p" | sort | uniq`; do
# 替换出来的函数名 追加在A后 并打印
A="$A $i"
done
echo $A
}

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 #得到build变量(脚本内)的绝对路径
function get_abs_build_var()
{
# 得到源码树顶层目录
T=$(gettop)
# 源码树顶层目录有效性容错
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&
return
fi
# 进入顶层目录,设置build变量,
# 通过make指定build/core/config.mk文件
# --no-print-directory:不要再屏幕上打印"Entering directory..
# CALLED_FROM_SETUP=true:打印出dumpvar-abs-$1所表示的变量的值必须先设置CALLED_FROM_SETUP
# BUILD_SYSTEM:设置所有的编译脚本路径
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
command make --no-print-directory -f build/core/config.mk dumpvar-abs-$)
}
 function get_build_var()
{
T=$(gettop)
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&
return
fi
# 注释同上 唯一不同是目标dumpvar-$1不同
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
command make --no-print-directory -f build/core/config.mk dumpvar-$)
}

题外话:

BUILD_SYSTEM设置的Makefile目录——build/core目录下所有Makefile一览

config.mk详见一篇,此处一笔带过,只为得到CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core command make --no-print-directory -f build/core/config.mk dumpvar-$1”最终执行结果与过程。

..... include $(BUILD_SYSTEM)/dumpvar.mk

继续引入dumpvar.mk

 # MAKECMDGOALS 变量是传进来的目标dumpvar-abs-$1或 dumpvar-$1的abs-$1或$
dumpvar_goals := \
$(strip $(patsubst dumpvar-%,%,$(filter dumpvar-%,$(MAKECMDGOALS))))
ifdef dumpvar_goals ifneq ($(words $(dumpvar_goals)),)
$(error Only one "dumpvar-" goal allowed. Saw "$(MAKECMDGOALS)")
endif # If the goal is of the form "dumpvar-abs-VARNAME", then
# treat VARNAME as a path and return the absolute path to it.
absolute_dumpvar := $(strip $(filter abs-%,$(dumpvar_goals)))
# 是否有abs
ifdef absolute_dumpvar
dumpvar_goals := $(patsubst abs-%,%,$(dumpvar_goals))
ifneq ($(filter /%,$($(dumpvar_goals))),)
DUMPVAR_VALUE := $($(dumpvar_goals))
else
DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals))
endif
# get_abs_build_var()中dumpvar-abs-$1对应的
dumpvar_target := dumpvar-abs-$(dumpvar_goals)
else
DUMPVAR_VALUE := $($(dumpvar_goals))
# get_build_var()中dumpvar-$1对应的
dumpvar_target := dumpvar-$(dumpvar_goals)
endif .PHONY: $(dumpvar_target)
# 执行目标与执行语句
$(dumpvar_target):
@echo $(DUMPVAR_VALUE)

即打印

其中如有abs则ifdef absolute_dumpvar->DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals)),打印信息增加pwd绝对路径

如没有  则else->DUMPVAR_VALUE := $($(dumpvar_goals)),打印信息没有绝对路径

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

envsetup.sh使用方法:

book@book-virtual-machine:/work/android-5.0.$ source build/envsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/fugu/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/friendly-arm/tiny4412/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/moto/shamu/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including sdk/bash_completion/adb.bash
book@book-virtual-machine:/work/android-5.0.$ get_abs_build_var TARGET_PRODUCT
/work/android-5.0./full

build/envsetup.sh中hmm、get_abs_build_var、get_build_var解析的更多相关文章

  1. 【Android】在build/envsetup.sh中添加自己的命令(函数)

    由于测试的需要,经常需要手动刷入boot.img和system.img,把它写到envsetup.sh就可以每次使用一行命令来代替了: function flashtestimage(){ if [[ ...

  2. build/envsetup.sh内lunch解析

    ........ # 测试device是否存在且是一个目录 并且 只查找device目录4层以上的子目录,名字为vendorsetup.sh 并且 将命令执行的错误报告直接送往回收站 不显示在屏幕上 ...

  3. build/envsetup.sh 生成的命令详解表

    参考: https://wiki.cyanogenmod.org/w/Envsetup_help 它是一个.sh文件,用source后就生成android编译相关函数,具体如下. 速查 Invokin ...

  4. 【转】Android编译系统详解(一)——build/envsetup.sh

    出处 http://www.cloudchou.com/android/post-134.html 本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 准备好编译环境后,编译Rom的 ...

  5. 【转】Android source build/envsetup.sh学习笔记

    原文网址:http://blog.csdn.net/mliubing2532/article/details/7567164 如果你只需要修改某一个模块的内容,但是却每次都要执行make, 最后等待很 ...

  6. [转载]Android 编译环境 build/envsetup.sh分析

    2013-12-23 11:28:40 转载自: http://blog.csdn.net/evilcode/article/details/7005757 请到转载地址阅读原文, 转载以备查询.

  7. Android编译执行envsetup.sh,产生工具命令m、mm、mmm、mmma、tapas 、croot、cgrep、jgrep、 resgrep、godir

    一般来说编译一个sdk或者一个比较大的工程项目,第一步都是执行 envsetup.sh这个脚本,比如编译android,qt源码以及其他一些嵌入式的sdk. 而且执行的时候需要特别注意使用 sourc ...

  8. Building System之 get_abs_build_var() && get_build_var()

    点击打开链接 1.get_abs_build_var() 和 get_build_var()的实现都在build/envsetup.sh中. 2.在buld目录下grep这两个函数可知:这两个函数只在 ...

  9. m mm等和envsetup.sh

    envsetup.sh简介: Android 完成编译的时候先执行 source build/envsetup.sh.在这个shell 脚本中定义了 help, croot, m, mm, mmm 等 ...

随机推荐

  1. [OJ] Matrix Zigzag Traversal

    LintCode #46. Matrix Zigzag Traversal (Easy) class Solution { public: vector<int> printZMatrix ...

  2. zip压缩解压缩 项目icsharpcode-SharpZipLib-e012155

    大家可以到http://www.icsharpcode.net/opensource/sharpziplib/ 下载SharpZiplib的最新版本,支持Zip, GZip, BZip2 和Tar格式 ...

  3. 根据指定的commit查找对应的log

    find commit by hash sha in git 问题: I need to find a commit in Git by given hash SHA. For example, if ...

  4. vi的撤销命令

    'u' : 撤销上一个编辑操作 'ctrl + r' : 恢复,即回退前一个命令 'U' : 行撤销,撤销所有在前一个编辑行上的操作 使用u 和 CTRL+R 命令可以恢复到任何编辑过的状态

  5. Linux kernel get_prng_bytes函数数字错误漏洞

    漏洞名称: Linux kernel get_prng_bytes函数数字错误漏洞 CNNVD编号: CNNVD-201310-142 发布时间: 2013-10-11 更新时间: 2013-10-1 ...

  6. 使用Xcode Instruments Leak解决内存泄漏问题

    iOS 5.0之后apple引入了Xcode编译器特性ARC(Automatic Reference Counting,自动引用计数)来帮助开发者管理内存,但为了追求app的高性能与减少安装包大小,工 ...

  7. 系统交易策略 hylt

    最令我尴尬的事情,莫过于很多朋友来到网站,不知道我说的是什么.大多数人以为鬼仆是推销软件的.其实这里理解是错的,特别是一些软件制作与经销商,更出 于推销的目的,故意夸大产品性能,模糊交易系统与一般行情 ...

  8. UIView frame, bounds and center

    http://stackoverflow.com/questions/5361369/uiview-frame-bounds-and-center Since the question I asked ...

  9. 批处理(.bat)中使用相对路径

    批处理中使用相对路径,只需要用cd /d %~dp0代替绝对路径就可以了. ->cd /d ->%~dp0 %0为当前批处理文件 %~d0 是指批处理所在的盘符 %~dp0 是指批处理所在 ...

  10. (5/18)重学Standford_iOS7开发_视图控制器生命周期_课程笔记

    第五课: 1.UITextView @property (nonatomic, readonly) NSTextStorage *textStorage;//注意为只读属性,因此不能直接更改内容,NS ...