xref: /aosp_15_r20/build/make/core/dex_preopt.mk (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1####################################
2# dexpreopt support - typically used on user builds to run dexopt (for Dalvik) or dex2oat (for ART) ahead of time
3#
4####################################
5
6include $(BUILD_SYSTEM)/dex_preopt_config.mk
7
8# Method returning whether the install path $(1) should be for system_other.
9# Under SANITIZE_LITE, we do not want system_other. Just put things under /data/asan.
10ifeq ($(SANITIZE_LITE),true)
11install-on-system-other =
12else
13install-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)))))
14endif
15
16# Build the boot.zip which contains the boot jars and their compilation output
17# We can do this only if preopt is enabled and if the product uses libart config (which sets the
18# default properties for preopting).
19# At the time of writing, this is only for ART Cloud.
20ifeq ($(WITH_DEXPREOPT), true)
21ifneq ($(WITH_DEXPREOPT_ART_BOOT_IMG_ONLY), true)
22ifeq ($(PRODUCT_USES_DEFAULT_ART_CONFIG), true)
23
24boot_zip := $(PRODUCT_OUT)/boot.zip
25bootclasspath_jars := $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)
26
27# TODO remove system_server_jars usages from boot.zip and depend directly on system_server.zip file.
28
29# Use "/system" path for JARs with "platform:" prefix.
30# These JARs counterintuitively use "platform" prefix but they will
31# be actually installed to /system partition.
32platform_system_server_jars = $(filter platform:%, $(PRODUCT_SYSTEM_SERVER_JARS))
33system_server_jars := \
34  $(foreach m,$(platform_system_server_jars),\
35    $(PRODUCT_OUT)/system/framework/$(call word-colon,2,$(m)).jar)
36
37# For the remaining system server JARs use the partition signified by the prefix.
38# For example, prefix "system_ext:" will use "/system_ext" path.
39other_system_server_jars = $(filter-out $(platform_system_server_jars), $(PRODUCT_SYSTEM_SERVER_JARS))
40system_server_jars += \
41  $(foreach m,$(other_system_server_jars),\
42    $(PRODUCT_OUT)/$(call word-colon,1,$(m))/framework/$(call word-colon,2,$(m)).jar)
43
44# Infix can be 'art' (ART image for testing), 'boot' (primary), or 'mainline' (mainline extension).
45# Soong creates a set of variables for Make, one or each boot image. The only reason why the ART
46# image is exposed to Make is testing (art gtests) and benchmarking (art golem benchmarks). Install
47# rules that use those variables are in dex_preopt_libart.mk. Here for dexpreopt purposes the infix
48# is always 'boot' or 'mainline'.
49DEXPREOPT_INFIX := $(if $(filter true,$(DEX_PREOPT_WITH_UPDATABLE_BCP)),mainline,boot)
50
51# The input variables are written by build/soong/java/dexpreopt_bootjars.go. Examples can be found
52# at the bottom of build/soong/java/dexpreopt_config_testing.go.
53dexpreopt_root_dir := $(dir $(patsubst %/,%,$(dir $(firstword $(bootclasspath_jars)))))
54bootclasspath_arg := $(subst $(space),:,$(patsubst $(dexpreopt_root_dir)%,%,$(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)))
55bootclasspath_locations_arg := $(subst $(space),:,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS))
56boot_images := $(subst :,$(space),$(DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE$(DEXPREOPT_INFIX)))
57boot_image_arg := $(subst $(space),:,$(patsubst /%,%,$(boot_images)))
58uffd_gc_flag_txt := $(OUT_DIR)/soong/dexpreopt/uffd_gc_flag.txt
59
60boot_zip_metadata_txt := $(dir $(boot_zip))boot_zip/METADATA.txt
61$(boot_zip_metadata_txt): $(uffd_gc_flag_txt)
62$(boot_zip_metadata_txt):
63	rm -f $@
64	echo "bootclasspath = $(bootclasspath_arg)" >> $@
65	echo "bootclasspath-locations = $(bootclasspath_locations_arg)" >> $@
66	echo "boot-image = $(boot_image_arg)" >> $@
67	echo "extra-args = `cat $(uffd_gc_flag_txt)`" >> $@
68
69$(call dist-for-goals, droidcore, $(boot_zip_metadata_txt))
70
71$(boot_zip): PRIVATE_BOOTCLASSPATH_JARS := $(bootclasspath_jars)
72$(boot_zip): PRIVATE_SYSTEM_SERVER_JARS := $(system_server_jars)
73$(boot_zip): $(bootclasspath_jars) $(system_server_jars) $(SOONG_ZIP) $(MERGE_ZIPS) $(DEXPREOPT_IMAGE_ZIP_boot) $(DEXPREOPT_IMAGE_ZIP_art) $(DEXPREOPT_IMAGE_ZIP_mainline) $(boot_zip_metadata_txt)
74	@echo "Create boot package: $@"
75	rm -f $@
76	$(SOONG_ZIP) -o $@.tmp \
77	  -C $(dir $(firstword $(PRIVATE_BOOTCLASSPATH_JARS)))/.. $(addprefix -f ,$(PRIVATE_BOOTCLASSPATH_JARS)) \
78	  -C $(PRODUCT_OUT) $(addprefix -f ,$(PRIVATE_SYSTEM_SERVER_JARS)) \
79	  -j -f $(boot_zip_metadata_txt)
80	$(MERGE_ZIPS) $@ $@.tmp $(DEXPREOPT_IMAGE_ZIP_boot) $(DEXPREOPT_IMAGE_ZIP_art) $(DEXPREOPT_IMAGE_ZIP_mainline)
81	rm -f $@.tmp
82
83$(call dist-for-goals, droidcore, $(boot_zip))
84
85# Build the system_server.zip which contains the Apex system server jars and standalone system server jars
86system_server_dex2oat_dir := $(SOONG_OUT_DIR)/system_server_dexjars
87system_server_zip := $(PRODUCT_OUT)/system_server.zip
88# non_updatable_system_server_jars contains jars in /system and /system_ext that are not part of an apex.
89non_updatable_system_server_jars := \
90  $(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),\
91    $(system_server_dex2oat_dir)/$(call word-colon,2,$(m)).jar)
92
93apex_system_server_jars := \
94  $(foreach m,$(PRODUCT_APEX_SYSTEM_SERVER_JARS),\
95    $(system_server_dex2oat_dir)/$(call word-colon,2,$(m)).jar)
96
97apex_standalone_system_server_jars := \
98  $(foreach m,$(PRODUCT_APEX_STANDALONE_SYSTEM_SERVER_JARS),\
99    $(system_server_dex2oat_dir)/$(call word-colon,2,$(m)).jar)
100
101standalone_system_server_jars := \
102  $(foreach m,$(PRODUCT_STANDALONE_SYSTEM_SERVER_JARS),\
103    $(system_server_dex2oat_dir)/$(call word-colon,2,$(m)).jar)
104
105$(system_server_zip): PRIVATE_SYSTEM_SERVER_DEX2OAT_DIR := $(system_server_dex2oat_dir)
106$(system_server_zip): PRIVATE_SYSTEM_SERVER_JARS := $(non_updatable_system_server_jars)
107$(system_server_zip): PRIVATE_APEX_SYSTEM_SERVER_JARS := $(apex_system_server_jars)
108$(system_server_zip): PRIVATE_APEX_STANDALONE_SYSTEM_SERVER_JARS := $(apex_standalone_system_server_jars)
109$(system_server_zip): PRIVATE_STANDALONE_SYSTEM_SERVER_JARS := $(standalone_system_server_jars)
110$(system_server_zip): $(system_server_jars) $(apex_system_server_jars) $(apex_standalone_system_server_jars) $(standalone_system_server_jars) $(SOONG_ZIP)
111	@echo "Create system server package: $@"
112	rm -f $@
113	$(SOONG_ZIP) -o $@ \
114	  -C $(PRIVATE_SYSTEM_SERVER_DEX2OAT_DIR) $(addprefix -f ,$(PRIVATE_SYSTEM_SERVER_JARS)) \
115	  -C $(PRIVATE_SYSTEM_SERVER_DEX2OAT_DIR) $(addprefix -f ,$(PRIVATE_APEX_SYSTEM_SERVER_JARS)) \
116	  -C $(PRIVATE_SYSTEM_SERVER_DEX2OAT_DIR) $(addprefix -f ,$(PRIVATE_APEX_STANDALONE_SYSTEM_SERVER_JARS)) \
117	  -C $(PRIVATE_SYSTEM_SERVER_DEX2OAT_DIR) $(addprefix -f ,$(PRIVATE_STANDALONE_SYSTEM_SERVER_JARS))
118
119$(call dist-for-goals, droidcore, $(system_server_zip))
120
121endif  #PRODUCT_USES_DEFAULT_ART_CONFIG
122endif  #WITH_DEXPREOPT_ART_BOOT_IMG_ONLY
123endif  #WITH_DEXPREOPT
124