Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed9f8663 authored by Cole Faust's avatar Cole Faust
Browse files

Build apkcerts.txt with soong

Make will still handle building apkcerts.txt for make modules, but
soong will build it for soong modules and then make will combine
the make and soong apkcerts files.

This is for soong-only builds. In a followup change I'll make it so
that only soong dists the apkcerts.txt file on unbundled builds.

Bug: 413145177
Test: Presubmits, make will doublecheck that the soong-built apkcerts.txt is correct
Change-Id: I00c86f33c2ef74eeabb7a1dcb5b50b761aa2d4a7
parent a8aabc0e
Loading
Loading
Loading
Loading
+29 −16
Original line number Diff line number Diff line
@@ -769,6 +769,21 @@ $(hide) cat $1 >> $2

endef

define _apkcerts_build_for_packages
$(1): $(sort $(foreach p,$(2),$(PACKAGES.$(p).APKCERTS_FILE)))
	rm -f $$@
	$$(foreach p,$(sort $(2)),\
    $$(if $$(filter UNUSED-%,$$(PACKAGES.$$(p).STEM)),,\
      $$(if $$(PACKAGES.$$(p).APKCERTS_FILE),\
        $$(call _apkcerts_merge,$$(PACKAGES.$$(p).APKCERTS_FILE), $$@),\
        $$(if $$(PACKAGES.$$(p).EXTERNAL_KEY),\
          $$(call _apkcerts_write_line,$$(PACKAGES.$$(p).STEM),EXTERNAL,,$$(PACKAGES.$$(p).COMPRESSED),$$(PACKAGES.$$(p).PARTITION),$$@),\
          $$(call _apkcerts_write_line,$$(PACKAGES.$$(p).STEM),$$(PACKAGES.$$(p).CERTIFICATE),$$(PACKAGES.$$(p).PRIVATE_KEY),$$(PACKAGES.$$(p).COMPRESSED),$$(PACKAGES.$$(p).PARTITION),$$@)))))
	touch $$@
	sort -u -o $$@ $$@

endef

name := $(TARGET_PRODUCT)
ifeq ($(TARGET_BUILD_TYPE),debug)
  name := $(name)_debug
@@ -777,26 +792,24 @@ name := $(name)-apkcerts
intermediates := \
	$(call intermediates-dir-for,PACKAGING,apkcerts)
APKCERTS_FILE := $(intermediates)/$(name).txt
ifeq ($(RELEASE_APKCERTS_INSTALL_ONLY), true)
  all_apkcerts_packages := $(filter $(call product-installed-modules,$(INTERNAL_PRODUCT)),$(PACKAGES))
else
  all_apkcerts_packages := $(PACKAGES)
endif
all_apkcerts_files := $(sort $(foreach p,$(all_apkcerts_packages),$(PACKAGES.$(p).APKCERTS_FILE)))

$(APKCERTS_FILE): $(all_apkcerts_files)
# We don't need to really build all the modules.
# TODO: rebuild APKCERTS_FILE if any app change its cert.
$(APKCERTS_FILE):
make_apkcerts_packages := $(foreach p,$(PACKAGES),$(if $(ALL_MODULES.$(p).IS_SOONG_MODULE),,$(p)))
make_apkcerts_file := $(intermediates)/$(name)-make.txt
$(eval $(call _apkcerts_build_for_packages,$(make_apkcerts_file),$(make_apkcerts_packages)))

soong_apkcerts_packages := $(foreach p,$(PACKAGES),$(if $(ALL_MODULES.$(p).IS_SOONG_MODULE),$(p)))
soong_doublecheck_apkcerts_file := $(intermediates)/$(name)-soong-doublecheck.txt
$(eval $(call _apkcerts_build_for_packages,$(soong_doublecheck_apkcerts_file),$(soong_apkcerts_packages)))

soong_apkcerts_doublecheck_stamp := $(intermediates)/$(name)-soong-doublecheck-stamp.txt
$(soong_apkcerts_doublecheck_stamp): $(soong_doublecheck_apkcerts_file) $(SOONG_APKCERTS_FILE)
	rm -f $@ && diff -q $^ && touch $@

$(APKCERTS_FILE): $(make_apkcerts_file) $(SOONG_APKCERTS_FILE) $(soong_apkcerts_doublecheck_stamp)
	@echo APK certs list: $@
	@mkdir -p $(dir $@)
	@rm -f $@
	$(foreach p,$(sort $(all_apkcerts_packages)),\
	  $(if $(PACKAGES.$(p).APKCERTS_FILE),\
	    $(call _apkcerts_merge,$(PACKAGES.$(p).APKCERTS_FILE), $@),\
	    $(if $(PACKAGES.$(p).EXTERNAL_KEY),\
	      $(call _apkcerts_write_line,$(PACKAGES.$(p).STEM),EXTERNAL,,$(PACKAGES.$(p).COMPRESSED),$(PACKAGES.$(p).PARTITION),$@),\
	      $(call _apkcerts_write_line,$(PACKAGES.$(p).STEM),$(PACKAGES.$(p).CERTIFICATE),$(PACKAGES.$(p).PRIVATE_KEY),$(PACKAGES.$(p).COMPRESSED),$(PACKAGES.$(p).PARTITION),$@))))
	cat $(make_apkcerts_file) $(SOONG_APKCERTS_FILE) > $@
	$(if $(filter true,$(PRODUCT_FSVERITY_GENERATE_METADATA)),\
	  $(call _apkcerts_write_line,BuildManifest,$(FSVERITY_APK_KEY_PATH).x509.pem,$(FSVERITY_APK_KEY_PATH).pk8,,system,$@) \
	  $(if $(filter true,$(BUILDING_SYSTEM_EXT_IMAGE)),\