From 7b226865c1e2e7d99f71f3fc5d31ac43ce2fb678 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 13 Sep 2018 15:11:42 -0700 Subject: [PATCH] Make package functions take an argument In preparation for rearranging the way jars and apks are built. Relands Ib9f0da132196942062c58fd5b12e84588106724e with a fix to correctly include classes.dex in hostdex jars. Test: m checkbuild Change-Id: I397544456b8ce5827716fcd1828de707b719c2bb --- core/definitions.mk | 37 ++++++++++++-------------------- core/dpi_specific_apk.mk | 8 +++---- core/host_dalvik_java_library.mk | 2 +- core/java_library.mk | 2 +- core/package_internal.mk | 14 ++++++------ 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/core/definitions.mk b/core/definitions.mk index 6c163df09..fea1a0af5 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2305,7 +2305,7 @@ endef # The MacOS jar tool doesn't like creating empty jar files, # so we need to give it something. # $(1) package to create -define create-empty-package-at +define create-empty-package @mkdir -p $(dir $(1)) $(hide) touch $(dir $(1))zipdummy $(hide) $(JAR) cf $(1) -C $(dir $(1)) zipdummy @@ -2313,13 +2313,6 @@ $(hide) zip -qd $(1) zipdummy $(hide) rm $(dir $(1))zipdummy endef -# Create a mostly-empty .jar file that we'll add to later. -# The MacOS jar tool doesn't like creating empty jar files, -# so we need to give it something. -define create-empty-package -$(call create-empty-package-at,$@) -endef - # Copy an arhchive file and delete any class files and empty folders inside. # $(1): the source archive file. # $(2): the destination archive file. @@ -2339,6 +2332,7 @@ endef #Note that the version numbers are given to aapt as simple default #values; applications can override these by explicitly stating #them in their manifest. +# $(1) the package file define add-assets-to-package $(hide) $(AAPT_ASAN_OPTIONS) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ $(addprefix -c , $(PRIVATE_PRODUCT_AAPT_CONFIG)) \ @@ -2355,16 +2349,17 @@ $(hide) $(AAPT_ASAN_OPTIONS) $(AAPT) package -u $(PRIVATE_AAPT_FLAGS) \ $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR)) \ --skip-symbols-without-default-localization \ - -F $@ + -F $(1) # So that we re-run aapt when the list of input files change $(hide) echo $(PRIVATE_RESOURCE_LIST) >/dev/null endef # We need the extra blank line, so that the command will be on a separate line. -# $(1): the ABI name -# $(2): the list of shared libraies +# $(1): the package +# $(2): the ABI name +# $(3): the list of shared libraies define _add-jni-shared-libs-to-package-per-abi -$(hide) cp $(2) $(dir $@)lib/$(1) +$(hide) cp $(3) $(dir $(1))lib/$(2) endef @@ -2378,23 +2373,19 @@ JNI_COMPRESS_FLAGS := -0 ZIPALIGN_PAGE_ALIGN_FLAGS := -p endif +# $(1): the package file define add-jni-shared-libs-to-package -$(hide) rm -rf $(dir $@)lib -$(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)) +$(hide) rm -rf $(dir $(1))lib +$(hide) mkdir -p $(addprefix $(dir $(1))lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI)) $(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\ - $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\ + $(call _add-jni-shared-libs-to-package-per-abi,$(1),$(abi),\ $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES))))) -$(hide) (cd $(dir $@) && zip -qrX $(JNI_COMPRESS_FLAGS) $(notdir $@) lib) -$(hide) rm -rf $(dir $@)lib -endef - -#TODO: update the manifest to point to the dex file -define add-dex-to-package -$(call add-dex-to-package-arg,$@) +$(hide) (cd $(dir $(1)) && zip -qrX $(JNI_COMPRESS_FLAGS) $(notdir $(1)) lib) +$(hide) rm -rf $(dir $(1))lib endef # $(1): the package file. -define add-dex-to-package-arg +define add-dex-to-package $(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $(1) endef diff --git a/core/dpi_specific_apk.mk b/core/dpi_specific_apk.mk index f32daf500..20bbbe23d 100644 --- a/core/dpi_specific_apk.mk +++ b/core/dpi_specific_apk.mk @@ -51,16 +51,16 @@ $(built_dpi_apk) : $(all_res_assets) $(jni_shared_libraries) $(full_android_mani @echo "target Package: $(PRIVATE_MODULE) ($@)" $(if $(PRIVATE_SOURCE_ARCHIVE),\ $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\ - $(create-empty-package)) - $(add-assets-to-package) + $(call create-empty-package,$@)) + $(call add-assets-to-package,$@) ifneq ($(jni_shared_libraries),) - $(add-jni-shared-libs-to-package) + $(call add-jni-shared-libs-to-package,$@) endif ifeq ($(full_classes_jar),) # We don't build jar, need to add the Java resources here. $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@)) else - $(add-dex-to-package) + $(call add-dex-to-package,$@) endif $(sign-package) diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk index 779cef950..09ce9fe42 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -174,7 +174,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) $(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources) @echo "Host Jar: $(PRIVATE_MODULE) ($@)" $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@) - $(add-dex-to-package) + $(call add-dex-to-package,$@) endif # !LOCAL_IS_STATIC_JAVA_LIBRARY diff --git a/core/java_library.mk b/core/java_library.mk index 0a70a3817..b9abbe4e1 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -68,7 +68,7 @@ $(common_javalib.jar): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar $(common_javalib.jar) : $(built_dex) $(java_resource_sources) | $(ZIPTIME) $(ZIPALIGN) @echo "target Jar: $(PRIVATE_MODULE) ($@)" $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@.tmp) - $(call add-dex-to-package-arg,$@.tmp) + $(call add-dex-to-package,$@.tmp) $(hide) $(ZIPTIME) $@.tmp $(call commit-change-for-toc,$@) ifeq (true, $(LOCAL_UNCOMPRESS_DEX)) diff --git a/core/package_internal.mk b/core/package_internal.mk index 7f74cc903..ef2a5a514 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -420,8 +420,8 @@ else # LOCAL_USE_AAPT2 $(resource_export_package): PRIVATE_RESOURCE_LIST := $(all_res_assets) $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(rs_generated_res_zip) $(AAPT) @echo "target Export Resources: $(PRIVATE_MODULE) ($@)" - $(create-empty-package) - $(add-assets-to-package) + $(call create-empty-package,$@) + $(call add-assets-to-package,$@) endif endif # LOCAL_USE_AAPT2 @@ -628,17 +628,17 @@ ifeq ($(LOCAL_USE_AAPT2),true) else # ! LOCAL_USE_AAPT2 $(if $(PRIVATE_SOURCE_ARCHIVE),\ $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\ - $(create-empty-package)) - $(add-assets-to-package) + $(call create-empty-package,$@)) + $(call add-assets-to-package,$@) endif # LOCAL_USE_AAPT2 ifneq ($(jni_shared_libraries),) - $(add-jni-shared-libs-to-package) + $(call add-jni-shared-libs-to-package,$@) endif ifeq ($(full_classes_jar),) # We don't build jar, need to add the Java resources here. $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@)) else # full_classes_jar - $(add-dex-to-package) + $(call add-dex-to-package,$@) ifeq ($(LOCAL_USE_AAPT2),true) $(call add-jar-resources-to-package,$@,$(PRIVATE_FULL_CLASSES_JAR),$(PRIVATE_RESOURCE_INTERMEDIATES_DIR)) endif @@ -687,7 +687,7 @@ $(built_odex): PRIVATE_DEX_FILE := $(built_dex) # Use pattern rule - we may have multiple built odex files. $(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex) $(hide) mkdir -p $(dir $@) && rm -f $@ - $(add-dex-to-package) + $(call add-dex-to-package,$@) ifeq (true, $(LOCAL_UNCOMPRESS_DEX)) $(uncompress-dexs) $(align-package)