blob: e3372799ef3d7ae548faac2413e17629c0f1fe1b [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
Nicolas Geoffray3972a472018-01-09 11:46:30 +00003# Output variables: LOCAL_DEX_PREOPT, LOCAL_UNCOMPRESS_DEX, built_odex,
4# dexpreopt_boot_jar_module
5
6# We explicitly uncompress APKs of privileged apps, and used by
7# privileged apps
8LOCAL_UNCOMPRESS_DEX := false
9ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS))
10ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
11 LOCAL_UNCOMPRESS_DEX := true
12else
13 ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
14 LOCAL_UNCOMPRESS_DEX := true
15 endif # PRODUCT_LOADED_BY_PRIVILEGED_MODULES
16endif # LOCAL_PRIVILEGED_MODULE
17endif # DONT_UNCOMPRESS_PRIV_APPS_DEXS
Brian Carlstromced4bff2013-11-14 23:44:56 -080018
19# Setting LOCAL_DEX_PREOPT based on WITH_DEXPREOPT, LOCAL_DEX_PREOPT, etc
20LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT))
21ifneq (true,$(WITH_DEXPREOPT))
22 LOCAL_DEX_PREOPT :=
23else # WITH_DEXPREOPT=true
24 ifeq (,$(TARGET_BUILD_APPS)) # TARGET_BUILD_APPS empty
Ying Wang9db168c2014-01-03 16:24:56 -080025 ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined
Ying Wangedfd55a2014-07-09 10:57:32 -070026 ifneq ($(filter $(TARGET_OUT)/%,$(my_module_path)),) # Installed to system.img.
27 ifeq (,$(LOCAL_APK_LIBRARIES)) # LOCAL_APK_LIBRARIES empty
Ying Wang20ebd2e2014-10-07 18:07:23 -070028 # If we have product-specific config for this module?
29 ifeq (disable,$(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG))
30 LOCAL_DEX_PREOPT := false
31 else
32 LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT)
33 endif
Ying Wangedfd55a2014-07-09 10:57:32 -070034 else # LOCAL_APK_LIBRARIES not empty
35 LOCAL_DEX_PREOPT := nostripping
36 endif # LOCAL_APK_LIBRARIES not empty
37 endif # Installed to system.img.
Ying Wang9db168c2014-01-03 16:24:56 -080038 endif # LOCAL_DEX_PREOPT undefined
Brian Carlstromced4bff2013-11-14 23:44:56 -080039 endif # TARGET_BUILD_APPS empty
40endif # WITH_DEXPREOPT=true
41ifeq (false,$(LOCAL_DEX_PREOPT))
42 LOCAL_DEX_PREOPT :=
43endif
44ifdef LOCAL_UNINSTALLABLE_MODULE
45LOCAL_DEX_PREOPT :=
46endif
Colin Crossf229de42017-10-05 16:01:00 -070047ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file)$(LOCAL_SOONG_DEX_JAR))) # contains no java code
Brian Carlstromced4bff2013-11-14 23:44:56 -080048LOCAL_DEX_PREOPT :=
49endif
Mathieu Chartier418258c2017-08-28 14:19:35 -070050# if WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true and module is not in boot class path skip
51# Also preopt system server jars since selinux prevents system server from loading anything from
52# /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 -070053# or performance. If my_preopt_for_extracted_apk is true, we ignore the only preopt boot image
54# options.
55ifneq (true,$(my_preopt_for_extracted_apk))
Mathieu Chartier418258c2017-08-28 14:19:35 -070056ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))
57ifeq ($(filter $(PRODUCT_SYSTEM_SERVER_JARS) $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),)
Alex Light7326f7b2014-08-04 17:09:41 -070058LOCAL_DEX_PREOPT :=
59endif
60endif
Mathieu Chartier0fbb8362017-09-15 13:40:48 -070061endif
62
Alex Light4e358ab2016-06-16 14:47:10 -070063ifeq ($(LOCAL_DEX_PREOPT),true)
Nicolas Geoffray3972a472018-01-09 11:46:30 +000064
65# Don't strip with dexes we explicitly uncompress (dexopt will not store the dex code).
66ifeq ($(LOCAL_UNCOMPRESS_DEX),true)
67LOCAL_DEX_PREOPT := nostripping
68endif # LOCAL_UNCOMPRESS_DEX
69
70# system_other isn't there for an OTA, so don't strip
71# if module is on system, and odex is on system_other.
72ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
Nicolas Geoffraycdd43432017-03-24 14:45:59 +000073ifneq ($(call install-on-system-other, $(my_module_path)),)
Alex Light4e358ab2016-06-16 14:47:10 -070074LOCAL_DEX_PREOPT := nostripping
Nicolas Geoffray3972a472018-01-09 11:46:30 +000075endif # install-on-system-other
76endif # BOARD_USES_SYSTEM_OTHER_ODEX
77
78# We also don't strip if all dexs are uncompressed (dexopt will not store the dex code),
79# but that requires to inspect the source file, which is too early at this point (as we
80# don't know if the source file will actually be used).
81# See dexpreopt-remove-classes.dex.
82
83endif # LOCAL_DEX_PREOPT
Brian Carlstromced4bff2013-11-14 23:44:56 -080084
85built_odex :=
David Brazdil70470162016-08-25 13:50:15 +010086built_vdex :=
Mathieu Chartier192b91c2017-02-08 18:30:31 -080087built_art :=
Brian Carlstromced4bff2013-11-14 23:44:56 -080088installed_odex :=
David Brazdil70470162016-08-25 13:50:15 +010089installed_vdex :=
Mathieu Chartier192b91c2017-02-08 18:30:31 -080090installed_art :=
Ying Wang74c98502014-05-19 13:03:36 -070091built_installed_odex :=
David Brazdil70470162016-08-25 13:50:15 +010092built_installed_vdex :=
Mathieu Chartier192b91c2017-02-08 18:30:31 -080093built_installed_art :=
94
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070095ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE))
96LOCAL_DEX_PREOPT_GENERATE_PROFILE := false
97endif
98
99ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE
100# If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the
101# profile class listing. TODO: Use product specific directory here.
102my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR)
103LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(my_classes_directory)/$(LOCAL_MODULE).prof.txt
104ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)))
105# Profile listing exists, use it to generate the profile.
Mathieu Chartier6324c2d2017-05-05 17:22:37 -0700106LOCAL_DEX_PREOPT_GENERATE_PROFILE := true
107endif
108endif
Mathieu Chartier48762292017-09-13 22:08:45 -0700109
110ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
111
112ifdef LOCAL_VENDOR_MODULE
113$(call pretty-error, Internal error: profiles are not supported for vendor modules)
114else
115LOCAL_DEX_PREOPT_APP_IMAGE := true
Mathieu Chartier44c9c072017-05-09 19:17:33 -0700116endif
Mathieu Chartier6324c2d2017-05-05 17:22:37 -0700117
Mathieu Chartier48762292017-09-13 22:08:45 -0700118ifndef LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING
119$(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING))
120endif
121ifeq (,$(dex_preopt_profile_src_file))
122$(call pretty-error, Internal error: dex_preopt_profile_src_file must be set)
123endif
124my_built_profile := $(dir $(LOCAL_BUILT_MODULE))/profile.prof
125my_dex_location := $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))
126# Remove compressed APK extension.
127my_dex_location := $(patsubst %.gz,%,$(my_dex_location))
128$(my_built_profile): PRIVATE_BUILT_MODULE := $(dex_preopt_profile_src_file)
129$(my_built_profile): PRIVATE_DEX_LOCATION := $(my_dex_location)
130$(my_built_profile): PRIVATE_SOURCE_CLASSES := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
131$(my_built_profile): $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
132$(my_built_profile): $(PROFMAN)
133$(my_built_profile): $(dex_preopt_profile_src_file)
134$(my_built_profile):
135 $(hide) mkdir -p $(dir $@)
136 ANDROID_LOG_TAGS="*:e" $(PROFMAN) \
137 --create-profile-from=$(PRIVATE_SOURCE_CLASSES) \
138 --apk=$(PRIVATE_BUILT_MODULE) \
139 --dex-location=$(PRIVATE_DEX_LOCATION) \
140 --reference-profile-file=$@
141dex_preopt_profile_src_file:=
142# Remove compressed APK extension.
143my_installed_profile := $(patsubst %.gz,%,$(LOCAL_INSTALLED_MODULE)).prof
144# my_installed_profile := $(LOCAL_INSTALLED_MODULE).prof
145$(eval $(call copy-one-file,$(my_built_profile),$(my_installed_profile)))
146build_installed_profile:=$(my_built_profile):$(my_installed_profile)
147else
148build_installed_profile:=
149my_installed_profile :=
150endif
151
152ifdef LOCAL_DEX_PREOPT
153
Brian Carlstromced4bff2013-11-14 23:44:56 -0800154dexpreopt_boot_jar_module := $(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE))
155ifdef dexpreopt_boot_jar_module
Brian Carlstromced4bff2013-11-14 23:44:56 -0800156# For libart, the boot jars' odex files are replaced by $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE).
157# We use this installed_odex trick to get boot.art installed.
158installed_odex := $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE)
Ying Wangb9aa5d42014-05-13 13:57:28 -0700159# Append the odex for the 2nd arch if we have one.
160installed_odex += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800161else # boot jar
Ying Wangb9aa5d42014-05-13 13:57:28 -0700162ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
Ying Wangc7ca6172015-03-09 17:17:51 -0700163# For a Java library, by default we build odex for both 1st arch and 2nd arch.
164# But it can be overridden with "LOCAL_MULTILIB := first".
165ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
166# For system server jars, we build for only "first".
167my_module_multilib := first
168else
169my_module_multilib := $(LOCAL_MULTILIB)
170endif
Ying Wangb9aa5d42014-05-13 13:57:28 -0700171# #################################################
172# Odex for the 1st arch
Ying Wangdb48da72014-09-13 11:26:39 -0700173my_2nd_arch_prefix :=
174include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wangb9aa5d42014-05-13 13:57:28 -0700175# #################################################
176# Odex for the 2nd arch
177ifdef TARGET_2ND_ARCH
Ying Wang62630222016-04-20 11:53:39 -0700178ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
Ying Wangc7ca6172015-03-09 17:17:51 -0700179ifneq (first,$(my_module_multilib))
Ying Wangdb48da72014-09-13 11:26:39 -0700180my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
181include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wangc7ca6172015-03-09 17:17:51 -0700182endif # my_module_multilib is not first.
Ying Wang62630222016-04-20 11:53:39 -0700183endif # TARGET_TRANSLATE_2ND_ARCH not true
Ying Wangb9aa5d42014-05-13 13:57:28 -0700184endif # TARGET_2ND_ARCH
185# #################################################
186else # must be APPS
Ying Wangdb48da72014-09-13 11:26:39 -0700187# The preferred arch
188my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
189include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wang7a899192014-09-15 11:45:52 -0700190ifdef TARGET_2ND_ARCH
Ying Wangdb48da72014-09-13 11:26:39 -0700191ifeq ($(LOCAL_MULTILIB),both)
192# The non-preferred arch
193my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX))
194include $(BUILD_SYSTEM)/setup_one_odex.mk
195endif # LOCAL_MULTILIB is both
Ying Wang7a899192014-09-15 11:45:52 -0700196endif # TARGET_2ND_ARCH
Ying Wangb9aa5d42014-05-13 13:57:28 -0700197endif # LOCAL_MODULE_CLASS
Ying Wang7a899192014-09-15 11:45:52 -0700198endif # boot jar
Brian Carlstromced4bff2013-11-14 23:44:56 -0800199
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800200built_odex := $(strip $(built_odex))
David Brazdil70470162016-08-25 13:50:15 +0100201built_vdex := $(strip $(built_vdex))
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800202built_art := $(strip $(built_art))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800203installed_odex := $(strip $(installed_odex))
David Brazdil70470162016-08-25 13:50:15 +0100204installed_vdex := $(strip $(installed_vdex))
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800205installed_art := $(strip $(installed_art))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800206
Brian Carlstromced4bff2013-11-14 23:44:56 -0800207ifdef built_odex
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800208ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800209$(built_odex): $(my_built_profile)
210$(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := --profile-file=$(my_built_profile)
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800211else
212$(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS :=
213endif
214
Ying Wang20ebd2e2014-10-07 18:07:23 -0700215ifndef LOCAL_DEX_PREOPT_FLAGS
216LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG)
217ifndef LOCAL_DEX_PREOPT_FLAGS
218LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS)
219endif
220endif
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000221
Mathieu Chartier6a902102017-06-23 10:44:45 -0700222my_system_server_compiler_filter := $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)
223ifeq (,$(my_system_server_compiler_filter))
224my_system_server_compiler_filter := speed
225endif
226
Mathieu Chartierb8d3cc02017-06-16 11:17:53 -0700227ifeq (,$(filter --compiler-filter=%, $(LOCAL_DEX_PREOPT_FLAGS)))
Mathieu Chartier6a902102017-06-23 10:44:45 -0700228 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
229 # Jars of system server, use the product option if it is set, speed otherwise.
230 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=$(my_system_server_compiler_filter)
Mathieu Chartierb8d3cc02017-06-16 11:17:53 -0700231 else
Mathieu Chartier6a902102017-06-23 10:44:45 -0700232 ifneq (,$(filter $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(LOCAL_MODULE)))
233 # Apps loaded into system server, and apps the product default to being compiled with the
234 # 'speed' compiler filter.
235 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed
Mathieu Chartierc5536ff2017-05-05 14:59:06 -0700236 else
Mathieu Chartier6a902102017-06-23 10:44:45 -0700237 ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
238 # For non system server jars, use speed-profile when we have a profile.
239 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed-profile
240 else
241 # If no compiler filter is specified, default to 'quicken' to save on storage.
242 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=quicken
243 endif
Mathieu Chartierc5536ff2017-05-05 14:59:06 -0700244 endif
Nicolas Geoffray24f54692017-03-30 13:50:12 +0100245 endif
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000246endif
247
Mathieu Chartier94f5f932017-06-23 14:47:56 -0700248# PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
249my_system_server_debug_info := $(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)
250ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
251# Only enable for non-eng builds.
252ifeq (,$(my_system_server_debug_info))
253my_system_server_debug_info := true
254endif
255endif
256
257ifeq (true, $(my_system_server_debug_info))
258 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
259 LOCAL_DEX_PREOPT_FLAGS += --generate-mini-debug-info
260 endif
261endif
262
Ying Wang20ebd2e2014-10-07 18:07:23 -0700263$(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
David Brazdil70470162016-08-25 13:50:15 +0100264$(built_vdex): $(built_odex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800265$(built_art): $(built_odex)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800266endif
267
268# Add the installed_odex to the list of installed files for this module.
Ying Wang74c98502014-05-19 13:03:36 -0700269ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex)
David Brazdil70470162016-08-25 13:50:15 +0100270ALL_MODULES.$(my_register_name).INSTALLED += $(installed_vdex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800271ALL_MODULES.$(my_register_name).INSTALLED += $(installed_art)
Mathieu Chartier48762292017-09-13 22:08:45 -0700272
Ying Wang74c98502014-05-19 13:03:36 -0700273ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex)
David Brazdil70470162016-08-25 13:50:15 +0100274ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_vdex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800275ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_art)
Ying Wang74c98502014-05-19 13:03:36 -0700276
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800277# Record dex-preopt config.
278DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT)
279DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB)
280DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
281DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE)
Dan Willemsen05a2b932017-03-20 18:31:17 -0700282DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE)
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800283DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH)
284DEXPREOPT.$(LOCAL_MODULE).INSTALLED := $(installed_odex)
285DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE)
286DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \
287 $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE))
288
289
David Brazdil70470162016-08-25 13:50:15 +0100290# Make sure to install the .odex and .vdex when you run "make <module_name>"
Mathieu Chartier48762292017-09-13 22:08:45 -0700291$(my_all_targets): $(installed_odex) $(installed_vdex) $(installed_art)
Ying Wang5c7fed22014-01-22 16:50:21 -0800292
Brian Carlstromced4bff2013-11-14 23:44:56 -0800293endif # LOCAL_DEX_PREOPT
Mathieu Chartier48762292017-09-13 22:08:45 -0700294
295# Profile doesn't depend on LOCAL_DEX_PREOPT.
296ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_profile)
297ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(build_installed_profile)
298
299$(my_all_targets): $(my_installed_profile)