dex_preopt.mk revision 7effde0048bcce6084e00bf29ff3bea4f34d1599
1####################################
2# dexpreopt support - typically used on user builds to run dexopt (for Dalvik) or dex2oat (for ART) ahead of time
3#
4####################################
5
6# list of boot classpath jars for dexpreopt
7DEXPREOPT_BOOT_JARS := $(subst $(space),:,$(PRODUCT_BOOT_JARS))
8DEXPREOPT_BOOT_JARS_MODULES := $(PRODUCT_BOOT_JARS)
9PRODUCT_BOOTCLASSPATH := $(subst $(space),:,$(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),/system/framework/$(m).jar))
10
11PRODUCT_SYSTEM_SERVER_CLASSPATH := $(subst $(space),:,$(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),/system/framework/$(m).jar))
12
13DEXPREOPT_BUILD_DIR := $(OUT_DIR)
14DEXPREOPT_PRODUCT_DIR_FULL_PATH := $(PRODUCT_OUT)/dex_bootjars
15DEXPREOPT_PRODUCT_DIR := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXPREOPT_PRODUCT_DIR_FULL_PATH))
16DEXPREOPT_BOOT_JAR_DIR := system/framework
17DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREOPT_BOOT_JAR_DIR)
18
19# The default value for LOCAL_DEX_PREOPT
20DEX_PREOPT_DEFAULT ?= true
21
22# The default values for pre-opting: always preopt PIC.
23# Conditional to building on linux, as dex2oat currently does not work on darwin.
24# Conditional to building a non-eng build, as it currently negatively affects
25# some development workflows.
26ifneq ($(TARGET_BUILD_VARIANT),eng)
27  ifeq ($(HOST_OS),linux)
28    WITH_DEXPREOPT_PIC ?= true
29    WITH_DEXPREOPT ?= true
30  endif
31endif
32
33# $(1): the .jar or .apk to remove classes.dex
34define dexpreopt-remove-classes.dex
35$(hide) zip --quiet --delete $(1) classes.dex; \
36dex_index=2; \
37while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \
38  let dex_index=dex_index+1; \
39done
40endef
41
42# Special rules for building stripped boot jars that override java_library.mk rules
43
44# $(1): boot jar module name
45define _dexpreopt-boot-jar-remove-classes.dex
46_dbj_jar_no_dex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1)_nodex.jar
47_dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar
48
49$$(_dbj_jar_no_dex) : $$(_dbj_src_jar) | $(ACP)
50	$$(call copy-file-to-target)
51ifneq ($(DEX_PREOPT_DEFAULT),nostripping)
52	$$(call dexpreopt-remove-classes.dex,$$@)
53endif
54
55_dbj_jar_no_dex :=
56_dbj_src_jar :=
57endef
58
59$(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),$(eval $(call _dexpreopt-boot-jar-remove-classes.dex,$(b))))
60
61include $(BUILD_SYSTEM)/dex_preopt_libart.mk
62
63# Define dexpreopt-one-file based on current default runtime.
64# $(1): the input .jar or .apk file
65# $(2): the output .odex file
66define dexpreopt-one-file
67$(call dex2oat-one-file,$(1),$(2))
68endef
69
70DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS := $(DEX2OAT_DEPENDENCY)
71DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
72ifdef TARGET_2ND_ARCH
73$(TARGET_2ND_ARCH_VAR_PREFIX)DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
74endif  # TARGET_2ND_ARCH
75