1# App prebuilt coming from Soong.
2# Extra inputs:
3# LOCAL_APK_SET_INSTALL_FILE
4
5ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
6  $(call pretty-error,soong_apk_set.mk may only be used from Soong)
7endif
8
9LOCAL_BUILT_MODULE_STEM := $(LOCAL_APK_SET_INSTALL_FILE)
10LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_APK_SET_INSTALL_FILE)
11
12#######################################
13include $(BUILD_SYSTEM)/base_rules.mk
14#######################################
15
16## Extract master APK from APK set into given directory
17# $(1) APK set
18# $(2) APK entry to install (e.g., splits/base.apk
19
20define extract-install-file-from-apk-set
21$(LOCAL_BUILT_MODULE): $(1)
22	@echo "Extracting $$@"
23	unzip -pq $$< $(2) >$$@
24endef
25
26$(eval $(call extract-install-file-from-apk-set,$(LOCAL_PREBUILT_MODULE_FILE),$(LOCAL_APK_SET_INSTALL_FILE)))
27# unzip returns 11 it there was nothing to extract, which is expected,
28# $(LOCAL_APK_SET_INSTALL_FILE) has is already there.
29LOCAL_POST_INSTALL_CMD := unzip -qoDD -j -d $(dir $(LOCAL_INSTALLED_MODULE)) \
30	$(LOCAL_PREBUILT_MODULE_FILE) -x $(LOCAL_APK_SET_INSTALL_FILE) || [[ $$? -eq 11 ]]
31$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
32PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
33
34PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
35# We can't know exactly what apk files would be outputted yet.
36# Let extract_apks generate apkcerts.txt and merge it later.
37PACKAGES.$(LOCAL_MODULE).APKCERTS_FILE := $(LOCAL_APKCERTS_FILE)
38
39SOONG_ALREADY_CONV += $(LOCAL_MODULE)
40