Move dexpreopting to Soong
Move the dexpreopting logic into Soong. Make modules will be
dexpreopted by executing the Soong logic in the standalone
dexpreopt_gen binary, which will generate scripts that will
perform dexpreopting for each module. Export global configuration
as JSON to $OUT/dexpreopt.config, which will be used by
dexpreopt_gen and Soong, and per-module JSON configuration that
will be used by dexpreopt_gen.
This relands I59b20c931ee3e5a8d35eb30da4148691c5095502,
I39d580999947ee54cfefe875b57a028be5333bd7,
Ie7daa94e107d53eff075ca58dbe721bd9d7fc8c2 and
Ica006a007d112c232311435aaac0c0e476232b67, with a minor
update to match the changes made to dexpreopt_gen arguments
and a fix to correctly keep dexpreopt disabled on mac builds.
Bug: 119412419
Bug: 120273280
Test: no differences to dexpreopt outputs on aosp_sailfish system/,
only expected changes to dexpreopt outputs on system_other
(.vdex files for privileged Soong modules no longer incorrectly
contain .dex contents).
Change-Id: I25163e91886cea6941afa25cdb529ed053278dcb
diff --git a/core/package_internal.mk b/core/package_internal.mk
index 9327587..451fce7 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -432,6 +432,8 @@
endif # need_compile_res
+my_dex_jar := $(intermediates.COMMON)/dex.jar
+
called_from_package_internal := true
#################################
include $(BUILD_SYSTEM)/java.mk
@@ -631,6 +633,12 @@
ifneq ($(BUILD_PLATFORM_ZIP),)
$(LOCAL_BUILT_MODULE) : .KATI_IMPLICIT_OUTPUTS := $(dir $(LOCAL_BUILT_MODULE))package.dex.apk
endif
+ifdef LOCAL_DEX_PREOPT
+$(LOCAL_BUILT_MODULE) : PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh
+$(LOCAL_BUILT_MODULE) : $(intermediates)/strip.sh
+$(LOCAL_BUILT_MODULE) : | $(DEXPREOPT_GEN_DEPS)
+$(LOCAL_BUILT_MODULE): .KATI_DEPFILE := $(LOCAL_BUILT_MODULE).d
+endif
$(LOCAL_BUILT_MODULE):
@echo "target Package: $(PRIVATE_MODULE) ($@)"
rm -rf $@.parts
@@ -670,9 +678,8 @@
@# Keep a copy of apk with classes.dex unstripped
$(hide) cp -f $@ $(dir $@)package.dex.apk
endif # BUILD_PLATFORM_ZIP
-ifdef LOCAL_STRIP_DEX
- $(call dexpreopt-remove-classes.dex,$@)
-endif
+ $(PRIVATE_STRIP_SCRIPT) $@ $@.tmp
+ mv -f $@.tmp $@
endif # LOCAL_DEX_PREOPT
$(sign-package)
ifdef LOCAL_COMPRESSED_MODULE
@@ -739,23 +746,13 @@
endif
###############################
-## Rule to build the odex file
+## Rule to build a jar containing dex files to dexpreopt without waiting for
+## the APK
ifdef LOCAL_DEX_PREOPT
-$(built_odex): PRIVATE_DEX_FILE := $(built_dex)
-ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
-$(built_odex): $(ZIP2ZIP) $(ZIPALIGN)
-endif
-# Use pattern rule - we may have multiple built odex files.
-$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(built_dex)
+ $(my_dex_jar): PRIVATE_DEX_FILE := $(built_dex)
+ $(my_dex_jar): $(built_dex)
$(hide) mkdir -p $(dir $@) && rm -f $@
$(call create-dex-jar,$@,$(PRIVATE_DEX_FILE))
-ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
- $(uncompress-dexs)
- $(align-package)
-endif
- $(hide) mv $@ $@.input
- $(call dexpreopt-one-file,$@.input,$@)
- $(hide) rm $@.input
endif
###############################