From fbc5b9f56b89dfeacbb05f9e780e5c0a34feabdb Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Fri, 11 Mar 2016 10:32:01 -0800 Subject: [PATCH] Rebuild odex files in PDK fusion build. To rebuild odex files of Java libraries and apps, we store the jars/apks without stripping the classes.dex inside the platform.zip. We also save the build variables that may affect how we rebuild an odex in pdk_dexpreopt_config.mk in the platform.zip. We store the files and configuration only for libraries/apps that get installed to the system.img (or vendor.img). In PDK fusion build, we auto-generate prebuilt module definitions for the javalib.jar and package.dex.apk carried in the platform.zip, using configuration stored in pdk_dexpreopt_config.mk. With the prebult modules, we override the implicit rule that directly copies the odex from the platform.zip. To rebuild odex of javalib.jar, we added support for prebuilt shared Java library to prebiult_internal.mk. An installable prebuilt Java library is treated as shared Java library, i.e. with classes.dex in the jar instead of a set of .class files. For apks in the platform.zip, we install the stripped version from platform files inside platform.zip, instead of the package.dex.apk, using a new variable LOCAL_REPLACE_PREBUILT_APK_INSTALLED. We can't strip package.dex.apk because we can't re-sign the stripped apk at this point. We generate prebuilt module only if it's not already defined in the source tree. Bug: 27543283 Change-Id: I9e146f8b713d6f57c397fd28d88c9ab700757ca1 (cherry-pick from commit 3a61eeb6cb588b9a206bd80814183bcc0263cd13) --- core/Makefile | 46 +++++++++++++++++-- core/clear_vars.mk | 3 ++ core/config.mk | 2 + core/definitions.mk | 18 ++++++-- core/dex_preopt.mk | 18 ++++++++ core/dex_preopt_libart.mk | 3 +- core/dex_preopt_libart_boot.mk | 7 +-- core/dex_preopt_odex_install.mk | 21 ++++++--- core/main.mk | 7 ++- core/package_internal.mk | 8 +++- core/pdk_fusion_modules.mk | 75 +++++++++++++++++++++++++++++++ core/prebuilt_internal.mk | 80 ++++++++++++++++++++++++++++----- 12 files changed, 256 insertions(+), 32 deletions(-) create mode 100644 core/pdk_fusion_modules.mk diff --git a/core/Makefile b/core/Makefile index c93031144..907943e1f 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1237,16 +1237,53 @@ systemtarball-nodeps: $(FS_GET_STATS) \ .PHONY: stnod stnod: systemtarball-nodeps -####### +# ----------------------------------------------------------------- ## platform.zip: system, plus other files to be used in PDK fusion build, ## in a zip file ## ## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip. ## The variable will be typically set from BoardConfig.mk. ## Files under out dir will be rejected to prevent possible conflicts with other rules. +pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\ + $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m)))) +pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\ + $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m)))) +pdk_classes_dex := $(strip \ + $(foreach m,$(pdk_odex_javalibs),$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar) \ + $(foreach m,$(pdk_odex_apps),$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)) + +pdk_odex_config_mk := $(PRODUCT_OUT)/pdk_dexpreopt_config.mk +$(pdk_odex_config_mk): PRIVATE_JAVA_LIBRARIES := $(pdk_odex_javalibs) +$(pdk_odex_config_mk): PRIVATE_APPS := $(pdk_odex_apps) +$(pdk_odex_config_mk) : + @echo "PDK odex config makefile: $@" + $(hide) mkdir -p $(dir $@) + $(hide) echo "# Auto-generated. Do not modify." > $@ + $(hide) echo "PDK.DEXPREOPT.JAVA_LIBRARIES:=$(PRIVATE_JAVA_LIBRARIES)" >> $@ + $(hide) echo "PDK.DEXPREOPT.APPS:=$(PRIVATE_APPS)" >> $@ + $(foreach m,$(PRIVATE_JAVA_LIBRARIES),\ + $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\ + ) + $(foreach m,$(PRIVATE_APPS),\ + $(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).PRIVILEGED_MODULE:=$(DEXPREOPT.$(m).PRIVILEGED_MODULE)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).PROPRIETARY_MODULE:=$(DEXPREOPT.$(m).PROPRIETARY_MODULE)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).TARGET_ARCH:=$(DEXPREOPT.$(m).TARGET_ARCH)" >> $@$(newline)\ + $(hide) echo "PDK.DEXPREOPT.$(m).STRIPPED_SRC:=$(patsubst $(PRODUCT_OUT)/%,%,$(DEXPREOPT.$(m).INSTALLED_STRIPPED))" >> $@$(newline)\ + ) + PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)) INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip -$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) + +$(INSTALLED_PLATFORM_ZIP): PRIVATE_DEX_FILES := $(pdk_classes_dex) +$(INSTALLED_PLATFORM_ZIP): PRIVATE_ODEX_CONFIG := $(pdk_odex_config_mk) +$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) $(pdk_odex_config_mk) $(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)") $(hide) rm -f $@ $(hide) cd $(dir $@) && zip -qryX $(notdir $@) \ @@ -1263,6 +1300,9 @@ endif ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),) $(hide) zip -qryX $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES) endif + @# Add dex-preopt files and config. + $(if $(PRIVATE_DEX_FILES),$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@ $(PRIVATE_DEX_FILES))) + $(hide) zip -qryXj $@ $(PRIVATE_ODEX_CONFIG) .PHONY: platform platform: $(INSTALLED_PLATFORM_ZIP) @@ -1275,7 +1315,7 @@ ifneq (,$(filter platform platform-java, $(MAKECMDGOALS))) $(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP)) endif -####### +# ----------------------------------------------------------------- ## boot tarball define build-boottarball-target $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)" diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 7304bf8d7..dc44a1a1a 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -187,6 +187,9 @@ LOCAL_DBUS_PROXY_PREFIX:= LOCAL_INIT_RC:= LOCAL_MODULE_HOST_OS:= LOCAL_NOTICE_FILE:= +# Used to replace the installed file of a presigned prebuilt apk in PDK fusion build, +# to avoid installing the presigned apks with classes.dex unstripped. +LOCAL_REPLACE_PREBUILT_APK_INSTALLED:= # arch specific variables LOCAL_SRC_FILES_$(TARGET_ARCH):= diff --git a/core/config.mk b/core/config.mk index 3a433513d..e68673367 100644 --- a/core/config.mk +++ b/core/config.mk @@ -439,6 +439,8 @@ ifeq (,$(wildcard $(PDK_FUSION_PLATFORM_ZIP))) endif endif +BUILD_PLATFORM_ZIP := $(filter platform platform-java,$(MAKECMDGOALS)) + # # Tools that are prebuilts for TARGET_BUILD_APPS # diff --git a/core/definitions.mk b/core/definitions.mk index e73f9d3da..5a91045a1 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2283,7 +2283,12 @@ endef #TODO: update the manifest to point to the dex file define add-dex-to-package -$(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $@ +$(call add-dex-to-package-arg,$@) +endef + +# $(1): the package file. +define add-dex-to-package-arg +$(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $(1) endef # Add java resources added by the current module. @@ -2322,12 +2327,17 @@ endef # Sign a package using the specified key/cert. # define sign-package -$(hide) mv $@ $@.unsigned +$(call sign-package-arg,$@) +endef + +# $(1): the package file we are signing. +define sign-package-arg +$(hide) mv $(1) $(1).unsigned $(hide) java -Djava.library.path=$(SIGNAPK_JNI_LIBRARY_PATH) -jar $(SIGNAPK_JAR) \ --min-sdk-version $(call get-package-min-sdk-version-int,$@.unsigned) \ $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \ - $(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed -$(hide) mv $@.signed $@ + $(PRIVATE_ADDITIONAL_CERTIFICATES) $(1).unsigned $(1).signed +$(hide) mv $(1).signed $(1) endef # Align STORED entries of a package on 4-byte boundaries to make them easier to mmap. diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk index 8c473f7c5..457f1d4de 100644 --- a/core/dex_preopt.mk +++ b/core/dex_preopt.mk @@ -19,6 +19,24 @@ DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREO # The default value for LOCAL_DEX_PREOPT DEX_PREOPT_DEFAULT ?= true +# The default values for pre-opting: always preopt PIC. +# Conditional to building on linux, as dex2oat currently does not work on darwin. +ifeq ($(HOST_OS),linux) + WITH_DEXPREOPT_PIC ?= true + WITH_DEXPREOPT ?= true +# For an eng build only pre-opt the boot image. This gives reasonable performance and still +# allows a simple workflow: building in frameworks/base and syncing. + ifeq (eng,$(TARGET_BUILD_VARIANT)) + WITH_DEXPREOPT_BOOT_IMG_ONLY ?= true + endif +endif + +GLOBAL_DEXPREOPT_FLAGS := +ifeq ($(WITH_DEXPREOPT_PIC),true) +# Compile boot.oat as position-independent code if WITH_DEXPREOPT_PIC=true +GLOBAL_DEXPREOPT_FLAGS += --compile-pic +endif + # $(1): the .jar or .apk to remove classes.dex define dexpreopt-remove-classes.dex $(hide) zip --quiet --delete $(1) classes.dex; \ diff --git a/core/dex_preopt_libart.mk b/core/dex_preopt_libart.mk index f90eebc60..30433f6fc 100644 --- a/core/dex_preopt_libart.mk +++ b/core/dex_preopt_libart.mk @@ -98,5 +98,6 @@ $(hide) ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \ --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info \ --abort-on-hard-verifier-error \ --no-inline-from=core-oj.jar \ - $(PRIVATE_DEX_PREOPT_FLAGS) + $(PRIVATE_DEX_PREOPT_FLAGS) \ + $(GLOBAL_DEXPREOPT_FLAGS) endef diff --git a/core/dex_preopt_libart_boot.mk b/core/dex_preopt_libart_boot.mk index f8fc655e3..1c8fb40b0 100644 --- a/core/dex_preopt_libart_boot.mk +++ b/core/dex_preopt_libart_boot.mk @@ -29,11 +29,6 @@ $(my_2nd_arch_prefix)LIBART_TARGET_BOOT_OAT_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPE $(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE := $(PRODUCT_OUT)$($(my_2nd_arch_prefix)LIBART_BOOT_IMAGE_FILENAME) -# Compile boot.oat as position-independent code if WITH_DEXPREOPT_PIC=true -ifeq (true,$(WITH_DEXPREOPT_PIC)) - PRODUCT_DEX_PREOPT_BOOT_FLAGS += --compile-pic -endif - # If we have a compiled-classes file, create a parameter. COMPILED_CLASSES_FLAGS := ifneq ($(COMPILED_CLASSES),) @@ -67,4 +62,4 @@ $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) : $(LIBART_TARGE --instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \ --android-root=$(PRODUCT_OUT)/system --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info \ --multi-image --no-inline-from=core-oj.jar \ - $(PRODUCT_DEX_PREOPT_BOOT_FLAGS) $(COMPILED_CLASSES_FLAGS) + $(PRODUCT_DEX_PREOPT_BOOT_FLAGS) $(GLOBAL_DEXPREOPT_FLAGS) $(COMPILED_CLASSES_FLAGS) diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk index c7d9750d7..c3279f69f 100644 --- a/core/dex_preopt_odex_install.mk +++ b/core/dex_preopt_odex_install.mk @@ -88,6 +88,9 @@ endif # TARGET_2ND_ARCH endif # LOCAL_MODULE_CLASS endif # boot jar +built_odex := $(strip $(built_odex)) +installed_odex := $(strip $(installed_odex)) + ifdef built_odex ifndef LOCAL_DEX_PREOPT_FLAGS LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG) @@ -96,11 +99,6 @@ LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS) endif endif -# Compile apps with position-independent code if WITH_DEXPREOPT_PIC=true -ifeq (true,$(WITH_DEXPREOPT_PIC)) - LOCAL_DEX_PREOPT_FLAGS += --compile-pic -endif - $(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) # Use pattern rule - we may have multiple installed odex files. @@ -115,6 +113,19 @@ endif ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex) ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex) +# Record dex-preopt config. +DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT) +DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB) +DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) +DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE) +DEXPREOPT.$(LOCAL_MODULE).PROPRIETARY_MODULE := $(LOCAL_PROPRIETARY_MODULE) +DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH) +DEXPREOPT.$(LOCAL_MODULE).INSTALLED := $(installed_odex) +DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE) +DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \ + $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE)) + + # Make sure to install the .odex when you run "make " $(my_register_name): $(installed_odex) diff --git a/core/main.mk b/core/main.mk index 44d52a034..6742deeb4 100644 --- a/core/main.mk +++ b/core/main.mk @@ -539,6 +539,11 @@ endif $(foreach mk, $(subdir_makefiles),$(info including $(mk) ...)$(eval include $(mk))) +ifdef PDK_FUSION_PLATFORM_ZIP +# Bring in the PDK platform.zip modules. +include $(BUILD_SYSTEM)/pdk_fusion_modules.mk +endif # PDK_FUSION_PLATFORM_ZIP + endif # dont_bother endif # ONE_SHOT_MAKEFILE @@ -766,7 +771,7 @@ overridden_packages := $(call get-package-overrides,$(modules_to_install)) ifdef overridden_packages # old_modules_to_install := $(modules_to_install) modules_to_install := \ - $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \ + $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk %/$(p).odex), \ $(modules_to_install)) endif #$(error filtered out diff --git a/core/package_internal.mk b/core/package_internal.mk index 1dff26950..64040e5f9 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -438,13 +438,17 @@ 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 +else # full_classes_jar $(add-dex-to-package) -endif +endif # full_classes_jar ifdef LOCAL_JACK_ENABLED $(add-carried-jack-resources) endif ifdef LOCAL_DEX_PREOPT +ifneq ($(BUILD_PLATFORM_ZIP),) + @# Keep a copy of apk with classes.dex unstripped + $(hide) cp -f $@ $(dir $@)package.dex.apk +endif # BUILD_PLATFORM_ZIP ifneq (nostripping,$(LOCAL_DEX_PREOPT)) $(call dexpreopt-remove-classes.dex,$@) endif diff --git a/core/pdk_fusion_modules.mk b/core/pdk_fusion_modules.mk new file mode 100644 index 000000000..369ecbbbe --- /dev/null +++ b/core/pdk_fusion_modules.mk @@ -0,0 +1,75 @@ +# Auto-generate module defitions from platform.zip. +# We use these rules to rebuild .odex files of the .jar/.apk inside the platform.zip. +# + +pdk_dexpreopt_config_mk := $(TARGET_OUT_INTERMEDIATES)/pdk_dexpreopt_config.mk + +$(shell rm -f $(pdk_dexpreopt_config_mk) && mkdir -p $(dir $(pdk_dexpreopt_config_mk)) && \ + unzip -qo $(PDK_FUSION_PLATFORM_ZIP) -d $(dir $(pdk_dexpreopt_config_mk)) pdk_dexpreopt_config.mk 2>/dev/null) + +-include $(pdk_dexpreopt_config_mk) + +# Define a PDK prebuilt module that comes from platform.zip. +# Must be called with $(eval) +define prebuilt-pdk-java-module +include $(CLEAR_VARS) +LOCAL_MODULE:=$(1) +LOCAL_MODULE_CLASS:=$(2) +# Use LOCAL_PREBUILT_MODULE_FILE instead of LOCAL_SRC_FILES so we don't need to deal with LOCAL_PATH. +LOCAL_PREBUILT_MODULE_FILE:=$(3) +LOCAL_DEX_PREOPT:=$(4) +LOCAL_MULTILIB:=$(5) +LOCAL_DEX_PREOPT_FLAGS:=$(6) +LOCAL_BUILT_MODULE_STEM:=$(7) +LOCAL_MODULE_SUFFIX:=$(suffix $(7)) +LOCAL_PRIVILEGED_MODULE:=$(8) +LOCAL_PROPRIETARY_MODULE:=$(9) +LOCAL_MODULE_TARGET_ARCH:=$(10) +LOCAL_REPLACE_PREBUILT_APK_INSTALLED:=$(11) +LOCAL_CERTIFICATE:=PRESIGNED +include $(BUILD_PREBUILT) + +# The source prebuilts are extracted in the rule of _pdk_fusion_stamp. +# Use a touch rule to establish the dependency. +$(3) $(11) : $(_pdk_fusion_stamp) + $(hide) if [ ! -f $$@ ]; then \ + echo 'Error: $$@ does not exist. Check your platform.zip.' 1>&2; \ + exit 1; \ + fi + $(hide) touch $$@ +endef + +##### Java libraries. +# Only set up rules for modules that aren't built from source. +pdk_prebuilt_libraries := $(foreach l,$(PDK.DEXPREOPT.JAVA_LIBRARIES),\ + $(if $(MODULE.TARGET.JAVA_LIBRARIES.$(l)),,$(l))) + +$(foreach l,$(pdk_prebuilt_libraries), $(eval \ + $(call prebuilt-pdk-java-module,\ + $(l),\ + JAVA_LIBRARIES,\ + $(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(l).SRC),\ + $(PDK.DEXPREOPT.$(l).DEX_PREOPT),\ + $(PDK.DEXPREOPT.$(l).MULTILIB),\ + $(PDK.DEXPREOPT.$(l).DEX_PREOPT_FLAGS),\ + javalib.jar,\ + ))) + +###### Apps. +pdk_prebuilt_apps := $(foreach a,$(PDK.DEXPREOPT.APPS),\ + $(if $(MODULE.TARGET.APPS.$(a)),,$(a))) + +$(foreach a,$(pdk_prebuilt_apps), $(eval \ + $(call prebuilt-pdk-java-module,\ + $(a),\ + APPS,\ + $(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(a).SRC),\ + $(PDK.DEXPREOPT.$(a).DEX_PREOPT),\ + $(PDK.DEXPREOPT.$(a).MULTILIB),\ + $(PDK.DEXPREOPT.$(a).DEX_PREOPT_FLAGS),\ + package.apk,\ + $(PDK.DEXPREOPT.$(a).PRIVILEGED_MODULE),\ + $(PDK.DEXPREOPT.$(a).PROPRIETARY_MODULE),\ + $(PDK.DEXPREOPT.$(a).TARGET_ARCH),\ + $(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(a).STRIPPED_SRC),\ + ))) diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index fb9cf8d28..e82675516 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -77,6 +77,12 @@ ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)) endif endif +ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE))) + prebuilt_module_is_dex_javalib := true +else + prebuilt_module_is_dex_javalib := +endif + ifeq ($(LOCAL_MODULE_CLASS),APPS) LOCAL_BUILT_MODULE_STEM := package.apk LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk @@ -203,16 +209,23 @@ else endif # Disable dex-preopt of prebuilts to save space, if requested. +ifndef LOCAL_DEX_PREOPT ifeq ($(DONT_DEXPREOPT_PREBUILTS),true) LOCAL_DEX_PREOPT := false endif +endif ####################################### # defines built_odex along with rule to install odex include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk ####################################### -# Sign and align non-presigned .apks. +ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),) +# There is a replacement for the prebuilt .apk we can install without any processing. +$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED) | $(ACP) + $(transform-prebuilt-to-target) +else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED +# Sign and align non-presigned .apks. # The embedded prebuilt jni to uncompress. ifeq ($(LOCAL_CERTIFICATE),PRESIGNED) # For PRESIGNED apks we must uncompress every .so file: @@ -229,18 +242,25 @@ $(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs) $(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR) $(AAPT) $(transform-prebuilt-to-target) $(uncompress-shared-libs) +ifdef LOCAL_DEX_PREOPT +ifneq ($(BUILD_PLATFORM_ZIP),) + @# Keep a copy of apk with classes.dex unstripped + $(hide) cp -f $@ $(dir $@)package.dex.apk +endif # BUILD_PLATFORM_ZIP +endif # LOCAL_DEX_PREOPT ifneq ($(LOCAL_CERTIFICATE),PRESIGNED) @# Only strip out files if we can re-sign the package. ifdef LOCAL_DEX_PREOPT ifneq (nostripping,$(LOCAL_DEX_PREOPT)) $(call dexpreopt-remove-classes.dex,$@) -endif -endif +endif # LOCAL_DEX_PREOPT != nostripping +endif # LOCAL_DEX_PREOPT $(sign-package) # No need for align-package because sign-package takes care of alignment -else +else # LOCAL_CERTIFICATE == PRESIGNED $(align-package) -endif +endif # LOCAL_CERTIFICATE +endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED ############################### ## Rule to build the odex file @@ -284,8 +304,39 @@ $(my_register_name): $(installed_apk_splits) endif # LOCAL_PACKAGE_SPLITS -else # LOCAL_MODULE_CLASS != APPS +else ifeq ($(prebuilt_module_is_dex_javalib),true) # LOCAL_MODULE_CLASS != APPS +# This is a target shared library, i.e. a jar with classes.dex. +####################################### +# defines built_odex along with rule to install odex +include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk +####################################### +ifdef LOCAL_DEX_PREOPT +ifneq ($(dexpreopt_boot_jar_module),) # boot jar +# boot jar's rules are defined in dex_preopt.mk +dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar +$(built_module) : $(dexpreopted_boot_jar) | $(ACP) + $(call copy-file-to-target) +# For libart boot jars, we don't have .odex files. +else # ! boot jar +$(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE) +# Use pattern rule - we may have multiple built odex files. +$(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) | $(ACP) + $(call copy-file-to-target) +ifneq (nostripping,$(LOCAL_DEX_PREOPT)) + $(call dexpreopt-remove-classes.dex,$@) +endif +endif # boot jar +else # ! LOCAL_DEX_PREOPT +$(built_module) : $(my_prebuilt_src_file) | $(ACP) + $(call copy-file-to-target) +endif # LOCAL_DEX_PREOPT + +else # ! prebuilt_module_is_dex_javalib $(built_module) : $(my_prebuilt_src_file) ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) $(transform-prebuilt-to-target-strip-comments) @@ -295,21 +346,25 @@ endif ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) $(hide) chmod +x $@ endif - -endif # LOCAL_MODULE_CLASS != APPS +endif # ! prebuilt_module_is_dex_javalib ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) my_src_jar := $(my_prebuilt_src_file) ifeq ($(LOCAL_IS_HOST_MODULE),) # for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir, # while the deps should be in the common dir, so we make a copy in the common dir. -# For nonstatic library, $(common_javalib_jar) is the dependency file, -# while $(common_classes_jar) is used to link. common_classes_jar := $(intermediates.COMMON)/classes.jar common_javalib_jar := $(intermediates.COMMON)/javalib.jar $(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE) +ifeq ($(prebuilt_module_is_dex_javalib),true) +# For prebuilt shared Java library we don't have classes.jar. +$(common_javalib_jar) : $(my_src_jar) | $(ACP) + $(transform-prebuilt-to-target) + +else # ! prebuilt_module_is_dex_javalib + ifneq ($(filter %.aar, $(my_prebuilt_src_file)),) # This is .aar file, archive of classes.jar and Android resources. my_src_jar := $(intermediates.COMMON)/aar/classes.jar @@ -321,6 +376,7 @@ $(my_src_jar) : $(my_prebuilt_src_file) $(hide) touch $@ endif + $(common_classes_jar) : $(my_src_jar) $(transform-prebuilt-to-target) @@ -331,8 +387,11 @@ $(call define-jar-to-toc-rule, $(common_classes_jar)) # make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE) $(built_module) : $(common_javalib_jar) + +endif # ! prebuilt_module_is_dex_javalib endif # LOCAL_IS_HOST_MODULE is not set +ifneq ($(prebuilt_module_is_dex_javalib),true) ifneq ($(LOCAL_JILL_FLAGS),) $(error LOCAL_JILL_FLAGS is not supported any more, please use jack options in LOCAL_JACK_FLAGS instead) endif @@ -349,6 +408,7 @@ $(intermediates.COMMON)/classes.jack : $(my_src_jar) \ $(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack touch $@ +endif # ! prebuilt_module_is_dex_javalib endif # JAVA_LIBRARIES $(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)