关于PRODUCT_PROPERTY_OVERRIDES属性的解析

已开通新的博客,后续文字都会发到新博客

http://www.0xfree.top


Android 编译系统解析系列文档

编译系统入口envsetup.sh解析

  • source build/envsetup.sh 做了什么?

解析lunch的执行过程以及make执行过程中include文件的顺序

  • Android编译系统分析之lunch分析
  • Android编译系统分析之make分析

关注一些make执行过程中的几个关键点

  • Android编译系统分析之几个关键点(一)
  • Android编译系统分析之几个关键点(二)
  • Android编译系统分析之几个关键点(三)

对一些独特的语法结构进行解析

  • PRODUCT_COPY_FILES语法解析
  • 关于PRODUCT_PROPERTY_OVERRIDES属性的解析

这个属性我们可以直接搜索源代码找到对应的位置

######
product_config.mk
######
# A list of property assignments, like "key = value", with zero or more
# whitespace characters on either side of the '='.
PRODUCT_PROPERTY_OVERRIDES := \
    $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PROPERTY_OVERRIDES))

......

# Add the product-defined properties to the build properties.
ADDITIONAL_BUILD_PROPERTIES := \
    $(ADDITIONAL_BUILD_PROPERTIES) \
    $(PRODUCT_PROPERTY_OVERRIDES)

从之前的继承系列的文章我们可以直到,PRODUCT_*系列的变量都有继承的功能,所以我们的PRODUCT_PROPERTY_OVERRIDES最终的取值就是$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PROPERTY_OVERRIDES),其中INTERNAL_PRODUCT对应的是当前编译机型配置目录相对于源码根目录的相对路径

接着,将这个属性赋予ADDITIONAL_BUILD_PROPERTIES这个变量

这块代码高亮部分显示的ADDITIONAL_BUILD_PROPERTIES宏的值已经在这个文件之前的部分处理过了,是这块代码

# build.prop
INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_BUILD_PROP_TARGET)
ADDITIONAL_BUILD_PROPERTIES := \
    $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))
ADDITIONAL_BUILD_PROPERTIES := $(call uniq-pairs-by-first-component, \
    $(ADDITIONAL_BUILD_PROPERTIES),=)

这里同样有两个函数处理这个变量
collapse-pairsuniq-pairs-by-first-component
我们来看这两个函数

define collapse-pairs
$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
$(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
    $(subst $(_cpSEP), $(_cpSEP) ,$(1))))
endef

###########################################################
## Given a list of pairs, if multiple pairs have the same
## first components, keep only the first pair.
##
## $(1): list of pairs
## $(2): the separator word, such as ":", "=", etc.
define uniq-pairs-by-first-component
$(eval _upbfc_fc_set :=)\
$(strip $(foreach w,$(1), $(eval _first := $(word 1,$(subst $(2),$(space),$(w))))\
    $(if $(filter $(_upbfc_fc_set),$(_first)),,$(w)\
        $(eval _upbfc_fc_set += $(_first)))))\
$(eval _upbfc_fc_set :=)\
$(eval _first:=)
endef

collapse-pairs函数是用来格式化赋值语句的,去掉=两边的空格,例如a = b或a =b,都会格式化为a=b

uniq-pairs-by-first-component函数是用来剔除这些赋值语句中多次重复对一个属性进行赋值的语句,规则为我们根据第二个参数来过滤第一个参数中重复的list
示例如下:

ro.mm.ffmpeg=1
ro.mm.ffmpeg=0

对于以上的两个属性,后一条属性会被过滤掉,只保留前一条属性,这个规则和PRODUCT_COPY_FILES是一样的

最终在Makefile中处理已经过滤完毕的属性,具体是在生成build.prop文件的时候,下边是主要的代码:

$(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file)
        @echo Target buildinfo: $@
        @mkdir -p $(dir $@)
        $(hide) echo > $@
ifneq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES),)
        $(hide) echo "#" >> $@; \
                echo "# PRODUCT_OEM_PROPERTIES" >> $@; \
                echo "#" >> $@;
        $(hide) $(foreach prop,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_OEM_PROPERTIES), \
                echo "import /oem/oem.prop $(prop)" >> $@;)
endif
        $(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
                        TARGET_BUILD_FLAVOR="$(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)" \
                        TARGET_DEVICE="$(TARGET_DEVICE)" \
                        PRODUCT_NAME="$(TARGET_PRODUCT)" \
                        PRODUCT_BRAND="$(PRODUCT_BRAND)" \
                        PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \
                        PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \
                        PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
                        PRODUCT_MODEL="$(PRODUCT_MODEL)" \
                        PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
                        PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
                        BUILD_ID="$(BUILD_ID)" \
                        BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
                        BUILD_DISPLAY_ID_MASK="$(BUILD_DISPLAY_ID_MASK)" \
                        BUILD_INSIDE_ID_MASK="$(BUILD_INSIDE_ID_MASK)" \
                        BUILD_NUMBER="$(BUILD_NUMBER)" \
                        PLATFORM_VERSION="$(PLATFORM_VERSION)" \
                        PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
                        PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
                        PLATFORM_VERSION_ALL_CODENAMES="$(PLATFORM_VERSION_ALL_CODENAMES)" \
                        BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
                        TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
                        BUILD_FINGERPRINT="$(BUILD_FINGERPRINT)" \
                        $(if $(OEM_THUMBPRINT_PROPERTIES),BUILD_THUMBPRINT="$(BUILD_THUMBPRINT)") \
                        TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
                        TARGET_CPU_ABI_LIST="$(TARGET_CPU_ABI_LIST)" \
                        TARGET_CPU_ABI_LIST_32_BIT="$(TARGET_CPU_ABI_LIST_32_BIT)" \
                        TARGET_CPU_ABI_LIST_64_BIT="$(TARGET_CPU_ABI_LIST_64_BIT)" \
                        TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
                        TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
                        TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \
                bash $(BUILDINFO_SH) >> $@
        $(hide) $(foreach file,$(system_prop_file), \
                if [ -f "$(file)" ]; then \
                        echo "#" >> $@; \
                        echo Target buildinfo from: "$(file)"; \
                        echo "# from $(file)" >> $@; \
                        echo "#" >> $@; \
                        cat $(file) >> $@; \
                fi;)
       >>==$(ADDITIONAL_BUILD_PROPERTIES), \
                $(hide) echo >> $@; \
                        echo "#" >> $@; \
                        echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
                        echo "#" >> $@; )
        $(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \
                echo "$(line)" >> $@;)
        $(hide) build/tools/post_process_props.py $@ $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_PROPERTY_BLACKLIST)==<<

build_desc :=

至此,关于PRODUCT_PROPERTY_OVERRIDES相关的内容就解析完毕

你可能感兴趣的:(android,android源码,Android编译系统分析)