Home | History | Annotate | Download | only in core
      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
      7 DEXPREOPT_BOOT_JARS := $(subst $(space),:,$(PRODUCT_BOOT_JARS))
      8 DEXPREOPT_BOOT_JARS_MODULES := $(PRODUCT_BOOT_JARS)
      9 PRODUCT_BOOTCLASSPATH := $(subst $(space),:,$(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),/system/framework/$(m).jar))
     10 
     11 PRODUCT_SYSTEM_SERVER_CLASSPATH := $(subst $(space),:,$(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),/system/framework/$(m).jar))
     12 
     13 DEXPREOPT_BUILD_DIR := $(OUT_DIR)
     14 DEXPREOPT_PRODUCT_DIR_FULL_PATH := $(PRODUCT_OUT)/dex_bootjars
     15 DEXPREOPT_PRODUCT_DIR := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXPREOPT_PRODUCT_DIR_FULL_PATH))
     16 DEXPREOPT_BOOT_JAR_DIR := system/framework
     17 DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREOPT_BOOT_JAR_DIR)
     18 
     19 # The default value for LOCAL_DEX_PREOPT
     20 DEX_PREOPT_DEFAULT ?= true
     21 
     22 # The default filter for which files go into the system_other image (if it is
     23 # being used). To bundle everything one should set this to '%'
     24 SYSTEM_OTHER_ODEX_FILTER ?= app/% priv-app/%
     25 
     26 # Method returning whether the install path $(1) should be for system_other.
     27 # Under SANITIZE_LITE, we do not want system_other. Just put things under /data/asan.
     28 ifeq ($(SANITIZE_LITE),true)
     29 install-on-system-other =
     30 else
     31 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)))))
     32 endif
     33 
     34 # The default values for pre-opting: always preopt PIC.
     35 # Conditional to building on linux, as dex2oat currently does not work on darwin.
     36 ifeq ($(HOST_OS),linux)
     37   WITH_DEXPREOPT ?= true
     38   ifeq (eng,$(TARGET_BUILD_VARIANT))
     39     # Don't strip for quick development turnarounds.
     40     DEX_PREOPT_DEFAULT := nostripping
     41     # For an eng build only pre-opt the boot image and system server. This gives reasonable performance
     42     # and still allows a simple workflow: building in frameworks/base and syncing.
     43     WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true
     44   endif
     45   # Add mini-debug-info to the boot classpath unless explicitly asked not to.
     46   ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO))
     47     PRODUCT_DEX_PREOPT_BOOT_FLAGS += --generate-mini-debug-info
     48   endif
     49 
     50   # Non eng linux builds must have preopt enabled so that system server doesn't run as interpreter
     51   # only. b/74209329
     52   ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
     53     ifneq (true,$(WITH_DEXPREOPT))
     54       ifneq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))
     55         $(call pretty-error, DEXPREOPT must be enabled for user and userdebug builds)
     56       endif
     57     endif
     58   endif
     59 endif
     60 
     61 GLOBAL_DEXPREOPT_FLAGS :=
     62 
     63 # Special rules for building stripped boot jars that override java_library.mk rules
     64 
     65 # $(1): boot jar module name
     66 define _dexpreopt-boot-jar-remove-classes.dex
     67 _dbj_jar_no_dex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1)_nodex.jar
     68 _dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar
     69 
     70 $(call dexpreopt-copy-jar,$$(_dbj_src_jar),$$(_dbj_jar_no_dex),$(DEX_PREOPT_DEFAULT))
     71 
     72 _dbj_jar_no_dex :=
     73 _dbj_src_jar :=
     74 endef
     75 
     76 $(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),$(eval $(call _dexpreopt-boot-jar-remove-classes.dex,$(b))))
     77 
     78 include $(BUILD_SYSTEM)/dex_preopt_libart.mk
     79 
     80 # Define dexpreopt-one-file based on current default runtime.
     81 # $(1): the input .jar or .apk file
     82 # $(2): the output .odex file
     83 define dexpreopt-one-file
     84 $(call dex2oat-one-file,$(1),$(2))
     85 endef
     86 
     87 DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS := $(DEX2OAT_DEPENDENCY)
     88 DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
     89 ifdef TARGET_2ND_ARCH
     90 $(TARGET_2ND_ARCH_VAR_PREFIX)DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME)
     91 endif  # TARGET_2ND_ARCH
     92 
     93 ifeq ($(PRODUCT_DIST_BOOT_AND_SYSTEM_JARS),true)
     94 boot_profile_jars_zip := $(PRODUCT_OUT)/boot_profile_jars.zip
     95 all_boot_jars := \
     96   $(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),$(PRODUCT_OUT)/system/framework/$(m).jar) \
     97   $(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),$(PRODUCT_OUT)/system/framework/$(m).jar)
     98 
     99 $(boot_profile_jars_zip): PRIVATE_JARS := $(all_boot_jars)
    100 $(boot_profile_jars_zip): $(all_boot_jars) $(SOONG_ZIP)
    101 	echo "Create boot profiles package: $@"
    102 	rm -f $@
    103 	$(SOONG_ZIP) -o $@ -C $(PRODUCT_OUT) $(PRIVATE_JARS)
    104 
    105 droidcore: $(boot_profile_jars_zip)
    106 
    107 $(call dist-for-goals, droidcore, $(boot_profile_jars_zip))
    108 endif
    109