blob: 235f4bc4f1ed9fc4aa19b1b6a705bf582cf6fcfd [file] [log] [blame]
Brian Carlstromced4bff2013-11-14 23:44:56 -08001# dexpreopt_odex_install.mk is used to define odex creation rules for JARs and APKs
2# This file depends on variables set in base_rules.mk
3# Output variables: LOCAL_DEX_PREOPT, built_odex, dexpreopt_boot_jar_module
4
5# Setting LOCAL_DEX_PREOPT based on WITH_DEXPREOPT, LOCAL_DEX_PREOPT, etc
6LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT))
7ifneq (true,$(WITH_DEXPREOPT))
8 LOCAL_DEX_PREOPT :=
9else # WITH_DEXPREOPT=true
10 ifeq (,$(TARGET_BUILD_APPS)) # TARGET_BUILD_APPS empty
Ying Wang9db168c2014-01-03 16:24:56 -080011 ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined
Ying Wangedfd55a2014-07-09 10:57:32 -070012 ifneq ($(filter $(TARGET_OUT)/%,$(my_module_path)),) # Installed to system.img.
13 ifeq (,$(LOCAL_APK_LIBRARIES)) # LOCAL_APK_LIBRARIES empty
Ying Wang20ebd2e2014-10-07 18:07:23 -070014 # If we have product-specific config for this module?
15 ifeq (disable,$(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG))
16 LOCAL_DEX_PREOPT := false
17 else
18 LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT)
19 endif
Ying Wangedfd55a2014-07-09 10:57:32 -070020 else # LOCAL_APK_LIBRARIES not empty
21 LOCAL_DEX_PREOPT := nostripping
22 endif # LOCAL_APK_LIBRARIES not empty
23 endif # Installed to system.img.
Ying Wang9db168c2014-01-03 16:24:56 -080024 endif # LOCAL_DEX_PREOPT undefined
Brian Carlstromced4bff2013-11-14 23:44:56 -080025 endif # TARGET_BUILD_APPS empty
26endif # WITH_DEXPREOPT=true
27ifeq (false,$(LOCAL_DEX_PREOPT))
28 LOCAL_DEX_PREOPT :=
29endif
30ifdef LOCAL_UNINSTALLABLE_MODULE
31LOCAL_DEX_PREOPT :=
32endif
Ying Wang62fb8a12014-10-08 14:48:07 -070033ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file))) # contains no java code
Brian Carlstromced4bff2013-11-14 23:44:56 -080034LOCAL_DEX_PREOPT :=
35endif
Mathieu Chartier418258c2017-08-28 14:19:35 -070036# if WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true and module is not in boot class path skip
37# Also preopt system server jars since selinux prevents system server from loading anything from
38# /data. If we don't do this they will need to be extracted which is not favorable for RAM usage
Mathieu Chartier0fbb8362017-09-15 13:40:48 -070039# or performance. If my_preopt_for_extracted_apk is true, we ignore the only preopt boot image
40# options.
41ifneq (true,$(my_preopt_for_extracted_apk))
Mathieu Chartier418258c2017-08-28 14:19:35 -070042ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))
43ifeq ($(filter $(PRODUCT_SYSTEM_SERVER_JARS) $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),)
Alex Light7326f7b2014-08-04 17:09:41 -070044LOCAL_DEX_PREOPT :=
45endif
46endif
Mathieu Chartier0fbb8362017-09-15 13:40:48 -070047endif
48
Alex Light4e358ab2016-06-16 14:47:10 -070049# if installing into system, and odex are being installed into system_other, don't strip
50ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
51ifeq ($(LOCAL_DEX_PREOPT),true)
Nicolas Geoffraycdd43432017-03-24 14:45:59 +000052ifneq ($(call install-on-system-other, $(my_module_path)),)
Alex Light4e358ab2016-06-16 14:47:10 -070053LOCAL_DEX_PREOPT := nostripping
54endif
55endif
56endif
Brian Carlstromced4bff2013-11-14 23:44:56 -080057
58built_odex :=
David Brazdil70470162016-08-25 13:50:15 +010059built_vdex :=
Mathieu Chartier192b91c2017-02-08 18:30:31 -080060built_art :=
Brian Carlstromced4bff2013-11-14 23:44:56 -080061installed_odex :=
David Brazdil70470162016-08-25 13:50:15 +010062installed_vdex :=
Mathieu Chartier192b91c2017-02-08 18:30:31 -080063installed_art :=
Ying Wang74c98502014-05-19 13:03:36 -070064built_installed_odex :=
David Brazdil70470162016-08-25 13:50:15 +010065built_installed_vdex :=
Mathieu Chartier192b91c2017-02-08 18:30:31 -080066built_installed_art :=
67
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070068ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE))
69LOCAL_DEX_PREOPT_GENERATE_PROFILE := false
70endif
71
72ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE
73# If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the
74# profile class listing. TODO: Use product specific directory here.
75my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR)
76LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(my_classes_directory)/$(LOCAL_MODULE).prof.txt
77ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)))
78# Profile listing exists, use it to generate the profile.
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070079LOCAL_DEX_PREOPT_GENERATE_PROFILE := true
80endif
81endif
Mathieu Chartier48762292017-09-13 22:08:45 -070082
83ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
84
85ifdef LOCAL_VENDOR_MODULE
86$(call pretty-error, Internal error: profiles are not supported for vendor modules)
87else
88LOCAL_DEX_PREOPT_APP_IMAGE := true
Mathieu Chartier44c9c072017-05-09 19:17:33 -070089endif
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070090
Mathieu Chartier48762292017-09-13 22:08:45 -070091ifndef LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING
92$(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING))
93endif
94ifeq (,$(dex_preopt_profile_src_file))
95$(call pretty-error, Internal error: dex_preopt_profile_src_file must be set)
96endif
97my_built_profile := $(dir $(LOCAL_BUILT_MODULE))/profile.prof
98my_dex_location := $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))
99# Remove compressed APK extension.
100my_dex_location := $(patsubst %.gz,%,$(my_dex_location))
101$(my_built_profile): PRIVATE_BUILT_MODULE := $(dex_preopt_profile_src_file)
102$(my_built_profile): PRIVATE_DEX_LOCATION := $(my_dex_location)
103$(my_built_profile): PRIVATE_SOURCE_CLASSES := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
104$(my_built_profile): $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
105$(my_built_profile): $(PROFMAN)
106$(my_built_profile): $(dex_preopt_profile_src_file)
107$(my_built_profile):
108 $(hide) mkdir -p $(dir $@)
109 ANDROID_LOG_TAGS="*:e" $(PROFMAN) \
110 --create-profile-from=$(PRIVATE_SOURCE_CLASSES) \
111 --apk=$(PRIVATE_BUILT_MODULE) \
112 --dex-location=$(PRIVATE_DEX_LOCATION) \
113 --reference-profile-file=$@
114dex_preopt_profile_src_file:=
115# Remove compressed APK extension.
116my_installed_profile := $(patsubst %.gz,%,$(LOCAL_INSTALLED_MODULE)).prof
117# my_installed_profile := $(LOCAL_INSTALLED_MODULE).prof
118$(eval $(call copy-one-file,$(my_built_profile),$(my_installed_profile)))
119build_installed_profile:=$(my_built_profile):$(my_installed_profile)
120else
121build_installed_profile:=
122my_installed_profile :=
123endif
124
125ifdef LOCAL_DEX_PREOPT
126
Brian Carlstromced4bff2013-11-14 23:44:56 -0800127dexpreopt_boot_jar_module := $(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE))
128ifdef dexpreopt_boot_jar_module
Brian Carlstromced4bff2013-11-14 23:44:56 -0800129# For libart, the boot jars' odex files are replaced by $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE).
130# We use this installed_odex trick to get boot.art installed.
131installed_odex := $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE)
Ying Wangb9aa5d42014-05-13 13:57:28 -0700132# Append the odex for the 2nd arch if we have one.
133installed_odex += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800134else # boot jar
Ying Wangb9aa5d42014-05-13 13:57:28 -0700135ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
Ying Wangc7ca6172015-03-09 17:17:51 -0700136# For a Java library, by default we build odex for both 1st arch and 2nd arch.
137# But it can be overridden with "LOCAL_MULTILIB := first".
138ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
139# For system server jars, we build for only "first".
140my_module_multilib := first
141else
142my_module_multilib := $(LOCAL_MULTILIB)
143endif
Ying Wangb9aa5d42014-05-13 13:57:28 -0700144# #################################################
145# Odex for the 1st arch
Ying Wangdb48da72014-09-13 11:26:39 -0700146my_2nd_arch_prefix :=
147include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wangb9aa5d42014-05-13 13:57:28 -0700148# #################################################
149# Odex for the 2nd arch
150ifdef TARGET_2ND_ARCH
Ying Wang62630222016-04-20 11:53:39 -0700151ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
Ying Wangc7ca6172015-03-09 17:17:51 -0700152ifneq (first,$(my_module_multilib))
Ying Wangdb48da72014-09-13 11:26:39 -0700153my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
154include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wangc7ca6172015-03-09 17:17:51 -0700155endif # my_module_multilib is not first.
Ying Wang62630222016-04-20 11:53:39 -0700156endif # TARGET_TRANSLATE_2ND_ARCH not true
Ying Wangb9aa5d42014-05-13 13:57:28 -0700157endif # TARGET_2ND_ARCH
158# #################################################
159else # must be APPS
Ying Wangdb48da72014-09-13 11:26:39 -0700160# The preferred arch
161my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
162include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wang7a899192014-09-15 11:45:52 -0700163ifdef TARGET_2ND_ARCH
Ying Wangdb48da72014-09-13 11:26:39 -0700164ifeq ($(LOCAL_MULTILIB),both)
165# The non-preferred arch
166my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX))
167include $(BUILD_SYSTEM)/setup_one_odex.mk
168endif # LOCAL_MULTILIB is both
Ying Wang7a899192014-09-15 11:45:52 -0700169endif # TARGET_2ND_ARCH
Ying Wangb9aa5d42014-05-13 13:57:28 -0700170endif # LOCAL_MODULE_CLASS
Ying Wang7a899192014-09-15 11:45:52 -0700171endif # boot jar
Brian Carlstromced4bff2013-11-14 23:44:56 -0800172
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800173built_odex := $(strip $(built_odex))
David Brazdil70470162016-08-25 13:50:15 +0100174built_vdex := $(strip $(built_vdex))
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800175built_art := $(strip $(built_art))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800176installed_odex := $(strip $(installed_odex))
David Brazdil70470162016-08-25 13:50:15 +0100177installed_vdex := $(strip $(installed_vdex))
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800178installed_art := $(strip $(installed_art))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800179
Brian Carlstromced4bff2013-11-14 23:44:56 -0800180ifdef built_odex
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800181ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800182$(built_odex): $(my_built_profile)
183$(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := --profile-file=$(my_built_profile)
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800184else
185$(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS :=
186endif
187
Ying Wang20ebd2e2014-10-07 18:07:23 -0700188ifndef LOCAL_DEX_PREOPT_FLAGS
189LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG)
190ifndef LOCAL_DEX_PREOPT_FLAGS
191LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS)
192endif
193endif
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000194
Mathieu Chartier6a902102017-06-23 10:44:45 -0700195my_system_server_compiler_filter := $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)
196ifeq (,$(my_system_server_compiler_filter))
197my_system_server_compiler_filter := speed
198endif
199
Mathieu Chartierb8d3cc02017-06-16 11:17:53 -0700200ifeq (,$(filter --compiler-filter=%, $(LOCAL_DEX_PREOPT_FLAGS)))
Mathieu Chartier6a902102017-06-23 10:44:45 -0700201 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
202 # Jars of system server, use the product option if it is set, speed otherwise.
203 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=$(my_system_server_compiler_filter)
Mathieu Chartierb8d3cc02017-06-16 11:17:53 -0700204 else
Mathieu Chartier6a902102017-06-23 10:44:45 -0700205 ifneq (,$(filter $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(LOCAL_MODULE)))
206 # Apps loaded into system server, and apps the product default to being compiled with the
207 # 'speed' compiler filter.
208 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed
Mathieu Chartierc5536ff2017-05-05 14:59:06 -0700209 else
Mathieu Chartier6a902102017-06-23 10:44:45 -0700210 ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
211 # For non system server jars, use speed-profile when we have a profile.
212 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed-profile
213 else
214 # If no compiler filter is specified, default to 'quicken' to save on storage.
215 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=quicken
216 endif
Mathieu Chartierc5536ff2017-05-05 14:59:06 -0700217 endif
Nicolas Geoffray24f54692017-03-30 13:50:12 +0100218 endif
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000219endif
220
Mathieu Chartier94f5f932017-06-23 14:47:56 -0700221# PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
222my_system_server_debug_info := $(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)
223ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
224# Only enable for non-eng builds.
225ifeq (,$(my_system_server_debug_info))
226my_system_server_debug_info := true
227endif
228endif
229
230ifeq (true, $(my_system_server_debug_info))
231 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
232 LOCAL_DEX_PREOPT_FLAGS += --generate-mini-debug-info
233 endif
234endif
235
Ying Wang20ebd2e2014-10-07 18:07:23 -0700236$(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
David Brazdil70470162016-08-25 13:50:15 +0100237$(built_vdex): $(built_odex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800238$(built_art): $(built_odex)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800239endif
240
241# Add the installed_odex to the list of installed files for this module.
Ying Wang74c98502014-05-19 13:03:36 -0700242ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex)
David Brazdil70470162016-08-25 13:50:15 +0100243ALL_MODULES.$(my_register_name).INSTALLED += $(installed_vdex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800244ALL_MODULES.$(my_register_name).INSTALLED += $(installed_art)
Mathieu Chartier48762292017-09-13 22:08:45 -0700245
Ying Wang74c98502014-05-19 13:03:36 -0700246ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex)
David Brazdil70470162016-08-25 13:50:15 +0100247ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_vdex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800248ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_art)
Ying Wang74c98502014-05-19 13:03:36 -0700249
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800250# Record dex-preopt config.
251DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT)
252DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB)
253DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
254DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE)
Dan Willemsen05a2b932017-03-20 18:31:17 -0700255DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE)
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800256DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH)
257DEXPREOPT.$(LOCAL_MODULE).INSTALLED := $(installed_odex)
258DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE)
259DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \
260 $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE))
261
262
David Brazdil70470162016-08-25 13:50:15 +0100263# Make sure to install the .odex and .vdex when you run "make <module_name>"
Mathieu Chartier48762292017-09-13 22:08:45 -0700264$(my_all_targets): $(installed_odex) $(installed_vdex) $(installed_art)
Ying Wang5c7fed22014-01-22 16:50:21 -0800265
Brian Carlstromced4bff2013-11-14 23:44:56 -0800266endif # LOCAL_DEX_PREOPT
Mathieu Chartier48762292017-09-13 22:08:45 -0700267
268# Profile doesn't depend on LOCAL_DEX_PREOPT.
269ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_profile)
270ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(build_installed_profile)
271
272$(my_all_targets): $(my_installed_profile)