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()相关推荐
- Mastering Android NDK Build System - Part 1: Techniques with ndk-build
This article is not a "Hello world!"-type tutorial for NDK. Although I will still provide ...
- Google和Facebook为什么不用Docker?
点击关注公众号,Java干货及时送达 写作本文的起因是我想让修改后的分布式 PyTorch 程序能更快的在 Facebook 的集群上启动.探索过程很有趣,也展示了工业机器学习需要的知识体系. 200 ...
- 你猜,为什么Google和Facebook不用Docker?
前言 本文涉及的所有技术细节都在开源软件和论文中. 写本文的起因是我想让分布式 PyTorch 程序更快的在 Facebook 的集群上启动.探索过程很有趣.也展示了工业机器学习需要的知识体系. 20 ...
- Android 编译系统分析(二)
把Android所有的Make文件分为4种: 1.For config 这类文件主要来配置product,board,以及根据你的Host和Target选择相应的工具以及设定相应的通用编译选项: bu ...
- 网络技术术语英汉对照
1. ADSL (Asymmetric Digital Subscriber Line) 非对称数字环路 2. ANSI (American National Standard Institute) ...
- 从达标到卓越 —— API 设计之道
摘要: 新技术层出不穷,长江后浪推前浪.在浪潮褪去后,能留下来的,是一些经典的设计思想. 在前端界,以前有远近闻名的 jQuery,近来有声名鹊起的 Vue.js.这两者叫好又叫座的原因固然有很多,但 ...
- ensp查看历史配置命令_网络工程师 | 手把手教你用华为ensp模拟器玩vxlan实验(静态方式)...
一.背景 随着云计算.虚拟化技术的发展,业务有时需要再不同地方同网段进行通信,即大二层网络.比如虚机迁移,从A数据中心迁移到异地数据中心. 首先,我们都知道,路由器是用来隔离广播域的,同网段通信都在一 ...
- Think in Java第四版 读书笔记9第15章 泛型
Think in Java第四版 读书笔记9第15章 泛型 泛型:适用于很多很多的类型 与其他语言相比 Java的泛型可能有许多局限 但是它还是有很多优点的. 本章介绍java泛型的局限和优势以及ja ...
- Docker学习总结(55)——Google和Facebook为什么不用Docker?
2007 年我刚毕业后在 Google 工作过三年.当时觉得分布式操作系统 Borg 真好用. 从 2010 年离开 Google 之后就一直盼着它开源,直到 Kubernetes 的出现. Kube ...
最新文章
- Android adb常用命令
- mysql 命令大全
- 利用ConcurrentHashMap来实现一个ConcurrentHashSet
- nrf51822-主从通信分析2
- 数据结构与算法(一):排序算法之 - 快速排序(详细步骤图解,附代码)
- IOS14.3开发之使用纯代码创建UIButton以及弹框的使用
- 征名公布|Qtum量子链企业版—Unita 中文名征集圆满落幕
- 《MySQL——索引笔记》
- react 使用 mobx_如何使用React和MobX状态树构建基于状态的路由器
- diskgenius 数据迁移_U盘格式化后数据恢复免费方法教程
- 管理功能(下):EqualLogic PS5000 强大丰富
- simulink模块的输入端口与参数的关系
- 一串数字中有两个只出现一次的数字其余都是成对相同,求这两个数
- 简单PHP留言板之二 —— PHP的数据库连接文件
- Source Map的概念
- TensorFlow 核心流程剖析 -- 2 神经网络模型的构建、分割和优化
- 【数据挖掘】搜狐公司数据挖掘工程师笔试题
- linux视频mp4无法播放器,mplayer播放器无法正常输出视频
- (Anroid Studio)用简单代码实现BMI计算器并且将应用安装到手机上
- python 存储字典_python 字典存储
热门文章
- synchronize与lock的区别
- @ControllerAdvice这个注解主要作用是什么
- 012_SpringBoot视图层技术thymeleaf-条件判断
- 010_JMS消息选择器
- 007_JMS中的持久订阅
- 016_continue和break语句
- 安卓连接linux软件,利用 Telnet 无线控制安卓手机 无需 Root
- python一行输入多个值用空格隔开_2020-09-22-Python-函数嵌套、filter()函数、一行输入多个整数(空格分隔)、多维列表的输入...
- python项目实践_Python 项目实践三(Web应用程序)第二篇
- 福田车载无线充电器方案开发设计_过年自驾回家,带上优胜仕车载无线充电器,一放即充导航无忧...