Add LOCAL_APKCERTS_FILE support.

This is used when Soong and Make don't know the full output file list,
and so use a tool to generate a per-module apkcerts.txt file instead.

Bug: 160119159
Bug: 162464887
Test: m apkcerts-list
Merged-In: I48183bc8cbf9dcc521f791812734205ed3f28f4c
Change-Id: I48183bc8cbf9dcc521f791812734205ed3f28f4c
This commit is contained in:
Jaewoong Jung 2020-06-29 19:37:53 -07:00
parent a6bcbd8a4a
commit 8f9d08a185
3 changed files with 21 additions and 14 deletions

View File

@ -677,6 +677,16 @@ $(hide) echo '' >> $5
endef endef
# -----------------------------------------------------------------
# Merge an individual apkcerts output into the final apkcerts.txt output.
# Use a macro to make it compatible with _apkcerts_write_line
# $1 apkcerts file to be merged
# $2 output file
define _apkcerts_merge
$(hide) cat $1 >> $2
endef
name := $(TARGET_PRODUCT) name := $(TARGET_PRODUCT)
ifeq ($(TARGET_BUILD_TYPE),debug) ifeq ($(TARGET_BUILD_TYPE),debug)
name := $(name)_debug name := $(name)_debug
@ -685,6 +695,8 @@ name := $(name)-apkcerts-$(FILE_NAME_TAG)
intermediates := \ intermediates := \
$(call intermediates-dir-for,PACKAGING,apkcerts) $(call intermediates-dir-for,PACKAGING,apkcerts)
APKCERTS_FILE := $(intermediates)/$(name).txt APKCERTS_FILE := $(intermediates)/$(name).txt
all_apkcerts_files := $(sort $(foreach p,$(PACKAGES),$(PACKAGES.$(p).APKCERTS_FILE)))
$(APKCERTS_FILE): $(all_apkcerts_files)
# We don't need to really build all the modules. # We don't need to really build all the modules.
# TODO: rebuild APKCERTS_FILE if any app change its cert. # TODO: rebuild APKCERTS_FILE if any app change its cert.
$(APKCERTS_FILE): $(APKCERTS_FILE):
@ -692,9 +704,11 @@ $(APKCERTS_FILE):
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@rm -f $@ @rm -f $@
$(foreach p,$(PACKAGES),\ $(foreach p,$(PACKAGES),\
$(if $(PACKAGES.$(p).EXTERNAL_KEY),\ $(if $(PACKAGES.$(p).APKCERTS_FILE),\
$(call _apkcerts_write_line,$(p),"EXTERNAL","",$(PACKAGES.$(p).COMPRESSED),$@),\ $(call _apkcerts_merge,$(PACKAGES.$(p).APKCERTS_FILE), $@),\
$(call _apkcerts_write_line,$(p),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$@))) $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
$(call _apkcerts_write_line,$(p),"EXTERNAL","",$(PACKAGES.$(p).COMPRESSED),$@),\
$(call _apkcerts_write_line,$(p),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$@))))
# In case value of PACKAGES is empty. # In case value of PACKAGES is empty.
$(hide) touch $@ $(hide) touch $@

View File

@ -22,6 +22,7 @@ LOCAL_APIDIFF_NEWAPI:=
LOCAL_APIDIFF_OLDAPI:= LOCAL_APIDIFF_OLDAPI:=
LOCAL_APK_LIBRARIES:= LOCAL_APK_LIBRARIES:=
LOCAL_APK_SET_MASTER_FILE:= LOCAL_APK_SET_MASTER_FILE:=
LOCAL_APKCERTS_FILE:=
LOCAL_ARM_MODE:= LOCAL_ARM_MODE:=
LOCAL_ASFLAGS:= LOCAL_ASFLAGS:=
LOCAL_ASSET_DIR:= LOCAL_ASSET_DIR:=

View File

@ -29,17 +29,9 @@ LOCAL_POST_INSTALL_CMD := unzip -qo -j -d $(dir $(LOCAL_INSTALLED_MODULE)) \
$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD) $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES)) PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
# android_app_set modules are always presigned
PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
PACKAGES := $(PACKAGES) $(LOCAL_MODULE) PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
# We can't know exactly what apk files would be outputted yet.
ifneq ($(LOCAL_MODULE_STEM),) # Let extract_apks generate apkcerts.txt and merge it later.
PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE_STEM) PACKAGES.$(LOCAL_MODULE).APKCERTS_FILE := $(LOCAL_APKCERTS_FILE)
else
PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE)
endif
# Set a actual_partition_tag (calculated in base_rules.mk) for the package.
PACKAGES.$(LOCAL_MODULE).PARTITION := $(actual_partition_tag)
SOONG_ALREADY_CONV += $(LOCAL_MODULE) SOONG_ALREADY_CONV += $(LOCAL_MODULE)