From ea1629e788a0a32bc6eacfbdaa40c41e11903470 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 6 Oct 2017 13:55:48 -0700 Subject: [PATCH] Refactor removing classes.dex for dexpreopt Combining $(call dexpreopt-remove-classes.dex) into a $(call copy-one-file) rule is hacky and error prone. Make a helper dexpreopt-copy-jar function that takes LOCAL_DEX_PREOPT and copies the jar, removing the dex files if necessary. Test: only description message changes to out/build-${TARGET_PRODUCT}.ninja Change-Id: Id2fa2d18571ca01bc81302c912b8de25f3dde7a1 --- core/definitions.mk | 20 ++++++++++++++++++++ core/dex_preopt.mk | 15 +-------------- core/java_library.mk | 5 +---- core/prebuilt_internal.mk | 6 +----- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/core/definitions.mk b/core/definitions.mk index 532d46d80..27783ca09 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2714,6 +2714,26 @@ $(3): | $(1) $(hide) ln -sf $(2) $$@ endef +# Copy an apk to a target location while removing classes*.dex +# $(1): source file +# $(2): destination file +# $(3): LOCAL_DEX_PREOPT, if nostripping then leave classes*.dex +define dexpreopt-copy-jar +$(2): $(1) + @echo $(if $(filter nostripping,$(3)),"Copy: $$@","Copy without dex: $$@") + $$(copy-file-to-target) + $(if $(filter nostripping,$(3)),,$$(call dexpreopt-remove-classes.dex,$$@)) +endef + +# $(1): the .jar or .apk to remove classes.dex +define dexpreopt-remove-classes.dex +$(hide) zip --quiet --delete $(1) classes.dex; \ +dex_index=2; \ +while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \ + let dex_index=dex_index+1; \ +done +endef + ########################################################### ## Commands to call Proguard ########################################################### diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk index 439f7e565..aad0acd4a 100644 --- a/core/dex_preopt.mk +++ b/core/dex_preopt.mk @@ -48,15 +48,6 @@ endif GLOBAL_DEXPREOPT_FLAGS := -# $(1): the .jar or .apk to remove classes.dex -define dexpreopt-remove-classes.dex -$(hide) zip --quiet --delete $(1) classes.dex; \ -dex_index=2; \ -while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \ - let dex_index=dex_index+1; \ -done -endef - # Special rules for building stripped boot jars that override java_library.mk rules # $(1): boot jar module name @@ -64,11 +55,7 @@ define _dexpreopt-boot-jar-remove-classes.dex _dbj_jar_no_dex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1)_nodex.jar _dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar -$$(_dbj_jar_no_dex) : $$(_dbj_src_jar) - $$(call copy-file-to-target) -ifneq ($(DEX_PREOPT_DEFAULT),nostripping) - $$(call dexpreopt-remove-classes.dex,$$@) -endif +$(call dexpreopt-copy-jar,$$(_dbj_src_jar),$$(_dbj_jar_no_dex),$(DEX_PREOPT_DEFAULT)) _dbj_jar_no_dex := _dbj_src_jar := diff --git a/core/java_library.mk b/core/java_library.mk index f93365381..d728c53b2 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -86,10 +86,7 @@ $(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(common_javalib.jar) @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)" $(call dexpreopt-one-file,$<,$@) -$(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE))) -ifneq (nostripping,$(LOCAL_DEX_PREOPT)) - $(call dexpreopt-remove-classes.dex,$@) -endif +$(eval $(call dexpreopt-copy-jar,$(common_javalib.jar),$(LOCAL_BUILT_MODULE),$(LOCAL_DEX_PREOPT))) endif # ! boot jar diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index f515230e4..d112e864b 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -430,11 +430,7 @@ $(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(my_prebuilt_src_file) @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)" $(call dexpreopt-one-file,$<,$@) -$(built_module) : $(my_prebuilt_src_file) - $(call copy-file-to-target) -ifneq (nostripping,$(LOCAL_DEX_PREOPT)) - $(call dexpreopt-remove-classes.dex,$@) -endif +$(eval $(call dexpreopt-copy-jar,$(my_prebuilt_src_file),$(built_module),$(LOCAL_DEX_PREOPT))) endif # boot jar else # ! LOCAL_DEX_PREOPT $(built_module) : $(my_prebuilt_src_file)