AOSP查看当前要打进系统里的都有哪些包(AOSP checks which packages are currently entering the system)

发现问题:

修改系统时常常需要预置APK,这就要修改这个变量,那么如何查看这个数组的值呢?我们可能直接在mk文件中去打印它,后来发现打印它只会显示继承关系(即继承自了哪些mk文件),并不会打印当前已将添加了哪些包

PRODUCT_PACKAGES
$(warning $(PRODUCT_PACKAGES))

所以上面这种方式行不通。

解决方案:

发现中定义了一个make的构建目标,能够打印构建当前目标所定义的变量:

build/core/product_config.mk
dump-products
ifneq ($(filter dump-products, $(MAKECMDGOALS)),)
$(dump-products)
$(error done)
endif

这里调用了,我们在目录全局搜一下这个变量,它是在中定义的,

dump-products
build/core
build/core/product.mk
define dump-product
$(info ==== $(1) ====)\
$(foreach v,$(_product_var_list),\
$(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
$(info --------)
endef

define dump-products
$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
endef

它是一个函数,针对每一个,循环打印该的中定义的变量,而是一个数组,定义如下:

product
product
_product_var_list
_product_var_list
_product_var_list := \
    PRODUCT_NAME \
    PRODUCT_MODEL \
    PRODUCT_LOCALES \
    PRODUCT_AAPT_CONFIG \
    PRODUCT_AAPT_PREF_CONFIG \
    PRODUCT_AAPT_PREBUILT_DPI \
    PRODUCT_PACKAGES \
    PRODUCT_PACKAGES_DEBUG \
    PRODUCT_PACKAGES_ENG \
    PRODUCT_PACKAGES_TESTS \
    PRODUCT_DEVICE \
    PRODUCT_MANUFACTURER \
    PRODUCT_BRAND \
    PRODUCT_PROPERTY_OVERRIDES \
    PRODUCT_DEFAULT_PROPERTY_OVERRIDES \
    PRODUCT_CHARACTERISTICS \
    PRODUCT_COPY_FILES \
    PRODUCT_OTA_PUBLIC_KEYS \
    PRODUCT_EXTRA_RECOVERY_KEYS \
    PRODUCT_PACKAGE_OVERLAYS \
    DEVICE_PACKAGE_OVERLAYS \
    PRODUCT_SDK_ATREE_FILES \
    PRODUCT_SDK_ADDON_NAME \
    PRODUCT_SDK_ADDON_COPY_FILES \
    PRODUCT_SDK_ADDON_COPY_MODULES \

里面就有。
最终打印结果:

PRODUCT_PACKAGES
PRODUCTS.device/lge/bullhead/aosp_bullhead.mk.PRODUCT_PACKAGES := libfwdlockengine OpenWnn libWnnEngDic libWnnJpnDic libwnndict WAPPushManager Galaxy4 HoloSpiralWallpaper LiveWallpapers LiveWallpapersPicker MagicSmokeWallpapers NoiseField PhaseBeam PhotoTable Bluetooth BluetoothMidiService Camera2 Gallery2 Music MusicFX  Launcher3 TestApp ....

另外,从打印结果可以看出构建目标的变量最终都被合并成:的形式

PRODUCTS.构建目标.变量名
————————

Problems found:

When modifying the system, you often need to preset APK, which requires modifying this variable. How to view the value of this array? We may print it directly in the MK file. Later, we found that printing it will only display the inheritance relationship (that is, which MK files we inherited from), and will not print which packages have been added at present

PRODUCT_PACKAGES
$(warning $(PRODUCT_PACKAGES))

So the above method doesn’t work.

Solution:

The discovery defines the build target of a make, which can print the variables defined by the current build target:

build/core/product_config.mk
dump-products
ifneq ($(filter dump-products, $(MAKECMDGOALS)),)
$(dump-products)
$(error done)
endif

This is called here. Let’s search the global directory for this variable, which is defined in,

dump-products
build/core
build/core/product.mk
define dump-product
$(info ==== $(1) ====)\
$(foreach v,$(_product_var_list),\
$(info PRODUCTS.$(1).$(v) := $(PRODUCTS.$(1).$(v))))\
$(info --------)
endef

define dump-products
$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
endef

For each variable in the array, it is defined as follows:

product
product
_product_var_list
_product_var_list
_product_var_list := \
    PRODUCT_NAME \
    PRODUCT_MODEL \
    PRODUCT_LOCALES \
    PRODUCT_AAPT_CONFIG \
    PRODUCT_AAPT_PREF_CONFIG \
    PRODUCT_AAPT_PREBUILT_DPI \
    PRODUCT_PACKAGES \
    PRODUCT_PACKAGES_DEBUG \
    PRODUCT_PACKAGES_ENG \
    PRODUCT_PACKAGES_TESTS \
    PRODUCT_DEVICE \
    PRODUCT_MANUFACTURER \
    PRODUCT_BRAND \
    PRODUCT_PROPERTY_OVERRIDES \
    PRODUCT_DEFAULT_PROPERTY_OVERRIDES \
    PRODUCT_CHARACTERISTICS \
    PRODUCT_COPY_FILES \
    PRODUCT_OTA_PUBLIC_KEYS \
    PRODUCT_EXTRA_RECOVERY_KEYS \
    PRODUCT_PACKAGE_OVERLAYS \
    DEVICE_PACKAGE_OVERLAYS \
    PRODUCT_SDK_ATREE_FILES \
    PRODUCT_SDK_ADDON_NAME \
    PRODUCT_SDK_ADDON_COPY_FILES \
    PRODUCT_SDK_ADDON_COPY_MODULES \

It’s in there.
Final print result:

PRODUCT_PACKAGES
PRODUCTS.device/lge/bullhead/aosp_bullhead.mk.PRODUCT_PACKAGES := libfwdlockengine OpenWnn libWnnEngDic libWnnJpnDic libwnndict WAPPushManager Galaxy4 HoloSpiralWallpaper LiveWallpapers LiveWallpapersPicker MagicSmokeWallpapers NoiseField PhaseBeam PhotoTable Bluetooth BluetoothMidiService Camera2 Gallery2 Music MusicFX  Launcher3 TestApp ....

In addition, it can be seen from the print results that the variables of the construction target are finally combined into the form of:

PRODUCTS.构建目标.变量名