From 6db5b0ea9aae3fffc4b90ed1cd40e50ee8b06765 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 16 Nov 2018 21:26:33 -0800 Subject: [PATCH] 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 --- {core => common}/json.mk | 0 core/Makefile | 7 +- core/clear_vars.mk | 2 +- core/config.mk | 2 + core/dex_preopt.mk | 70 +---- core/dex_preopt_config.mk | 200 ++++++++++++++ core/dex_preopt_libart.mk | 116 -------- core/dex_preopt_libart_boot.mk | 4 +- core/dex_preopt_odex_install.mk | 451 ++++++++++---------------------- core/java_library.mk | 14 +- core/package_internal.mk | 31 +-- core/prebuilt_internal.mk | 44 ++-- core/setup_one_odex.mk | 140 ---------- core/soong_app_prebuilt.mk | 35 +-- core/soong_config.mk | 12 +- core/soong_java_prebuilt.mk | 49 ++-- 16 files changed, 441 insertions(+), 736 deletions(-) rename {core => common}/json.mk (100%) create mode 100644 core/dex_preopt_config.mk delete mode 100644 core/setup_one_odex.mk diff --git a/core/json.mk b/common/json.mk similarity index 100% rename from core/json.mk rename to common/json.mk diff --git a/core/Makefile b/core/Makefile index 70bf60df41..4eb04a6c86 100644 --- a/core/Makefile +++ b/core/Makefile @@ -2158,9 +2158,9 @@ stnod: systemtarball-nodeps ## Files under out dir will be rejected to prevent possible conflicts with other rules. ifneq (,$(BUILD_PLATFORM_ZIP)) pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\ - $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m)))) + $(if $(filter $(DEXPREOPT.$(m).INSTALLED_STRIPPED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m)))) pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\ - $(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m)))) + $(if $(filter $(DEXPREOPT.$(m).INSTALLED_STRIPPED),$(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)) @@ -2446,6 +2446,9 @@ INTERNAL_SYSTEMOTHERIMAGE_FILES := \ $(ALL_PDK_FUSION_FILES)) \ $(PDK_FUSION_SYMLINK_STAMP) +# system_other dex files are installed as a side-effect of installing system image files +INTERNAL_SYSTEMOTHERIMAGE_FILES += $(INTERNAL_SYSTEMIMAGE_FILES) + INSTALLED_FILES_FILE_SYSTEMOTHER := $(PRODUCT_OUT)/installed-files-system-other.txt INSTALLED_FILES_JSON_SYSTEMOTHER := $(INSTALLED_FILES_FILE_SYSTEMOTHER:.txt=.json) $(INSTALLED_FILES_FILE_SYSTEMOTHER): .KATI_IMPLICIT_OUTPUTS := $(INSTALLED_FILES_JSON_SYSTEMOTHER) diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 799425f156..0fce502a65 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -256,6 +256,7 @@ LOCAL_SDK_VERSION:= LOCAL_SHARED_ANDROID_LIBRARIES:= LOCAL_SHARED_LIBRARIES:= LOCAL_SOONG_AAR := +LOCAL_SOONG_BUILT_INSTALLED := LOCAL_SOONG_BUNDLE := LOCAL_SOONG_CLASSES_JAR := LOCAL_SOONG_DEX_JAR := @@ -278,7 +279,6 @@ LOCAL_STATIC_ANDROID_LIBRARIES:= LOCAL_STATIC_JAVA_AAR_LIBRARIES:= LOCAL_STATIC_JAVA_LIBRARIES:= LOCAL_STATIC_LIBRARIES:= -LOCAL_STRIP_DEX:= LOCAL_STRIP_MODULE:= LOCAL_SYSTEM_SHARED_LIBRARIES:=none LOCAL_TARGET_REQUIRED_MODULES:= diff --git a/core/config.mk b/core/config.mk index b7c2ed1620..9d77fe52ba 100644 --- a/core/config.mk +++ b/core/config.mk @@ -120,6 +120,8 @@ include $(BUILD_SYSTEM_COMMON)/math.mk include $(BUILD_SYSTEM_COMMON)/strings.mk +include $(BUILD_SYSTEM_COMMON)/json.mk + # Various mappings to avoid hard-coding paths all over the place include $(BUILD_SYSTEM)/pathmap.mk diff --git a/core/dex_preopt.mk b/core/dex_preopt.mk index 92ed9707fb..59346ed352 100644 --- a/core/dex_preopt.mk +++ b/core/dex_preopt.mk @@ -3,31 +3,7 @@ # #################################### -# list of boot classpath jars for dexpreopt -DEXPREOPT_BOOT_JARS := $(subst $(space),:,$(PRODUCT_BOOT_JARS)) -DEXPREOPT_BOOT_JARS_MODULES := $(PRODUCT_BOOT_JARS) -PRODUCT_BOOTCLASSPATH := $(subst $(space),:,$(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),/system/framework/$(m).jar)) - -PRODUCT_SYSTEM_SERVER_CLASSPATH := $(subst $(space),:,$(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),/system/framework/$(m).jar)) - -DEXPREOPT_BUILD_DIR := $(OUT_DIR) -DEXPREOPT_PRODUCT_DIR_FULL_PATH := $(PRODUCT_OUT)/dex_bootjars -DEXPREOPT_PRODUCT_DIR := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXPREOPT_PRODUCT_DIR_FULL_PATH)) -DEXPREOPT_BOOT_JAR_DIR := system/framework -DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREOPT_BOOT_JAR_DIR) - -# The default value for LOCAL_DEX_PREOPT -DEX_PREOPT_DEFAULT ?= true - -# The default filter for which files go into the system_other image (if it is -# being used). To bundle everything one should set this to '%' -SYSTEM_OTHER_ODEX_FILTER ?= \ - app/% \ - priv-app/% \ - product_services/app/% \ - product_services/priv-app/% \ - product/app/% \ - product/priv-app/% \ +include $(BUILD_SYSTEM)/dex_preopt_config.mk # Method returning whether the install path $(1) should be for system_other. # Under SANITIZE_LITE, we do not want system_other. Just put things under /data/asan. @@ -37,35 +13,6 @@ else install-on-system-other = $(filter-out $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(basename $(notdir $(filter $(foreach f,$(SYSTEM_OTHER_ODEX_FILTER),$(TARGET_OUT)/$(f)),$(1))))) endif -# 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 ?= true - ifeq (eng,$(TARGET_BUILD_VARIANT)) - # Don't strip for quick development turnarounds. - DEX_PREOPT_DEFAULT := nostripping - # For an eng build only pre-opt the boot image and system server. This gives reasonable performance - # and still allows a simple workflow: building in frameworks/base and syncing. - WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true - endif - # Add mini-debug-info to the boot classpath unless explicitly asked not to. - ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO)) - PRODUCT_DEX_PREOPT_BOOT_FLAGS += --generate-mini-debug-info - endif - - # Non eng linux builds must have preopt enabled so that system server doesn't run as interpreter - # only. b/74209329 - ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT))) - ifneq (true,$(WITH_DEXPREOPT)) - ifneq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY)) - $(call pretty-error, DEXPREOPT must be enabled for user and userdebug builds) - endif - endif - endif -endif - -GLOBAL_DEXPREOPT_FLAGS := - # Special rules for building stripped boot jars that override java_library.mk rules # $(1): boot jar module name @@ -83,19 +30,6 @@ $(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),$(eval $(call _dexpreopt-boot-jar-rem include $(BUILD_SYSTEM)/dex_preopt_libart.mk -# Define dexpreopt-one-file based on current default runtime. -# $(1): the input .jar or .apk file -# $(2): the output .odex file -define dexpreopt-one-file -$(call dex2oat-one-file,$(1),$(2)) -endef - -DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS := $(DEX2OAT_DEPENDENCY) -DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) -ifdef TARGET_2ND_ARCH -$(TARGET_2ND_ARCH_VAR_PREFIX)DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) -endif # TARGET_2ND_ARCH - # === hiddenapi rules === hiddenapi_stubs_jar = $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar @@ -149,6 +83,8 @@ $(INTERNAL_PLATFORM_HIDDENAPI_PRIVATE_LIST): $(HIDDENAPI) $(HIDDENAPI_STUBS) \ $(call commit-change-for-toc,$(INTERNAL_PLATFORM_HIDDENAPI_PUBLIC_LIST)) $(call commit-change-for-toc,$(INTERNAL_PLATFORM_HIDDENAPI_PRIVATE_LIST)) + + ifeq ($(PRODUCT_DIST_BOOT_AND_SYSTEM_JARS),true) boot_profile_jars_zip := $(PRODUCT_OUT)/boot_profile_jars.zip all_boot_jars := \ diff --git a/core/dex_preopt_config.mk b/core/dex_preopt_config.mk new file mode 100644 index 0000000000..cc456897a6 --- /dev/null +++ b/core/dex_preopt_config.mk @@ -0,0 +1,200 @@ +DEX_PREOPT_CONFIG := $(PRODUCT_OUT)/dexpreopt.config + +# list of boot classpath jars for dexpreopt +DEXPREOPT_BOOT_JARS := $(subst $(space),:,$(PRODUCT_BOOT_JARS)) +DEXPREOPT_BOOT_JARS_MODULES := $(PRODUCT_BOOT_JARS) +PRODUCT_BOOTCLASSPATH := $(subst $(space),:,$(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),/system/framework/$(m).jar)) + +PRODUCT_SYSTEM_SERVER_CLASSPATH := $(subst $(space),:,$(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),/system/framework/$(m).jar)) + +DEXPREOPT_BUILD_DIR := $(OUT_DIR) +DEXPREOPT_PRODUCT_DIR_FULL_PATH := $(PRODUCT_OUT)/dex_bootjars +DEXPREOPT_PRODUCT_DIR := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXPREOPT_PRODUCT_DIR_FULL_PATH)) +DEXPREOPT_BOOT_JAR_DIR := system/framework +DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREOPT_BOOT_JAR_DIR) + +DEFAULT_DEX_PREOPT_BUILT_IMAGE_LOCATION := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.art +DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(DEX2OAT_TARGET_ARCH)/boot.art + +ifdef TARGET_2ND_ARCH + $(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_LOCATION := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.art + $(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH)/boot.art +endif + +# The default value for LOCAL_DEX_PREOPT +DEX_PREOPT_DEFAULT ?= true + +# The default filter for which files go into the system_other image (if it is +# being used). To bundle everything one should set this to '%' +SYSTEM_OTHER_ODEX_FILTER ?= \ + app/% \ + priv-app/% \ + product_services/app/% \ + product_services/priv-app/% \ + product/app/% \ + product/priv-app/% \ + +# 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 ?= true + ifeq (eng,$(TARGET_BUILD_VARIANT)) + # Don't strip for quick development turnarounds. + DEX_PREOPT_DEFAULT := nostripping + # For an eng build only pre-opt the boot image and system server. This gives reasonable performance + # and still allows a simple workflow: building in frameworks/base and syncing. + WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true + endif + # Add mini-debug-info to the boot classpath unless explicitly asked not to. + ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO)) + PRODUCT_DEX_PREOPT_BOOT_FLAGS += --generate-mini-debug-info + endif + + # Non eng linux builds must have preopt enabled so that system server doesn't run as interpreter + # only. b/74209329 + ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT))) + ifneq (true,$(WITH_DEXPREOPT)) + ifneq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY)) + $(call pretty-error, DEXPREOPT must be enabled for user and userdebug builds) + endif + endif + endif +endif + +# Default to debug version to help find bugs. +# Set USE_DEX2OAT_DEBUG to false for only building non-debug versions. +ifeq ($(USE_DEX2OAT_DEBUG),false) +DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oat$(HOST_EXECUTABLE_SUFFIX) +else +DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX) +endif + +DEX2OAT_DEPENDENCY += $(DEX2OAT) + +# Use the first preloaded-classes file in PRODUCT_COPY_FILES. +PRELOADED_CLASSES := $(call word-colon,1,$(firstword \ + $(filter %system/etc/preloaded-classes,$(PRODUCT_COPY_FILES)))) + +# Use the first dirty-image-objects file in PRODUCT_COPY_FILES. +DIRTY_IMAGE_OBJECTS := $(call word-colon,1,$(firstword \ + $(filter %system/etc/dirty-image-objects,$(PRODUCT_COPY_FILES)))) + +define get-product-default-property +$(strip \ + $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))\ + $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES))))) +endef + +DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms) +DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx) +DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms) +DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx) + +ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64)) +# MIPS specific overrides. +# For MIPS the ART image is loaded at a lower address. This causes issues +# with the image overlapping with memory on the host cross-compiling and +# building the image. We therefore limit the Xmx value. This isn't done +# via a property as we want the larger Xmx value if we're running on a +# MIPS device. +DEX2OAT_XMX := 128m +endif + +ifeq ($(WRITE_SOONG_VARIABLES),true) + + $(call json_start) + + $(call add_json_bool, DefaultNoStripping, $(filter nostripping,$(DEX_PREOPT_DEFAULT))) + $(call add_json_list, DisablePreoptModules, $(DEXPREOPT_DISABLED_MODULES)) + $(call add_json_bool, OnlyPreoptBootImageAndSystemServer, $(filter true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))) + $(call add_json_bool, DontUncompressPrivAppsDex, $(filter true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS))) + $(call add_json_list, ModulesLoadedByPrivilegedModules, $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES)) + $(call add_json_bool, HasSystemOther, $(BOARD_USES_SYSTEM_OTHER_ODEX)) + $(call add_json_list, PatternsOnSystemOther, $(SYSTEM_OTHER_ODEX_FILTER)) + $(call add_json_bool, DisableGenerateProfile, $(filter false,$(WITH_DEX_PREOPT_GENERATE_PROFILE))) + $(call add_json_list, BootJars, $(DEXPREOPT_BOOT_JARS_MODULES)) + $(call add_json_list, SystemServerJars, $(PRODUCT_SYSTEM_SERVER_JARS)) + $(call add_json_list, SystemServerApps, $(PRODUCT_SYSTEM_SERVER_APPS)) + $(call add_json_list, SpeedApps, $(PRODUCT_DEXPREOPT_SPEED_APPS)) + $(call add_json_list, PreoptFlags, $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS)) + $(call add_json_str, DefaultCompilerFilter, $(PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER)) + $(call add_json_str, SystemServerCompilerFilter, $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)) + $(call add_json_bool, GenerateDmFiles, $(PRODUCT_DEX_PREOPT_GENERATE_DM_FILES)) + $(call add_json_bool, NoDebugInfo, $(filter false,$(WITH_DEXPREOPT_DEBUG_INFO))) + $(call add_json_bool, AlwaysSystemServerDebugInfo, $(filter true,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO))) + $(call add_json_bool, NeverSystemServerDebugInfo, $(filter false,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO))) + $(call add_json_bool, AlwaysOtherDebugInfo, $(filter true,$(PRODUCT_OTHER_JAVA_DEBUG_INFO))) + $(call add_json_bool, NeverOtherDebugInfo, $(filter false,$(PRODUCT_OTHER_JAVA_DEBUG_INFO))) + $(call add_json_list, MissingUsesLibraries, $(INTERNAL_PLATFORM_MISSING_USES_LIBRARIES)) + $(call add_json_bool, IsEng, $(filter eng,$(TARGET_BUILD_VARIANT))) + $(call add_json_bool, SanitizeLite, $(SANITIZE_LITE)) + $(call add_json_bool, DefaultAppImages, $(WITH_DEX_PREOPT_APP_IMAGE)) + $(call add_json_str, Dex2oatXmx, $(DEX2OAT_XMX)) + $(call add_json_str, Dex2oatXms, $(DEX2OAT_XMS)) + $(call add_json_str, EmptyDirectory, $(OUT_DIR)/empty) + + $(call add_json_map, DefaultDexPreoptImageLocation) + $(call add_json_str, $(TARGET_ARCH), $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_LOCATION)) + ifdef TARGET_2ND_ARCH + $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_LOCATION)) + endif + $(call end_json_map) + + $(call add_json_map, CpuVariant) + $(call add_json_str, $(TARGET_ARCH), $(DEX2OAT_TARGET_CPU_VARIANT)) + ifdef TARGET_2ND_ARCH + $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT)) + endif + $(call end_json_map) + + $(call add_json_map, InstructionSetFeatures) + $(call add_json_str, $(TARGET_ARCH), $(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)) + ifdef TARGET_2ND_ARCH + $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES)) + endif + $(call end_json_map) + + $(call add_json_map, Tools) + $(call add_json_str, Profman, $(PROFMAN)) + $(call add_json_str, Dex2oat, $(DEX2OAT)) + $(call add_json_str, Aapt, $(AAPT)) + $(call add_json_str, SoongZip, $(SOONG_ZIP)) + $(call add_json_str, Zip2zip, $(ZIP2ZIP)) + $(call add_json_str, VerifyUsesLibraries, $(BUILD_SYSTEM)/verify_uses_libraries.sh) + $(call add_json_str, ConstructContext, $(BUILD_SYSTEM)/construct_context.sh) + $(call end_json_map) + + $(call json_end) + + $(shell mkdir -p $(dir $(DEX_PREOPT_CONFIG))) + $(file >$(DEX_PREOPT_CONFIG).tmp,$(json_contents)) + + $(shell \ + if ! cmp -s $(DEX_PREOPT_CONFIG).tmp $(DEX_PREOPT_CONFIG); then \ + mv $(DEX_PREOPT_CONFIG).tmp $(DEX_PREOPT_CONFIG); \ + else \ + rm $(DEX_PREOPT_CONFIG).tmp; \ + fi) +endif + +# Dummy rule to create dexpreopt.config, it will already have been created +# by the $(file) call above, but a rule needs to exist to keep the dangling +# rule check happy. +$(DEX_PREOPT_CONFIG): + @#empty + +DEXPREOPT_GEN_DEPS := \ + $(PROFMAN) \ + $(DEX2OAT) \ + $(AAPT) \ + $(SOONG_ZIP) \ + $(ZIP2ZIP) \ + $(BUILD_SYSTEM)/verify_uses_libraries.sh \ + $(BUILD_SYSTEM)/construct_context.sh \ + +DEXPREOPT_GEN_DEPS += $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) +ifdef TARGET_2ND_ARCH + ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true) + DEXPREOPT_GEN_DEPS += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) + endif +endif diff --git a/core/dex_preopt_libart.mk b/core/dex_preopt_libart.mk index 1c9ef64335..631db0a0f1 100644 --- a/core/dex_preopt_libart.mk +++ b/core/dex_preopt_libart.mk @@ -3,77 +3,9 @@ # #################################### -# Default to debug version to help find bugs. -# Set USE_DEX2OAT_DEBUG to false for only building non-debug versions. -ifeq ($(USE_DEX2OAT_DEBUG),false) -DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oat$(HOST_EXECUTABLE_SUFFIX) -else -DEX2OAT := $(HOST_OUT_EXECUTABLES)/dex2oatd$(HOST_EXECUTABLE_SUFFIX) -endif - -DEX2OAT_DEPENDENCY += $(DEX2OAT) - -# Use the first preloaded-classes file in PRODUCT_COPY_FILES. -PRELOADED_CLASSES := $(call word-colon,1,$(firstword \ - $(filter %system/etc/preloaded-classes,$(PRODUCT_COPY_FILES)))) - -# Use the first dirty-image-objects file in PRODUCT_COPY_FILES. -DIRTY_IMAGE_OBJECTS := $(call word-colon,1,$(firstword \ - $(filter %system/etc/dirty-image-objects,$(PRODUCT_COPY_FILES)))) - -define get-product-default-property -$(strip \ - $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))\ - $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES))))) -endef - -DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms) -DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx) -DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms) -DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx) - -ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64)) -# MIPS specific overrides. -# For MIPS the ART image is loaded at a lower address. This causes issues -# with the image overlapping with memory on the host cross-compiling and -# building the image. We therefore limit the Xmx value. This isn't done -# via a property as we want the larger Xmx value if we're running on a -# MIPS device. -DEX2OAT_XMX := 128m -endif - ######################################################################## # The full system boot classpath -# Returns the path to the .odex file -# $(1): the arch name. -# $(2): the full path (including file name) of the corresponding .jar or .apk. -define get-odex-file-path -$(dir $(2))oat/$(1)/$(basename $(notdir $(2))).odex -endef - -# Returns the full path to the installed .odex file. -# This handles BOARD_USES_SYSTEM_OTHER_ODEX to install odex files into another -# partition. -# $(1): the arch name. -# $(2): the full install path (including file name) of the corresponding .apk. -ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true) -define get-odex-installed-file-path -$(if $(call install-on-system-other, $(2)), - $(call get-odex-file-path,$(1),$(patsubst $(TARGET_OUT)/%,$(TARGET_OUT_SYSTEM_OTHER)/%,$(2))), - $(call get-odex-file-path,$(1),$(2))) -endef -else -get-odex-installed-file-path = $(get-odex-file-path) -endif - -# Returns the path to the image file (such as "/system/framework//boot.art" -# $(1): the arch name (such as "arm") -# $(2): the image location (such as "/system/framework/boot.art") -define get-image-file-path -$(dir $(2))$(1)/$(notdir $(2)) -endef - LIBART_TARGET_BOOT_JARS := $(DEXPREOPT_BOOT_JARS_MODULES) LIBART_TARGET_BOOT_DEX_LOCATIONS := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),/$(DEXPREOPT_BOOT_JAR_DIR)/$(jar).jar) LIBART_TARGET_BOOT_DEX_FILES := $(foreach jar,$(LIBART_TARGET_BOOT_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),,COMMON)/javalib.jar) @@ -164,51 +96,3 @@ $(LIBART_TARGET_BOOT_ART_VDEX_INSTALLED_SHARED_FILES) : $(DEFAULT_DEX_PREOPT_BUI $(hide) ln -sf /$(DEXPREOPT_BOOT_JAR_DIR)/$(notdir $@) $(SECOND_ARCH_DIR)$(notdir $@) my_2nd_arch_prefix := - -######################################################################## -# For a single jar or APK - -# $(1): the input .jar or .apk file -# $(2): the output .odex file -# In the case where LOCAL_ENFORCE_USES_LIBRARIES is true, PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT -# contains the normalized path list of the libraries. This makes it easier to conditionally prepend -# org.apache.http.legacy.impl based on the SDK level if required. -# -# Pass --avoid-storing-invocation to make the output deterministics between -# different products that may have different paths on the command line. -define dex2oat-one-file -$(hide) rm -f $(2) -$(hide) mkdir -p $(dir $(2)) -stored_class_loader_context_libs=$(PRIVATE_DEX2OAT_STORED_CLASS_LOADER_CONTEXT_LIBS) && \ -class_loader_context_arg=--class-loader-context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \ -class_loader_context=$(PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT) && \ -stored_class_loader_context_arg="" && \ -uses_library_names="$(PRIVATE_USES_LIBRARY_NAMES)" && \ -optional_uses_library_names="$(PRIVATE_OPTIONAL_USES_LIBRARY_NAMES)" && \ -aapt_binary="$(AAPT)" && \ -$(if $(filter true,$(PRIVATE_ENFORCE_USES_LIBRARIES)), \ -source build/make/core/verify_uses_libraries.sh "$(1)" && \ -source build/make/core/construct_context.sh "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_HOST)" "$(PRIVATE_CONDITIONAL_USES_LIBRARIES_TARGET)" && \ -,) \ -ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \ - --avoid-storing-invocation \ - --runtime-arg -Xms$(DEX2OAT_XMS) --runtime-arg -Xmx$(DEX2OAT_XMX) \ - $${class_loader_context_arg} \ - $${stored_class_loader_context_arg} \ - --boot-image=$(PRIVATE_DEX_PREOPT_IMAGE_LOCATION) \ - --dex-file=$(1) \ - --dex-location=$(PRIVATE_DEX_LOCATION) \ - --oat-file=$(2) \ - --android-root=$(PRODUCT_OUT)/system \ - --instruction-set=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_ARCH) \ - --instruction-set-variant=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT) \ - --instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \ - --no-generate-debug-info --generate-build-id \ - --abort-on-hard-verifier-error \ - --force-determinism \ - --no-inline-from=core-oj.jar \ - $(PRIVATE_DEX_PREOPT_FLAGS) \ - $(PRIVATE_ART_FILE_PREOPT_FLAGS) \ - $(PRIVATE_PROFILE_PREOPT_FLAGS) \ - $(GLOBAL_DEXPREOPT_FLAGS) -endef diff --git a/core/dex_preopt_libart_boot.mk b/core/dex_preopt_libart_boot.mk index 70a934cd98..156ce02f73 100644 --- a/core/dex_preopt_libart_boot.mk +++ b/core/dex_preopt_libart_boot.mk @@ -20,8 +20,6 @@ # 2ND_DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME=out/target/product/generic_x86_64/dex_bootjars/system/framework/x86/boot.art # 2ND_LIBART_BOOT_IMAGE=/system/framework/x86/boot.art -$(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_BUILT_IMAGE_LOCATION := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.art -$(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$($(my_2nd_arch_prefix)DEX2OAT_TARGET_ARCH)/boot.art $(my_2nd_arch_prefix)LIBART_BOOT_IMAGE_FILENAME := /$(DEXPREOPT_BOOT_JAR_DIR)/$($(my_2nd_arch_prefix)DEX2OAT_TARGET_ARCH)/boot.art # The .oat with symbols @@ -114,7 +112,7 @@ $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) : $(LIBART_TARGE --no-inline-from=core-oj.jar \ --abort-on-hard-verifier-error \ --abort-on-soft-verifier-error \ - $(PRODUCT_DEX_PREOPT_BOOT_FLAGS) $(GLOBAL_DEXPREOPT_FLAGS) $(ART_BOOT_IMAGE_EXTRA_ARGS) \ + $(PRODUCT_DEX_PREOPT_BOOT_FLAGS) $(ART_BOOT_IMAGE_EXTRA_ARGS) \ || ( echo "$(DEX2OAT_FAILURE_MESSAGE)" ; false ) endif diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk index 47a03e855a..0d19619108 100644 --- a/core/dex_preopt_odex_install.mk +++ b/core/dex_preopt_odex_install.mk @@ -25,24 +25,6 @@ endif # DONT_UNCOMPRESS_PRIV_APPS_DEXS LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT)) ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT) - - ifeq ($(filter $(TARGET_OUT)/%,$(my_module_path)),) # Not installed to system.img. - # Default to nostripping for non system preopt (enables preopt). - # Don't strip in case the oat/vdex version in system ROM doesn't match the one in other - # partitions. It needs to be able to fall back to the APK for that case. - LOCAL_DEX_PREOPT := nostripping - endif - - ifneq (,$(LOCAL_APK_LIBRARIES)) # LOCAL_APK_LIBRARIES not empty - LOCAL_DEX_PREOPT := nostripping - endif -endif - -ifeq (nostripping,$(LOCAL_DEX_PREOPT)) - LOCAL_DEX_PREOPT := true - LOCAL_STRIP_DEX := -else - LOCAL_STRIP_DEX := true endif ifeq (false,$(LOCAL_DEX_PREOPT)) @@ -90,38 +72,8 @@ ifneq (true,$(my_preopt_for_extracted_apk)) endif endif -ifeq ($(LOCAL_DEX_PREOPT),true) - # Don't strip with dexes we explicitly uncompress (dexopt will not store the dex code). - ifeq ($(LOCAL_UNCOMPRESS_DEX),true) - LOCAL_STRIP_DEX := - endif # LOCAL_UNCOMPRESS_DEX - - # system_other isn't there for an OTA, so don't strip - # if module is on system, and odex is on system_other. - ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true) - ifneq ($(call install-on-system-other, $(my_module_path)),) - LOCAL_STRIP_DEX := - endif # install-on-system-other - endif # BOARD_USES_SYSTEM_OTHER_ODEX - - # We also don't strip if all dexs are uncompressed (dexopt will not store the dex code), - # but that requires to inspect the source file, which is too early at this point (as we - # don't know if the source file will actually be used). - # See dexpreopt-remove-classes.dex. -endif # LOCAL_DEX_PREOPT - -built_odex := -built_vdex := -built_art := -installed_odex := -installed_vdex := -installed_art := -built_installed_odex := -built_installed_vdex := -built_installed_art := my_process_profile := my_profile_is_text_listing := -my_generate_dm := ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE)) LOCAL_DEX_PREOPT_GENERATE_PROFILE := false @@ -135,7 +87,7 @@ ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE))) my_process_profile := true - my_profile_is_text_listing := false + my_profile_is_text_listing := endif else my_process_profile := $(LOCAL_DEX_PREOPT_GENERATE_PROFILE) @@ -144,273 +96,72 @@ else endif ifeq (true,$(my_process_profile)) - - ifeq (,$(LOCAL_DEX_PREOPT_APP_IMAGE)) - LOCAL_DEX_PREOPT_APP_IMAGE := true - endif - ifndef LOCAL_DEX_PREOPT_PROFILE $(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE)) endif ifeq (,$(dex_preopt_profile_src_file)) $(call pretty-error, Internal error: dex_preopt_profile_src_file must be set) endif - my_built_profile := $(dir $(LOCAL_BUILT_MODULE))/profile.prof - my_dex_location := $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE)) - # Remove compressed APK extension. - my_dex_location := $(patsubst %.gz,%,$(my_dex_location)) - $(my_built_profile): PRIVATE_BUILT_MODULE := $(dex_preopt_profile_src_file) - $(my_built_profile): PRIVATE_DEX_LOCATION := $(my_dex_location) - $(my_built_profile): PRIVATE_SOURCE_CLASSES := $(LOCAL_DEX_PREOPT_PROFILE) - $(my_built_profile): $(LOCAL_DEX_PREOPT_PROFILE) - $(my_built_profile): $(PROFMAN) - $(my_built_profile): $(dex_preopt_profile_src_file) - ifeq (true,$(my_profile_is_text_listing)) - # The profile is a test listing of classes (used for framework jars). - # We need to generate the actual binary profile before being able to compile. - $(my_built_profile): - $(hide) mkdir -p $(dir $@) - ANDROID_LOG_TAGS="*:e" $(PROFMAN) \ - --create-profile-from=$(PRIVATE_SOURCE_CLASSES) \ - --apk=$(PRIVATE_BUILT_MODULE) \ - --dex-location=$(PRIVATE_DEX_LOCATION) \ - --reference-profile-file=$@ - else - # The profile is binary profile (used for apps). Run it through profman to - # ensure the profile keys match the apk. - $(my_built_profile): - $(hide) mkdir -p $(dir $@) - touch $@ - ANDROID_LOG_TAGS="*:e" $(PROFMAN) \ - --copy-and-update-profile-key \ - --profile-file=$(PRIVATE_SOURCE_CLASSES) \ - --apk=$(PRIVATE_BUILT_MODULE) \ - --dex-location=$(PRIVATE_DEX_LOCATION) \ - --reference-profile-file=$@ \ - || echo "Profile out of date for $(PRIVATE_BUILT_MODULE)" - endif - - my_profile_is_text_listing := - dex_preopt_profile_src_file := - - # Remove compressed APK extension. - my_installed_profile := $(patsubst %.gz,%,$(LOCAL_INSTALLED_MODULE)).prof - - # my_installed_profile := $(LOCAL_INSTALLED_MODULE).prof - $(eval $(call copy-one-file,$(my_built_profile),$(my_installed_profile))) - build_installed_profile:=$(my_built_profile):$(my_installed_profile) -else - build_installed_profile:= - my_installed_profile := endif +# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or +# LOCAL_OPTIONAL_USES_LIBRARIES are specified. +ifeq (,$(LOCAL_ENFORCE_USES_LIBRARIES)) + # Will change the default to true unconditionally in the future. + ifneq (,$(LOCAL_OPTIONAL_USES_LIBRARIES)) + LOCAL_ENFORCE_USES_LIBRARIES := true + endif + ifneq (,$(LOCAL_USES_LIBRARIES)) + LOCAL_ENFORCE_USES_LIBRARIES := true + endif +endif + +my_dexpreopt_archs := + ifdef LOCAL_DEX_PREOPT - - dexpreopt_boot_jar_module := $(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)) - - ifdef dexpreopt_boot_jar_module - # For libart, the boot jars' odex files are replaced by $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE). - # We use this installed_odex trick to get boot.art installed. - installed_odex := $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE) - # Append the odex for the 2nd arch if we have one. - installed_odex += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE) - else # boot jar - ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) - - my_module_multilib := $(LOCAL_MULTILIB) - # If the module is not an SDK library and it's a system server jar, only preopt the primary arch. - my_filtered_lib_name := $(patsubst %.impl,%,$(LOCAL_MODULE)) - ifeq (,$(filter $(JAVA_SDK_LIBRARIES),$(my_filtered_lib_name))) - # For a Java library, by default we build odex for both 1st arch and 2nd arch. - # But it can be overridden with "LOCAL_MULTILIB := first". - ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) - # For system server jars, we build for only "first". - my_module_multilib := first - endif - endif - - # Only preopt primary arch for translated arch since there is only an image there. - ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) + ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) + my_module_multilib := $(LOCAL_MULTILIB) + # If the module is not an SDK library and it's a system server jar, only preopt the primary arch. + my_filtered_lib_name := $(patsubst %.impl,%,$(LOCAL_MODULE)) + ifeq (,$(filter $(JAVA_SDK_LIBRARIES),$(my_filtered_lib_name))) + # For a Java library, by default we build odex for both 1st arch and 2nd arch. + # But it can be overridden with "LOCAL_MULTILIB := first". + ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) + # For system server jars, we build for only "first". my_module_multilib := first endif - - # ################################################# - # Odex for the 1st arch - my_2nd_arch_prefix := - include $(BUILD_SYSTEM)/setup_one_odex.mk - # ################################################# - # Odex for the 2nd arch - ifdef TARGET_2ND_ARCH - ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true) - ifneq (first,$(my_module_multilib)) - my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX) - include $(BUILD_SYSTEM)/setup_one_odex.mk - endif # my_module_multilib is not first. - endif # TARGET_TRANSLATE_2ND_ARCH not true - endif # TARGET_2ND_ARCH - # ################################################# - else # must be APPS - # The preferred arch - my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) - # Save the module multilib since setup_one_odex modifies it. - saved_my_module_multilib := $(my_module_multilib) - include $(BUILD_SYSTEM)/setup_one_odex.mk - my_module_multilib := $(saved_my_module_multilib) - ifdef TARGET_2ND_ARCH - ifeq ($(my_module_multilib),both) - # The non-preferred arch - my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX)) - include $(BUILD_SYSTEM)/setup_one_odex.mk - endif # LOCAL_MULTILIB is both - endif # TARGET_2ND_ARCH - endif # LOCAL_MODULE_CLASS - endif # boot jar - - built_odex := $(strip $(built_odex)) - built_vdex := $(strip $(built_vdex)) - built_art := $(strip $(built_art)) - installed_odex := $(strip $(installed_odex)) - installed_vdex := $(strip $(installed_vdex)) - installed_art := $(strip $(installed_art)) - - ifdef built_odex - ifeq (true,$(my_process_profile)) - $(built_odex): $(my_built_profile) - $(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := --profile-file=$(my_built_profile) - else - $(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := endif - ifndef LOCAL_DEX_PREOPT_FLAGS - LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG) - ifndef LOCAL_DEX_PREOPT_FLAGS - LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS) - endif + # Only preopt primary arch for translated arch since there is only an image there. + ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) + my_module_multilib := first endif - my_system_server_compiler_filter := $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER) - ifeq (,$(my_system_server_compiler_filter)) - my_system_server_compiler_filter := speed - endif - - my_default_compiler_filter := $(PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER) - ifeq (,$(my_default_compiler_filter)) - # If no default compiler filter is specified, default to 'quicken' to save on storage. - my_default_compiler_filter := quicken - endif - - ifeq (,$(filter --compiler-filter=%, $(LOCAL_DEX_PREOPT_FLAGS))) - ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) - # Jars of system server, use the product option if it is set, speed otherwise. - LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=$(my_system_server_compiler_filter) - else - ifneq (,$(filter $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(LOCAL_MODULE))) - # Apps loaded into system server, and apps the product default to being compiled with the - # 'speed' compiler filter. - LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed - else - ifeq (true,$(my_process_profile)) - # For non system server jars, use speed-profile when we have a profile. - LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed-profile - else - LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=$(my_default_compiler_filter) - endif - endif - endif - endif - - my_generate_dm := $(PRODUCT_DEX_PREOPT_GENERATE_DM_FILES) - ifeq (,$(filter $(LOCAL_DEX_PREOPT_FLAGS),--compiler-filter=verify)) - # Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs. - my_generate_dm := false - endif - - # No reason to use a dm file if the dex is already uncompressed. - ifeq ($(LOCAL_UNCOMPRESS_DEX),true) - my_generate_dm := false - endif - - ifeq (true,$(my_generate_dm)) - LOCAL_DEX_PREOPT_FLAGS += --copy-dex-files=false - LOCAL_DEX_PREOPT := true - LOCAL_STRIP_DEX := - my_built_dm := $(dir $(LOCAL_BUILT_MODULE))generated.dm - my_installed_dm := $(patsubst %.apk,%,$(LOCAL_INSTALLED_MODULE)).dm - my_copied_vdex := $(dir $(LOCAL_BUILT_MODULE))primary.vdex - $(eval $(call copy-one-file,$(built_vdex),$(my_copied_vdex))) - $(my_built_dm): PRIVATE_INPUT_VDEX := $(my_copied_vdex) - $(my_built_dm): $(my_copied_vdex) $(ZIPTIME) - $(hide) mkdir -p $(dir $@) - $(hide) rm -f $@ - $(hide) zip -qD -j -X -9 $@ $(PRIVATE_INPUT_VDEX) - $(ZIPTIME) $@ - $(eval $(call copy-one-file,$(my_built_dm),$(my_installed_dm))) - endif - - # By default, emit debug info. - my_dexpreopt_debug_info := true - # If the global setting suppresses mini-debug-info, disable it. - ifeq (false,$(WITH_DEXPREOPT_DEBUG_INFO)) - my_dexpreopt_debug_info := false - endif - - # PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. - # PRODUCT_OTHER_JAVA_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. - ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) - ifeq (true,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)) - my_dexpreopt_debug_info := true - else ifeq (false,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)) - my_dexpreopt_debug_info := false - endif - else - ifeq (true,$(PRODUCT_OTHER_JAVA_DEBUG_INFO)) - my_dexpreopt_debug_info := true - else ifeq (false,$(PRODUCT_OTHER_JAVA_DEBUG_INFO)) - my_dexpreopt_debug_info := false - endif - endif - - # Never enable on eng. - ifeq (eng,$(filter eng, $(TARGET_BUILD_VARIANT))) - my_dexpreopt_debug_info := false - endif - - # Add dex2oat flag for debug-info/no-debug-info. - ifeq (true,$(my_dexpreopt_debug_info)) - LOCAL_DEX_PREOPT_FLAGS += --generate-mini-debug-info - else ifeq (false,$(my_dexpreopt_debug_info)) - LOCAL_DEX_PREOPT_FLAGS += --no-generate-mini-debug-info - endif - - # Set the compiler reason to 'prebuilt' to identify the oat files produced - # during the build, as opposed to compiled on the device. - LOCAL_DEX_PREOPT_FLAGS += --compilation-reason=prebuilt - - $(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) - $(built_vdex): $(built_odex) - $(built_art): $(built_odex) - endif - - ifneq (true,$(my_generate_dm)) - # Add the installed_odex to the list of installed files for this module if we aren't generating a - # dm file. - ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex) - ALL_MODULES.$(my_register_name).INSTALLED += $(installed_vdex) - ALL_MODULES.$(my_register_name).INSTALLED += $(installed_art) - - ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex) - ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_vdex) - ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_art) - - # Make sure to install the .odex and .vdex when you run "make " - $(my_all_targets): $(installed_odex) $(installed_vdex) $(installed_art) - else - ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_dm) - ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(my_built_dm) $(my_installed_dm) - - # Make sure to install the .dm when you run "make " - $(my_all_targets): $(installed_dm) - endif + # ################################################# + # Odex for the 1st arch + my_dexpreopt_archs += $(TARGET_ARCH) + # Odex for the 2nd arch + ifdef TARGET_2ND_ARCH + ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true) + ifneq (first,$(my_module_multilib)) + my_dexpreopt_archs += $(TARGET_2ND_ARCH) + endif # my_module_multilib is not first. + endif # TARGET_TRANSLATE_2ND_ARCH not true + endif # TARGET_2ND_ARCH + # ################################################# + else # must be APPS + # The preferred arch + # Save the module multilib since setup_one_odex modifies it. + my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) + my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH) + ifdef TARGET_2ND_ARCH + ifeq ($(my_module_multilib),both) + # The non-preferred arch + my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX)) + my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH) + endif # LOCAL_MULTILIB is both + endif # TARGET_2ND_ARCH + endif # LOCAL_MODULE_CLASS # Record dex-preopt config. DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT) @@ -419,17 +170,97 @@ ifdef LOCAL_DEX_PREOPT DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE) DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_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)) + $(call json_start) + + $(call add_json_str, Name, $(LOCAL_MODULE)) + $(call add_json_str, DexLocation, $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))) + $(call add_json_str, BuildPath, $(LOCAL_BUILT_MODULE)) + $(call add_json_str, DexPath, $$1) + $(call add_json_str, ExtrasOutputPath, $$2) + $(call add_json_bool, PreferIntegrity, $(filter true,$(LOCAL_PREFER_INTEGRITY))) + $(call add_json_bool, Privileged, $(filter true,$(LOCAL_PRIVILEGED_MODULE))) + $(call add_json_bool, UncompressedDex, $(filter true,$(LOCAL_UNCOMPRESS_DEX))) + $(call add_json_bool, HasApkLibraries, $(LOCAL_APK_LIBRARIES)) + $(call add_json_list, PreoptFlags, $(LOCAL_DEX_PREOPT_FLAGS)) + $(call add_json_str, ProfileClassListing, $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE))) + $(call add_json_bool, ProfileIsTextListing, $(my_profile_is_text_listing)) + $(call add_json_bool, EnforceUsesLibraries, $(LOCAL_ENFORCE_USES_LIBRARIES)) + $(call add_json_list, OptionalUsesLibraries, $(LOCAL_OPTIONAL_USES_LIBRARIES)) + $(call add_json_list, UsesLibraries, $(LOCAL_USES_LIBRARIES)) + $(call add_json_map, LibraryPaths) + $(foreach lib,$(sort $(LOCAL_USES_LIBRARIES) $(LOCAL_OPTIONAL_USES_LIBRARIES) org.apache.http.legacy.impl),\ + $(call add_json_str, $(lib), $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar)) + $(call end_json_map) + $(call add_json_list, Archs, $(my_dexpreopt_archs)) + $(call add_json_str, DexPreoptImageLocation, $(LOCAL_DEX_PREOPT_IMAGE_LOCATION)) + $(call add_json_bool, PreoptExtractedApk, $(my_preopt_for_extracted_apk)) + $(call add_json_bool, NoCreateAppImage, $(filter false,$(LOCAL_DEX_PREOPT_APP_IMAGE))) + $(call add_json_bool, ForceCreateAppImage, $(filter true,$(LOCAL_DEX_PREOPT_APP_IMAGE))) + $(call add_json_bool, PresignedPrebuilt, $(filter PRESIGNED,$(LOCAL_CERTIFICATE))) + + $(call add_json_str, StripInputPath, $$1) + $(call add_json_str, StripOutputPath, $$2) + + $(call json_end) + + my_dexpreopt_config := $(intermediates)/dexpreopt.config + my_dexpreopt_script := $(intermediates)/dexpreopt.sh + my_strip_script := $(intermediates)/strip.sh + my_dexpreopt_zip := $(intermediates)/dexpreopt.zip + + $(my_dexpreopt_config): PRIVATE_MODULE := $(LOCAL_MODULE) + $(my_dexpreopt_config): PRIVATE_CONTENTS := $(json_contents) + $(my_dexpreopt_config): + @echo "$(PRIVATE_MODULE) dexpreopt.config" + echo -e -n '$(subst $(newline),\n,$(subst ','\'',$(subst \,\\,$(PRIVATE_CONTENTS))))' > $@ + + .KATI_RESTAT: $(my_dexpreopt_script) $(my_strip_script) + $(my_dexpreopt_script): PRIVATE_MODULE := $(LOCAL_MODULE) + $(my_dexpreopt_script): PRIVATE_GLOBAL_CONFIG := $(PRODUCT_OUT)/dexpreopt.config + $(my_dexpreopt_script): PRIVATE_MODULE_CONFIG := $(my_dexpreopt_config) + $(my_dexpreopt_script): PRIVATE_STRIP_SCRIPT := $(my_strip_script) + $(my_dexpreopt_script): .KATI_IMPLICIT_OUTPUTS := $(my_strip_script) + $(my_dexpreopt_script): $(DEXPREOPT_GEN) + $(my_dexpreopt_script): $(my_dexpreopt_config) $(PRODUCT_OUT)/dexpreopt.config + @echo "$(PRIVATE_MODULE) dexpreopt gen" + $(DEXPREOPT_GEN) -global $(PRIVATE_GLOBAL_CONFIG) -module $(PRIVATE_MODULE_CONFIG) \ + -dexpreopt_script $@ -strip_script $(PRIVATE_STRIP_SCRIPT) + + my_dexpreopt_deps := $(my_dex_jar) + my_dexpreopt_deps += $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE)) + my_dexpreopt_deps += \ + $(foreach lib,$(sort $(LOCAL_USES_LIBRARIES) $(LOCAL_OPTIONAL_USES_LIBRARIES) org.apache.http.legacy.impl),\ + $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar) + my_dexpreopt_deps += $(LOCAL_DEX_PREOPT_IMAGE_LOCATION) + # TODO: default boot images + + $(my_dexpreopt_zip): PRIVATE_MODULE := $(LOCAL_MODULE) + $(my_dexpreopt_zip): $(my_dexpreopt_deps) + $(my_dexpreopt_zip): | $(DEXPREOPT_GEN_DEPS) + $(my_dexpreopt_zip): .KATI_DEPFILE := $(my_dexpreopt_zip).d + $(my_dexpreopt_zip): PRIVATE_DEX := $(my_dex_jar) + $(my_dexpreopt_zip): PRIVATE_SCRIPT := $(my_dexpreopt_script) + $(my_dexpreopt_zip): $(my_dexpreopt_script) + @echo "$(PRIVATE_MODULE) dexpreopt" + bash $(PRIVATE_SCRIPT) $(PRIVATE_DEX) $@ + + ifdef LOCAL_POST_INSTALL_CMD + # Add a shell command separator + LOCAL_POST_INSTALL_CMD += && + endif + + LOCAL_POST_INSTALL_CMD += for i in $$(zipinfo -1 $(my_dexpreopt_zip)); do mkdir -p $(PRODUCT_OUT)/$$(dirname $$i); done && unzip -qo -d $(PRODUCT_OUT) $(my_dexpreopt_zip) + $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD) + $(LOCAL_INSTALLED_MODULE): $(my_dexpreopt_zip) + + $(my_all_targets): $(my_dexpreopt_zip) + + my_dexpreopt_config := + my_dexpreopt_script := + my_strip_script := + my_dexpreopt_zip := endif # LOCAL_DEX_PREOPT - -# Profile doesn't depend on LOCAL_DEX_PREOPT. -ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_profile) -ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(build_installed_profile) - -my_process_profile := - -$(my_all_targets): $(my_installed_profile) diff --git a/core/java_library.mk b/core/java_library.mk index e4e51d85cc..3e54b0ecce 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -50,6 +50,8 @@ else LOCAL_EMMA_INSTRUMENT := false endif # EMMA_INSTRUMENT +my_dex_jar := $(common_javalib.jar) + ################################# include $(BUILD_SYSTEM)/java.mk ################################# @@ -90,13 +92,13 @@ $(eval $(call copy-one-file,$(dexpreopted_boot_jar),$(LOCAL_BUILT_MODULE))) # 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))% : $(common_javalib.jar) - @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)" - $(call dexpreopt-one-file,$<,$@) -$(eval $(call dexpreopt-copy-jar,$(common_javalib.jar),$(LOCAL_BUILT_MODULE),$(LOCAL_STRIP_DEX))) +$(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 +$(LOCAL_BUILT_MODULE): $(common_javalib.jar) + $(PRIVATE_STRIP_SCRIPT) $< $@ endif # ! boot jar diff --git a/core/package_internal.mk b/core/package_internal.mk index 9327587dd4..451fce7d90 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -432,6 +432,8 @@ endif # LOCAL_USE_AAPT2 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 @@ endif 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 @@ ifneq ($(BUILD_PLATFORM_ZIP),) @# 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 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 ############################### diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index a4b58fc663..013497f126 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -319,6 +319,8 @@ ifdef LOCAL_COMPRESSED_MODULE LOCAL_DEX_PREOPT := false endif +my_dex_jar := $(my_prebuilt_src_file) + ####################################### # defines built_odex along with rule to install odex include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk @@ -342,7 +344,6 @@ ifndef embedded_prebuilt_jni_libs embedded_prebuilt_jni_libs := endif $(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs) -$(built_module): $(ZIP2ZIP) ifdef LOCAL_COMPRESSED_MODULE $(built_module) : $(MINIGZIP) @@ -356,7 +357,13 @@ endif ifneq ($(BUILD_PLATFORM_ZIP),) $(built_module) : .KATI_IMPLICIT_OUTPUTS := $(dir $(LOCAL_BUILT_MODULE))package.dex.apk endif -$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR) +ifdef LOCAL_DEX_PREOPT +$(built_module) : PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh +$(built_module) : $(intermediates)/strip.sh +$(built_module) : | $(DEXPREOPT_GEN_DEPS) +$(built_module) : .KATI_DEPFILE := $(built_module).d +endif +$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(ZIP2ZIP) $(SIGNAPK_JAR) $(transform-prebuilt-to-target) $(uncompress-prebuilt-embedded-jni-libs) ifeq (true, $(LOCAL_UNCOMPRESS_DEX)) @@ -380,9 +387,8 @@ endif $(run-appcompat) endif # module_run_appcompat ifdef LOCAL_DEX_PREOPT -ifdef LOCAL_STRIP_DEX - $(call dexpreopt-remove-classes.dex,$@) -endif # LOCAL_STRIP_DEX + $(PRIVATE_STRIP_SCRIPT) $@ $@.tmp + mv -f $@.tmp $@ endif # LOCAL_DEX_PREOPT $(sign-package) # No need for align-package because sign-package takes care of alignment @@ -394,20 +400,6 @@ ifdef LOCAL_COMPRESSED_MODULE endif # LOCAL_COMPRESSED_MODULE endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED -############################### -## Rule to build the odex file. -# In case we don't strip the built module, use it, as dexpreopt -# can do optimizations based on whether the built module only -# contains uncompressed dex code. -ifdef LOCAL_DEX_PREOPT -ifndef LOCAL_STRIP_DEX -$(built_odex) : $(built_module) - $(call dexpreopt-one-file,$<,$@) -else -$(built_odex) : $(my_prebuilt_src_file) - $(call dexpreopt-one-file,$<,$@) -endif -endif ############################### ## Install split apks. @@ -450,6 +442,7 @@ $(my_all_targets): $(installed_apk_splits) endif # LOCAL_PACKAGE_SPLITS else ifeq ($(prebuilt_module_is_dex_javalib),true) # ! LOCAL_MODULE_CLASS != APPS +my_dex_jar := $(my_prebuilt_src_file) # This is a target shared library, i.e. a jar with classes.dex. ####################################### # defines built_odex along with rule to install odex @@ -464,13 +457,14 @@ $(built_module) : $(dexpreopted_boot_jar) # 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,$<,$@) -$(eval $(call dexpreopt-copy-jar,$(my_prebuilt_src_file),$(built_module),$(LOCAL_STRIP_DEX))) +$(built_module): PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh +$(built_module): $(intermediates)/strip.sh +$(built_module): | $(DEXPREOPT_GEN_DEPS) +$(built_module): .KATI_DEPFILE := $(built_module).d +$(built_module): $(my_prebuilt_src_file) + $(PRIVATE_STRIP_SCRIPT) $< $@ + endif # boot jar else # ! LOCAL_DEX_PREOPT $(built_module) : $(my_prebuilt_src_file) diff --git a/core/setup_one_odex.mk b/core/setup_one_odex.mk deleted file mode 100644 index 92f58b2c5a..0000000000 --- a/core/setup_one_odex.mk +++ /dev/null @@ -1,140 +0,0 @@ -# -# Copyright (C) 2014 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Set up variables and dependency for one odex file -# Input variables: my_2nd_arch_prefix -# Output(modified) variables: built_odex, installed_odex, built_installed_odex - -my_built_odex := $(call get-odex-file-path,$($(my_2nd_arch_prefix)DEX2OAT_TARGET_ARCH),$(LOCAL_BUILT_MODULE)) -ifdef LOCAL_DEX_PREOPT_IMAGE_LOCATION -my_dex_preopt_image_location := $(LOCAL_DEX_PREOPT_IMAGE_LOCATION) -else -my_dex_preopt_image_location := $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_BUILT_IMAGE_LOCATION) -endif -my_dex_preopt_image_filename := $(call get-image-file-path,$($(my_2nd_arch_prefix)DEX2OAT_TARGET_ARCH),$(my_dex_preopt_image_location)) - -# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or -# LOCAL_OPTIONAL_USES_LIBRARIES are specified. -ifeq (,$(LOCAL_ENFORCE_USES_LIBRARIES)) -# Will change the default to true unconditionally in the future. -ifneq (,$(LOCAL_OPTIONAL_USES_LIBRARIES)) -LOCAL_ENFORCE_USES_LIBRARIES := true -endif -ifneq (,$(LOCAL_USES_LIBRARIES)) -LOCAL_ENFORCE_USES_LIBRARIES := true -endif -endif - -my_uses_libraries := $(LOCAL_USES_LIBRARIES) -my_optional_uses_libraries := $(LOCAL_OPTIONAL_USES_LIBRARIES) -my_missing_uses_libraries := $(INTERNAL_PLATFORM_MISSING_USES_LIBRARIES) - -# If we have either optional or required uses-libraries, set up the class loader context -# accordingly. -my_lib_names := -my_optional_lib_names := -my_filtered_optional_uses_libraries := -my_system_dependencies := -my_stored_preopt_class_loader_context_libs := -my_conditional_uses_libraries_host := -my_conditional_uses_libraries_target := - -ifneq (true,$(LOCAL_ENFORCE_USES_LIBRARIES)) - # Pass special class loader context to skip the classpath and collision check. - # This will get removed once LOCAL_USES_LIBRARIES is enforced. - # Right now LOCAL_USES_LIBRARIES is opt in, for the case where it's not specified we still default - # to the &. - my_dex_preopt_class_loader_context := \& -else - # Compute the filtered optional uses libraries by removing ones that are not supposed to exist. - my_filtered_optional_uses_libraries := \ - $(filter-out $(my_missing_uses_libraries), $(my_optional_uses_libraries)) - my_filtered_uses_libraries := $(my_uses_libraries) $(my_filtered_optional_uses_libraries) - - # These are the ones we are verifying in the make rule, use the unfiltered libraries. - my_lib_names := $(my_uses_libraries) - my_optional_lib_names := $(my_optional_uses_libraries) - - # Calculate system build dependencies based on the filtered libraries. - my_intermediate_libs := $(foreach lib_name, $(my_lib_names) $(my_filtered_optional_uses_libraries), \ - $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib_name),,COMMON)/javalib.jar) - my_dex_preopt_system_dependencies := $(my_intermediate_libs) - my_dex_preopt_class_loader_context := $(call normalize-path-list,$(my_intermediate_libs)) - - # The class loader context checksums are filled in by dex2oat. - my_stored_preopt_class_loader_context_libs := $(call normalize-path-list, \ - $(foreach lib_name,$(my_filtered_uses_libraries),/system/framework/$(lib_name).jar)) - - # Fix up org.apache.http.legacy.impl since it should be org.apache.http.legacy in the manifest. - my_lib_names := $(patsubst org.apache.http.legacy.impl,org.apache.http.legacy,$(my_lib_names)) - my_optional_lib_names := $(patsubst org.apache.http.legacy.impl,org.apache.http.legacy,$(my_optional_lib_names)) - ifeq (,$(filter org.apache.http.legacy,$(my_lib_names) $(my_optional_lib_names))) - my_conditional_uses_libraries_host := $(call intermediates-dir-for,JAVA_LIBRARIES,org.apache.http.legacy.impl,,COMMON)/javalib.jar - my_conditional_uses_libraries_target := /system/framework/org.apache.http.legacy.impl.jar - endif -endif - -$(my_built_odex): $(AAPT) -$(my_built_odex): $(my_conditional_uses_libraries_host) -$(my_built_odex): $(my_dex_preopt_system_dependencies) -$(my_built_odex): PRIVATE_ENFORCE_USES_LIBRARIES := $(LOCAL_ENFORCE_USES_LIBRARIES) -$(my_built_odex): PRIVATE_CONDITIONAL_USES_LIBRARIES_HOST := $(my_conditional_uses_libraries_host) -$(my_built_odex): PRIVATE_CONDITIONAL_USES_LIBRARIES_TARGET := $(my_conditional_uses_libraries_target) -$(my_built_odex): PRIVATE_USES_LIBRARY_NAMES := $(my_lib_names) -$(my_built_odex): PRIVATE_OPTIONAL_USES_LIBRARY_NAMES := $(my_optional_lib_names) -$(my_built_odex): PRIVATE_2ND_ARCH_VAR_PREFIX := $(my_2nd_arch_prefix) -$(my_built_odex): PRIVATE_DEX_LOCATION := $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE)) -$(my_built_odex): PRIVATE_DEX_PREOPT_IMAGE_LOCATION := $(my_dex_preopt_image_location) -$(my_built_odex): PRIVATE_DEX2OAT_CLASS_LOADER_CONTEXT := $(my_dex_preopt_class_loader_context) -$(my_built_odex): PRIVATE_DEX2OAT_STORED_CLASS_LOADER_CONTEXT_LIBS := $(my_stored_preopt_class_loader_context_libs) -$(my_built_odex) : $($(my_2nd_arch_prefix)DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT) \ - $(DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS) \ - $(my_dex_preopt_image_filename) - -my_installed_odex := $(call get-odex-installed-file-path,$($(my_2nd_arch_prefix)DEX2OAT_TARGET_ARCH),$(LOCAL_INSTALLED_MODULE)) - -my_built_vdex := $(patsubst %.odex,%.vdex,$(my_built_odex)) -my_installed_vdex := $(patsubst %.odex,%.vdex,$(my_installed_odex)) -my_installed_art := $(patsubst %.odex,%.art,$(my_installed_odex)) - -ifndef LOCAL_DEX_PREOPT_APP_IMAGE -# Local override not defined, use the global one. -ifeq (true,$(WITH_DEX_PREOPT_APP_IMAGE)) - LOCAL_DEX_PREOPT_APP_IMAGE := true -endif -endif - -ifeq (true,$(LOCAL_DEX_PREOPT_APP_IMAGE)) -my_built_art := $(patsubst %.odex,%.art,$(my_built_odex)) -$(my_built_odex): PRIVATE_ART_FILE_PREOPT_FLAGS := --app-image-file=$(my_built_art) \ - --image-format=lz4 -$(eval $(call copy-one-file,$(my_built_art),$(my_installed_art))) -built_art += $(my_built_art) -installed_art += $(my_installed_art) -built_installed_art += $(my_built_art):$(my_installed_art) -endif - -$(eval $(call copy-one-file,$(my_built_odex),$(my_installed_odex))) -$(eval $(call copy-one-file,$(my_built_vdex),$(my_installed_vdex))) - -built_odex += $(my_built_odex) -built_vdex += $(my_built_vdex) - -installed_odex += $(my_installed_odex) -installed_vdex += $(my_installed_vdex) - -built_installed_odex += $(my_built_odex):$(my_installed_odex) -built_installed_vdex += $(my_built_vdex):$(my_installed_vdex) diff --git a/core/soong_app_prebuilt.mk b/core/soong_app_prebuilt.mk index 1440806c5c..73d934bf99 100644 --- a/core/soong_app_prebuilt.mk +++ b/core/soong_app_prebuilt.mk @@ -1,6 +1,16 @@ # App prebuilt coming from Soong. # Extra inputs: +# LOCAL_SOONG_BUILT_INSTALLED +# LOCAL_SOONG_BUNDLE +# LOCAL_SOONG_CLASSES_JAR +# LOCAL_SOONG_DEX_JAR +# LOCAL_SOONG_HEADER_JAR +# LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR +# LOCAL_SOONG_PROGUARD_DICT # LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE +# LOCAL_SOONG_RRO_DIRS +# LOCAL_SOONG_JNI_LIBS_$(TARGET_ARCH) +# LOCAL_SOONG_JNI_LIBS_$(TARGET_2ND_ARCH) ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK)) $(call pretty-error,soong_app_prebuilt.mk may only be used from Soong) @@ -59,28 +69,19 @@ endif # LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE java-dex: $(LOCAL_SOONG_DEX_JAR) -# defines built_odex along with rule to install odex -include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk ifneq ($(BUILD_PLATFORM_ZIP),) $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(dir $(LOCAL_BUILT_MODULE))package.dex.apk)) endif -ifdef LOCAL_DEX_PREOPT -ifdef LOCAL_STRIP_DEX - # If we have stripped the final APK, use the original jar generated by soong. - $(built_odex): $(LOCAL_SOONG_DEX_JAR) - $(call dexpreopt-one-file,$<,$@) -else - # If we haven't stripped, use the final APK for dexpreopt, as this may affect how the dex - # code is compiled. - $(built_odex): $(LOCAL_PREBUILT_MODULE_FILE) - $(call dexpreopt-one-file,$<,$@) -endif # LOCAL_STRIP_DEX - $(eval $(call dexpreopt-copy-jar,$(LOCAL_PREBUILT_MODULE_FILE),$(LOCAL_BUILT_MODULE),$(LOCAL_STRIP_DEX))) -else - $(eval $(call copy-one-file,$(LOCAL_PREBUILT_MODULE_FILE),$(LOCAL_BUILT_MODULE))) -endif +$(eval $(call copy-one-file,$(LOCAL_PREBUILT_MODULE_FILE),$(LOCAL_BUILT_MODULE))) + +my_built_installed := $(foreach f,$(LOCAL_SOONG_BUILT_INSTALLED),\ + $(call word-colon,1,$(f)):$(PRODUCT_OUT)$(call word-colon,2,$(f))) +my_installed := $(call copy-many-files, $(my_built_installed)) +ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed) +ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(my_built_installed) +$(my_register_name): $(my_installed) # embedded JNI will already have been handled by soong my_embed_jni := diff --git a/core/soong_config.mk b/core/soong_config.mk index 279a612fcd..3dc6d9ae81 100644 --- a/core/soong_config.mk +++ b/core/soong_config.mk @@ -13,9 +13,9 @@ BINDER32BIT := true endif endif -ifeq ($(WRITE_SOONG_VARIABLES),true) +include $(BUILD_SYSTEM)/dex_preopt_config.mk -include $(BUILD_SYSTEM)/json.mk +ifeq ($(WRITE_SOONG_VARIABLES),true) # Create soong.variables with copies of makefile settings. Runs every build, # but only updates soong.variables if it changes @@ -106,11 +106,13 @@ $(call add_json_list, DeviceSystemSdkVersions, $(BOARD_SYSTEMSDK_VERSI $(call add_json_list, Platform_systemsdk_versions, $(PLATFORM_SYSTEMSDK_VERSIONS)) $(call add_json_bool, Malloc_not_svelte, $(call invert_bool,$(filter true,$(MALLOC_SVELTE)))) $(call add_json_str, Override_rs_driver, $(OVERRIDE_RS_DRIVER)) + $(call add_json_bool, UncompressPrivAppDex, $(call invert_bool,$(filter true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS)))) $(call add_json_list, ModulesLoadedByPrivilegedModules, $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES)) -$(call add_json_bool, DefaultStripDex, $(call invert_bool,$(filter nostripping,$(DEX_PREOPT_DEFAULT)))) -$(call add_json_bool, DisableDexPreopt, $(filter false,$(WITH_DEXPREOPT))) + +$(call add_json_bool, DisableDexPreopt, $(call invert_bool,$(filter true,$(WITH_DEXPREOPT)))) $(call add_json_list, DisableDexPreoptModules, $(DEXPREOPT_DISABLED_MODULES)) +$(call add_json_str, DexPreoptProfileDir, $(PRODUCT_DEX_PREOPT_PROFILE_DIR)) $(call add_json_bool, Product_is_iot, $(filter true,$(PRODUCT_IOT))) @@ -139,6 +141,8 @@ $(call add_json_list, BoardPlatPrivateSepolicyDirs, $(BOARD_PLAT_PRIVATE_SE $(call add_json_bool, FlattenApex, $(filter true,$(TARGET_FLATTEN_APEX))) +$(call add_json_str, DexpreoptGlobalConfig, $(DEX_PREOPT_CONFIG)) + $(call add_json_map, VendorVars) $(foreach namespace,$(SOONG_CONFIG_NAMESPACES),\ $(call add_json_map, $(namespace))\ diff --git a/core/soong_java_prebuilt.mk b/core/soong_java_prebuilt.mk index 1642ba7fb9..7adee8896a 100644 --- a/core/soong_java_prebuilt.mk +++ b/core/soong_java_prebuilt.mk @@ -1,5 +1,7 @@ # Java prebuilt coming from Soong. # Extra inputs: +# LOCAL_SOONG_BUILT_INSTALLED +# LOCAL_SOONG_CLASSES_JAR # LOCAL_SOONG_HEADER_JAR # LOCAL_SOONG_DEX_JAR # LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR @@ -22,8 +24,8 @@ common_javalib.jar := $(intermediates.COMMON)/javalib.jar hiddenapi_flags_csv := $(intermediates.COMMON)/hiddenapi/flags.csv hiddenapi_metadata_csv := $(intermediates.COMMON)/hiddenapi/greylist.csv -$(eval $(call copy-one-file,$(LOCAL_PREBUILT_MODULE_FILE),$(full_classes_jar))) -$(eval $(call copy-one-file,$(LOCAL_PREBUILT_MODULE_FILE),$(full_classes_pre_proguard_jar))) +$(eval $(call copy-one-file,$(LOCAL_SOONG_CLASSES_JAR),$(full_classes_jar))) +$(eval $(call copy-one-file,$(LOCAL_SOONG_CLASSES_JAR),$(full_classes_pre_proguard_jar))) ifdef LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR $(eval $(call copy-one-file,$(LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR),\ @@ -80,37 +82,21 @@ ifdef LOCAL_SOONG_DEX_JAR # java.mk. $(eval $(call hiddenapi-generate-csv,$(full_classes_jar),$(hiddenapi_flags_csv),$(hiddenapi_metadata_csv))) $(eval $(call hiddenapi-copy-soong-jar,$(LOCAL_SOONG_DEX_JAR),$(common_javalib.jar))) + + # For libart, the boot jars' odex files are replaced by $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE). + # We use this installed_odex trick to get boot.art installed. + installed_odex := $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE) + # Append the odex for the 2nd arch if we have one. + installed_odex += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE) + ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex) + # Make sure to install the .odex and .vdex when you run "make " + $(my_all_targets): $(installed_odex) else # !is_boot_jar $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(common_javalib.jar))) endif # is_boot_jar $(eval $(call add-dependency,$(common_javalib.jar),$(full_classes_jar) $(full_classes_header_jar))) - dex_preopt_profile_src_file := $(common_javalib.jar) - - # defines built_odex along with rule to install odex - include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk - - dex_preopt_profile_src_file := - - 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 - $(eval $(call copy-one-file,$(dexpreopted_boot_jar),$(LOCAL_BUILT_MODULE))) - - # 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))% : $(common_javalib.jar) - @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)" - $(call dexpreopt-one-file,$<,$@) - - $(eval $(call dexpreopt-copy-jar,$(common_javalib.jar),$(LOCAL_BUILT_MODULE),$(LOCAL_STRIP_DEX))) - endif # ! boot jar - else # LOCAL_DEX_PREOPT - $(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE))) - endif # LOCAL_DEX_PREOPT + $(eval $(call copy-one-file,$(LOCAL_PREBUILT_MODULE_FILE),$(LOCAL_BUILT_MODULE))) else # LOCAL_IS_HOST_MODULE $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(LOCAL_BUILT_MODULE))) $(eval $(call add-dependency,$(LOCAL_BUILT_MODULE),$(full_classes_jar) $(full_classes_header_jar))) @@ -135,6 +121,13 @@ else # LOCAL_SOONG_DEX_JAR $(eval $(call copy-one-file,$(full_classes_jar),$(LOCAL_BUILT_MODULE))) endif # LOCAL_SOONG_DEX_JAR +my_built_installed := $(foreach f,$(LOCAL_SOONG_BUILT_INSTALLED),\ + $(call word-colon,1,$(f)):$(PRODUCT_OUT)$(call word-colon,2,$(f))) +my_installed := $(call copy-many-files, $(my_built_installed)) +ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed) +ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(my_built_installed) +$(my_register_name): $(my_installed) + ifdef LOCAL_SOONG_AAR ALL_MODULES.$(LOCAL_MODULE).AAR := $(LOCAL_SOONG_AAR) endif