Building System之 get_abs_build_var() && get_build_var()
1、get_abs_build_var() 和 get_build_var()的实现都在build/envsetup.sh中。
2、在buld目录下grep这两个函数可知:这两个函数只在build/envsetup.sh脚本中使用。
言归正传,贴代码
- # Get the value of a build variable as an absolute path.
- function get_abs_build_var()
- {
- T=$(gettop)
- if [ ! "$T" ]; then
- echo "Couldn't locate the top of the tree. Try setting TOP." >&2
- return
- fi
- (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
- command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
- }
- # 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
- (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
- command make --no-print-directory -f build/core/config.mk dumpvar-$1)
- }
这两个shell函数的实现很相似,都是通过make指定build/core/config.mk文件,唯一不同的地方是target目标不同。
接下来我们分析config.mk文件。
config.mk文件开头的注释:
- # This is included by the top-level Makefile.
- # It sets up standard variables based on the
- # current configuration and platform, which
- # are not specific to what is being built.
根据注释,我们可知config.mk文件主要是配置变量。
而且,config.mk 文件最后一行包含的$(BUILD_SYSTEM)/dumpvar.mk用于获取一些变量。
接下来我们分析dumpvar.mk文件。
- # ---------------------------------------------------------------
- # the setpath shell function in envsetup.sh uses this to figure out
- # what to add to the path given the config we have chosen.
- ifeq ($(CALLED_FROM_SETUP),true) # 在get_abs_build_var() 和 get_build_var()函数中,CALLED_FROM_SETUP=true,走if分支。
- ifneq ($(filter /%,$(HOST_OUT_EXECUTABLES)),)
- # HOST_OUT_EXECUTABLES变量是在envsetup.mk文件中设置的。
- ABP:=$(HOST_OUT_EXECUTABLES)
- else
- ABP:=$(PWD)/$(HOST_OUT_EXECUTABLES)
- endif
- ANDROID_BUILD_PATHS := $(ABP) # 应该是 out/host/linux-x86/bin
- ANDROID_PREBUILTS := prebuilt/$(HOST_PREBUILT_TAG)
- # HOST_PREBUILT_TAG变量是在envsetup.mk文件中设置的。应该是 linux-x86
- ANDROID_GCC_PREBUILTS := prebuilts/gcc/$(HOST_PREBUILT_TAG)
- # The "dumpvar" stuff lets you say something like
- #
- # CALLED_FROM_SETUP=true \
- # make -f config/envsetup.make dumpvar-TARGET_OUT
- # or
- # CALLED_FROM_SETUP=true \
- # make -f config/envsetup.make dumpvar-abs-HOST_OUT_EXECUTABLES
- #
- # The plain (non-abs) version just dumps the value of the named variable.
- # The "abs" version will treat the variable as a path, and dumps an
- # absolute path to it.
- #
- dumpvar_goals := \
- $(strip $(patsubst dumpvar-%,%,$(filter dumpvar-%,$(MAKECMDGOALS))))
- # MAKECMDGOALS 变量就是传进来的目标dumpvar-abs-$1或 dumpvar-$1。
- ifdef dumpvar_goals
- ifneq ($(words $(dumpvar_goals)),1)
- $(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)))
- ifdef absolute_dumpvar
- dumpvar_goals := $(patsubst abs-%,%,$(dumpvar_goals))
- ifneq ($(filter /%,$($(dumpvar_goals))),)
- DUMPVAR_VALUE := $($(dumpvar_goals))
- else
- DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals))
- endif
- dumpvar_target := dumpvar-abs-$(dumpvar_goals)
- else
- DUMPVAR_VALUE := $($(dumpvar_goals))
- dumpvar_target := dumpvar-$(dumpvar_goals)
- endif
- .PHONY: $(dumpvar_target)
- $(dumpvar_target):
- @echo $(DUMPVAR_VALUE)
- # DUMPVAR_VALE其实就是dumpvar-$1中的$1变量的值。
- endif # dumpvar_goals
- ifneq ($(dumpvar_goals),report_config)
- # PRINT_BUILD_CONFIG 在envsetup.mk中被定义为true
- PRINT_BUILD_CONFIG:=
- endif
- endif # CALLED_FROM_SETUP
- ifneq ($(PRINT_BUILD_CONFIG),)
- HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
- $(info ============================================)
- $(info PLATFORM_VERSION_CODENAME=$(PLATFORM_VERSION_CODENAME))
- $(info PLATFORM_VERSION=$(PLATFORM_VERSION))
- $(info TARGET_PRODUCT=$(TARGET_PRODUCT))
- $(info TARGET_BUILD_VARIANT=$(TARGET_BUILD_VARIANT))
- $(info TARGET_BUILD_TYPE=$(TARGET_BUILD_TYPE))
- $(info TARGET_BUILD_APPS=$(TARGET_BUILD_APPS))
- $(info TARGET_ARCH=$(TARGET_ARCH))
- $(info TARGET_ARCH_VARIANT=$(TARGET_ARCH_VARIANT))
- $(info TARGET_CPU_VARIANT=$(TARGET_CPU_VARIANT))
- $(info TARGET_2ND_ARCH=$(TARGET_2ND_ARCH))
- $(info TARGET_2ND_ARCH_VARIANT=$(TARGET_2ND_ARCH_VARIANT))
- $(info TARGET_2ND_CPU_VARIANT=$(TARGET_2ND_CPU_VARIANT))
- $(info HOST_ARCH=$(HOST_ARCH))
- $(info HOST_OS=$(HOST_OS))
- $(info HOST_OS_EXTRA=$(HOST_OS_EXTRA))
- $(info HOST_BUILD_TYPE=$(HOST_BUILD_TYPE))
- $(info BUILD_ID=$(BUILD_ID))
- $(info OUT_DIR=$(OUT_DIR))
- $(info ============================================)
- endif
小结:
大多数的变量配置都是在config.mk中设置的,尤其是其包含的envsetup.mk文件。所以,就在config.mk的最后包含dumpvar.mk文件,该文件执行@echo $(DUMPVAR_VALUE)输出$1变量值。
Examples:
1、get_abs_build_var ANDROID_GCC_PREBUILTS
- #####################
- # file:envsetup.mk #
- #####################
- 34 # ---------------------------------------------------------------
- 35 # Set up configuration for host machine. We don't do cross-
- 36 # compiles except for arm/mips, so the HOST is whatever we are
- 37 # running on
- 38
- 39 UNAME := $(shell uname -sm)
- 40
- 41 # HOST_OS
- 42 ifneq (,$(findstring Linux,$(UNAME)))
- 43 <u><strong>HOST_OS</strong></u> := linux
- 44 endif
- 45 ifneq (,$(findstring Darwin,$(UNAME)))
- 46 HOST_OS := darwin
- 47 endif
- 48 ifneq (,$(findstring Macintosh,$(UNAME)))
- 49 HOST_OS := darwin
- 50 endif
- 51 ifneq (,$(findstring CYGWIN,$(UNAME)))
- 52 HOST_OS := windows
- 53 endif
- 108 # We don't want to move all the prebuilt host tools to a $(HOST_OS)-x86_64 dir.
- 109 HOST_PREBUILT_ARCH := x86
- 110 # This is the standard way to name a directory containing prebuilt host
- 111 # objects. E.g., prebuilt/$(HOST_PREBUILT_TAG)/cc
- 112 ifeq ($(HOST_OS),windows)
- 113 HOST_PREBUILT_TAG := windows
- 114 else
- 115 HOST_PREBUILT_TAG := $(HOST_OS)-$(HOST_PREBUILT_ARCH)
- 116 endif
- ##############
- # dumpvar.mk #
- ##############
- ./dumpvar.mk:ANDROID_GCC_PREBUILTS := prebuilts/gcc/$(HOST_PREBUILT_TAG)
2、get_abs_build_var PRODUCT_OUT
- #####################
- # file:envsetup.mk #
- #####################
- 192 # the target build type defaults to release
- 193 ifneq ($(TARGET_BUILD_TYPE),debug)
- 194 TARGET_BUILD_TYPE := release
- 195 endif
- 196
- 197 # ---------------------------------------------------------------
- 198 # figure out the output directories
- 199
- 200 ifeq (,$(strip $(OUT_DIR)))
- 201 ifeq (,$(strip $(OUT_DIR_COMMON_BASE)))
- 202 OUT_DIR := $(TOPDIR)out
- 203 else
- 204 OUT_DIR := $(OUT_DIR_COMMON_BASE)/$(notdir $(PWD))
- 205 endif
- 206 endif207
- 208 DEBUG_OUT_DIR := $(OUT_DIR)/debug
- 209
- 210 # Move the host or target under the debug/ directory
- 211 # if necessary.
- 212 TARGET_OUT_ROOT_release := $(OUT_DIR)/target
- 213 TARGET_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/target
- 214 TARGET_OUT_ROOT := $(TARGET_OUT_ROOT_$(TARGET_BUILD_TYPE))
- 227 TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product
- 232 PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE)
- #####################
- # product_config.mk #
- #####################
- ./product_config.mk:TARGET_DEVICE := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEVICE)
- # 该变量的分析将独立写一篇文章介绍。
3、get_abs_build_var HOST_OUT
- #####################
- # file: envsetup.mk #
- #####################
- 1 # Variables we check:
- 2 # HOST_BUILD_TYPE = { release debug }
- 3 # TARGET_BUILD_TYPE = { release debug }
- 4 # and we output a bunch of variables, see the case statement at
- 5 # the bottom for the full list
- 6 # OUT_DIR is also set to "out" if it's not already set.
- 7 # this allows you to set it to somewhere else if you like
- 97 # the host build defaults to release, and it must be release or debug
- 98 ifeq ($(HOST_BUILD_TYPE),)
- 99 HOST_BUILD_TYPE := release
- 100 endif
- 101
- 102 ifneq ($(HOST_BUILD_TYPE),release)
- 103 ifneq ($(HOST_BUILD_TYPE),debug)
- 104 $(error HOST_BUILD_TYPE must be either release or debug, not '$(HOST_BUILD_TYPE)')
- 105 endif
- 106 endif
- 216 HOST_OUT_ROOT_release := $(OUT_DIR)/host # OUT_DIR 见2的分析。
- 217 HOST_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/host # DEBUG_OUT_DIR 见2的分析。
- 220 # We want to avoid two host bin directories in multilib build.
- 221 HOST_OUT_release := $(HOST_OUT_ROOT_release)/$(HOST_OS)-$(HOST_PREBUILT_ARCH)
- # HOST_OS 见 1 的分析。
- 222 HOST_OUT_debug := $(HOST_OUT_ROOT_debug)/$(HOST_OS)-$(HOST_PREBUILT_ARCH)
- # HOST_PREBUILT_ARCH 见 1 的分析。
- 223 HOST_OUT := $(HOST_OUT_$(HOST_BUILD_TYPE))
4、get_build_var TARGET_DEVICE
- #####################
- # product_config.mk #
- #####################
- ./product_config.mk:TARGET_DEVICE := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEVICE)
- # 该变量的分析将独立写一篇文章介绍。
5、get_build_var TARGET_GCC_VERSION
- TARGET_GCC_VERSION是在combo/TARGET_linux-$(TARGET_ARCH).mk文件中赋的值。
- 而TARGET_linux-$(TARGET_ARCH).mk文件是有config.mk -> combo/select.mk文件选择性包含进来的。
6、get_build_var 2ND_TARGET_GCC_VERSION
- ./core/envsetup.mk:254:HOST_2ND_ARCH_VAR_PREFIX := 2ND_
- ./core/envsetup.mk:297:TARGET_2ND_ARCH_VAR_PREFIX := $(HOST_2ND_ARCH_VAR_PREFIX)
- ./core/config.mk:156:include $(BUILD_SYSTEM)/envsetup.mk
- ./core/config.mk:230:combo_2nd_arch_prefix :=
- ./core/config.mk:236:combo_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX)
- ./core/config.mk:244:combo_2nd_arch_prefix :=
- ./core/config.mk:250:combo_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
- $(combo_2nd_arch_prefix)TARGET_GCC_VERSION的赋值是在combo/TARGET_linux-$(TARGET_ARCH).mk 文件中赋的值。
7、get_build_var TARGET_ARCH
- TARGET_ARCH是在BoardConfig.mk文件中赋的值。
- BoardConfig.mk文件是由config.mk -> envsetup.mk中的$(board_config_mk)变量包含进来的。
8、get_build_var ANDROID_BUILD_PATHS
- ./core/envsetup.mk:238:HOST_OUT_EXECUTABLES := $(HOST_OUT)/bin
- # HOST_OUT 见 3 的分析。
- ##############
- # dumpvar.mk #
- ##############
- ifneq ($(filter /%,$(HOST_OUT_EXECUTABLES)),)
- ABP:=$(HOST_OUT_EXECUTABLES)
- else
- ABP:=$(PWD)/$(HOST_OUT_EXECUTABLES)
- endif
- ANDROID_BUILD_PATHS := $(ABP)
9、get_build_var report_config
- 在dumpvar.mk中,目标是report_config的代码流程如下:
- ifneq ($(dumpvar_goals),report_config)
- PRINT_BUILD_CONFIG:=
- endif
- endif # CALLED_FROM_SETUP
- ifneq ($(PRINT_BUILD_CONFIG),)
- HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
- $(info ============================================)
- $(info PLATFORM_VERSION_CODENAME=$(PLATFORM_VERSION_CODENAME))
- # ./core/version_defaults.mk:62: PLATFORM_VERSION_CODENAME := REL
- $(info PLATFORM_VERSION=$(PLATFORM_VERSION))
- # ./core/version_defaults.mk:44: PLATFORM_VERSION := 5.1
- $(info TARGET_PRODUCT=$(TARGET_PRODUCT))
- # 是lunch时选择的<product_name>
- # ./envsetup.sh: export TARGET_PRODUCT=$product
- $(info TARGET_BUILD_VARIANT=$(TARGET_BUILD_VARIANT))
- # 是lunch时选择的<product_variant>
- # ./envsetup.sh: export TARGET_BUILD_VARIANT=$variant
- $(info TARGET_BUILD_TYPE=$(TARGET_BUILD_TYPE))
- # 是lunch时默认指定的,release
- # ./envsetup.sh: export TARGET_BUILD_TYPE=release
- $(info TARGET_BUILD_APPS=$(TARGET_BUILD_APPS))
- # 是lunch时默认指定的,空值
- # ./envsetup.sh: export TARGET_BUILD_APPS=
- $(info TARGET_ARCH=$(TARGET_ARCH)) # TARGET_ARCH 见 7 的分析。
- $(info TARGET_ARCH_VARIANT=$(TARGET_ARCH_VARIANT))
- # 是在$(board_config_mk)即 BoardConfig.mk文件中赋的值。
- $(info TARGET_CPU_VARIANT=$(TARGET_CPU_VARIANT))
- # 是在$(board_config_mk)即 BoardConfig.mk文件中赋的值。
- $(info TARGET_2ND_ARCH=$(TARGET_2ND_ARCH))
- # 是在$(board_config_mk)即 BoardConfig.mk文件中赋的值。
- $(info TARGET_2ND_ARCH_VARIANT=$(TARGET_2ND_ARCH_VARIANT))
- # 是在$(board_config_mk)即 BoardConfig.mk文件中赋的值。
- $(info TARGET_2ND_CPU_VARIANT=$(TARGET_2ND_CPU_VARIANT))
- # 是在$(board_config_mk)即 BoardConfig.mk文件中赋的值。
- $(info HOST_ARCH=$(HOST_ARCH))
- # ./core/envsetup.mk:79: HOST_ARCH := x86_64
- $(info HOST_OS=$(HOST_OS)) # HOST_OS 见 1 的分析。
- $(info HOST_OS_EXTRA=$(HOST_OS_EXTRA)) # ifneq 的第一行。
- $(info HOST_BUILD_TYPE=$(HOST_BUILD_TYPE)) # HOST_BUILD_TYPE 见 3 的分析。
- $(info BUILD_ID=$(BUILD_ID))
- # ./core/build_id.mk:21:export BUILD_ID=LMY47D
- $(info OUT_DIR=$(OUT_DIR)) # OUT_DIR 见 2 的分析。
- $(info ============================================)
- endif
Building System之 get_abs_build_var() && get_build_var()的更多相关文章
- 【转】Android Building System 总结 - 一醉千年 - CSDN博客
原文网址:http://www.360doc.com/content/15/0314/23/1709014_455175716.shtml Android Building System 总结 收藏 ...
- building system busy, pls wait !!
编译ca是可能会报这个错误,是189服务器上的/home/pub-work/.android_build_lock这个文件的问题,删除即可.
- 【Java心得总结四】Java泛型下——万恶的擦除
一.万恶的擦除 我在自己总结的[Java心得总结三]Java泛型上——初识泛型这篇博文中提到了Java中对泛型擦除的问题,考虑下面代码: import java.util.*; public clas ...
- Thinking in Java from Chapter 15
From Thinking in Java 4th Edition. 泛型实现了:参数化类型的概念,使代码可以应用于多种类型.“泛型”这个术语的意思是:“适用于许多许多的类型”. 如果你了解其他语言( ...
- Android开发的技术层次
任何一种移动开发生态系统其技术人员都是呈现金字塔式分布的.我借此也说说Developer和Programmer的区别: Programmer是真正意义上的程序员,写程序的.灵魂级 Developer是 ...
- JAVA虚拟机学习笔记(一)Windows10下编译OpenJDK8
转载请注明源地址:http://www.cnblogs.com/lighten/p/5906359.html 1. 编译环境的准备 1.1 JDK源码下载 OpenJDK是JAVA发展史中的一个开源项 ...
- sublime搭建Java编译平台及编码问题
Sublime自带Java编译功能,当时只能编译不能运行,我们做一下小小的修改就可以让sublime一步完成编译运行的功能,实现sublime搭建Java编译平台. 使用Ctrl + B 编译时,所编 ...
- AsciiDoc
AsciiDoc Text based document generation AsciiDoc Home Page Table of Contents Introduction Overview a ...
- 关于sublime text
Sublime text2 C/C++ 编译环境设置 (2014-04-10 20:51:16) 转载▼ 标签: sublime c语言 程序设计 gcc cpp 分类: 记录与分享 sublime ...
随机推荐
- ●洛谷P1291 [SHOI2002]百事世界杯之旅
题链: https://www.luogu.org/recordnew/show/5861351题解: dp,期望 定义dp[i]表示还剩下i个盖子没收集时,期望还需要多少次才能手机完. 初始值:dp ...
- ●HDU 5608 function
题链: http://acm.hdu.edu.cn/showproblem.php?pid=5608 题解: 莫比乌斯反演,杜教筛 已知$$N^2-3N+2=\sum_{d|N} f(d)$$ 多次询 ...
- Educational Codeforces Round 17F Tree nesting
来自FallDream的博客,未经允许,请勿转载, 谢谢. 给你两棵树,一棵比较大(n<=1000),一棵比较小(m<=12) 问第一棵树中有多少个连通子树和第二棵同构. 答案取膜1e9+ ...
- [BZOJ]1076 奖励关(SCOI2008)
终于又一次迎来了一道期望DP题,按照约定,小C把它贴了出来. Description 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃 ...
- 用js来实现那些数据结构11(字典)
我们这篇文章来说说Map这种数据结构如何用js来实现,其实它和集合(Set)极为类似,只不过Map是[键,值]的形式存储元素,通过键来查询值,Map用于保存具有映射关系的数据,Map里保存着两组数据: ...
- ml-agent:Win10下环境安装
这是我看到的最全面最详细的ml-agent讲解.(只用于学习与知识分享,如有侵权,联系删除.谢谢!) 来自CodeGize的个人博客 .源链接:https://www.cnblogs.com/Code ...
- 如何导入python中的模块
作为一名新手Python程序员,你首先需要学习的内容之一就是如何导入模块或包.但是我注意到,那些许多年来不时使用Python的人并不是都知道Python的导入机制其实非常灵活.在本文中,我们将探讨以下 ...
- 一个使用 Python 的人工智能聊天机器人框架
一个Python 的 AI Chatbot框架 建立一个聊天室可以听起来很棒,但它是完全可行的. IKY是一个内置于Python中的AI动力对话对话界面. 使用IKY,很容易创建自然语言会话场景,无需 ...
- Image中的alt
如果图片不存在,默认会显示一个缺失图片,这是不友好的 所以可以加上alt属性. 当图片存在的时候,alt是不会显示的 当图片不存在的时候,alt就会出现 <img src="http: ...
- sqlserver 按照特定值排序查询结果
select * from t_ss_student order by case when xm like '林%' then 1 else 2 end asc; 姓林的会排在前面