blob: 4ff6c8d965888fa5c4a75e231cd84d5b3ceeb27a [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
Brian Carlstromced4bff2013-11-14 23:44:56 -080068ifdef LOCAL_DEX_PREOPT
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070069
70ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE))
71LOCAL_DEX_PREOPT_GENERATE_PROFILE := false
72endif
73
Mathieu Chartier44c9c072017-05-09 19:17:33 -070074ifdef LOCAL_VENDOR_MODULE
75ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
76$(error profiles are not supported for vendor modules)
77endif
78else
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070079ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE
80# If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the
81# profile class listing. TODO: Use product specific directory here.
82my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR)
83LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(my_classes_directory)/$(LOCAL_MODULE).prof.txt
84ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)))
85# Profile listing exists, use it to generate the profile.
86ifeq ($(LOCAL_DEX_PREOPT_APP_IMAGE),)
87LOCAL_DEX_PREOPT_APP_IMAGE := true
88endif
89LOCAL_DEX_PREOPT_GENERATE_PROFILE := true
90endif
91endif
Mathieu Chartier44c9c072017-05-09 19:17:33 -070092endif
Mathieu Chartier6324c2d2017-05-05 17:22:37 -070093
Brian Carlstromced4bff2013-11-14 23:44:56 -080094dexpreopt_boot_jar_module := $(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE))
95ifdef dexpreopt_boot_jar_module
Brian Carlstromced4bff2013-11-14 23:44:56 -080096# For libart, the boot jars' odex files are replaced by $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE).
97# We use this installed_odex trick to get boot.art installed.
98installed_odex := $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE)
Ying Wangb9aa5d42014-05-13 13:57:28 -070099# Append the odex for the 2nd arch if we have one.
100installed_odex += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800101else # boot jar
Ying Wangb9aa5d42014-05-13 13:57:28 -0700102ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
Ying Wangc7ca6172015-03-09 17:17:51 -0700103# For a Java library, by default we build odex for both 1st arch and 2nd arch.
104# But it can be overridden with "LOCAL_MULTILIB := first".
105ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
106# For system server jars, we build for only "first".
107my_module_multilib := first
108else
109my_module_multilib := $(LOCAL_MULTILIB)
110endif
Ying Wangb9aa5d42014-05-13 13:57:28 -0700111# #################################################
112# Odex for the 1st arch
Ying Wangdb48da72014-09-13 11:26:39 -0700113my_2nd_arch_prefix :=
114include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wangb9aa5d42014-05-13 13:57:28 -0700115# #################################################
116# Odex for the 2nd arch
117ifdef TARGET_2ND_ARCH
Ying Wang62630222016-04-20 11:53:39 -0700118ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
Ying Wangc7ca6172015-03-09 17:17:51 -0700119ifneq (first,$(my_module_multilib))
Ying Wangdb48da72014-09-13 11:26:39 -0700120my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
121include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wangc7ca6172015-03-09 17:17:51 -0700122endif # my_module_multilib is not first.
Ying Wang62630222016-04-20 11:53:39 -0700123endif # TARGET_TRANSLATE_2ND_ARCH not true
Ying Wangb9aa5d42014-05-13 13:57:28 -0700124endif # TARGET_2ND_ARCH
125# #################################################
126else # must be APPS
Ying Wangdb48da72014-09-13 11:26:39 -0700127# The preferred arch
128my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
129include $(BUILD_SYSTEM)/setup_one_odex.mk
Ying Wang7a899192014-09-15 11:45:52 -0700130ifdef TARGET_2ND_ARCH
Ying Wangdb48da72014-09-13 11:26:39 -0700131ifeq ($(LOCAL_MULTILIB),both)
132# The non-preferred arch
133my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX))
134include $(BUILD_SYSTEM)/setup_one_odex.mk
135endif # LOCAL_MULTILIB is both
Ying Wang7a899192014-09-15 11:45:52 -0700136endif # TARGET_2ND_ARCH
Ying Wangb9aa5d42014-05-13 13:57:28 -0700137endif # LOCAL_MODULE_CLASS
Ying Wang7a899192014-09-15 11:45:52 -0700138endif # boot jar
Brian Carlstromced4bff2013-11-14 23:44:56 -0800139
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800140built_odex := $(strip $(built_odex))
David Brazdil70470162016-08-25 13:50:15 +0100141built_vdex := $(strip $(built_vdex))
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800142built_art := $(strip $(built_art))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800143installed_odex := $(strip $(installed_odex))
David Brazdil70470162016-08-25 13:50:15 +0100144installed_vdex := $(strip $(installed_vdex))
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800145installed_art := $(strip $(installed_art))
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800146
Brian Carlstromced4bff2013-11-14 23:44:56 -0800147ifdef built_odex
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800148ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
149ifndef LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING
150$(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING))
151endif
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100152ifeq (,$(dex_preopt_profile_src_file))
153$(call pretty-error, Internal error: dex_preopt_profile_src_file must be set)
154endif
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800155my_built_profile := $(dir $(LOCAL_BUILT_MODULE))/profile.prof
156my_dex_location := $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))
157$(built_odex): $(my_built_profile)
158$(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := --profile-file=$(my_built_profile)
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100159$(my_built_profile): PRIVATE_BUILT_MODULE := $(dex_preopt_profile_src_file)
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800160$(my_built_profile): PRIVATE_DEX_LOCATION := $(my_dex_location)
161$(my_built_profile): PRIVATE_SOURCE_CLASSES := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
162$(my_built_profile): $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
163$(my_built_profile): $(PROFMAN)
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100164$(my_built_profile): $(dex_preopt_profile_src_file)
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800165$(my_built_profile):
166 $(hide) mkdir -p $(dir $@)
167 ANDROID_LOG_TAGS="*:e" $(PROFMAN) \
168 --create-profile-from=$(PRIVATE_SOURCE_CLASSES) \
Dan Willemsen3d072d52017-03-20 13:54:41 -0700169 --apk=$(PRIVATE_BUILT_MODULE) \
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800170 --dex-location=$(PRIVATE_DEX_LOCATION) \
171 --reference-profile-file=$@
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100172dex_preopt_profile_src_file:=
Mathieu Chartier44c9c072017-05-09 19:17:33 -0700173my_installed_profile := $(LOCAL_INSTALLED_MODULE).prof
174$(eval $(call copy-one-file,$(my_built_profile),$(my_installed_profile)))
175build_installed_profile:=$(my_built_profile):$(my_installed_profile)
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800176else
Mathieu Chartier44c9c072017-05-09 19:17:33 -0700177build_installed_profile:=
178my_installed_profile :=
Mathieu Chartier2ac264f2017-03-03 11:17:36 -0800179$(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS :=
180endif
181
Ying Wang20ebd2e2014-10-07 18:07:23 -0700182ifndef LOCAL_DEX_PREOPT_FLAGS
183LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG)
184ifndef LOCAL_DEX_PREOPT_FLAGS
185LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS)
186endif
187endif
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000188
Mathieu Chartier6a902102017-06-23 10:44:45 -0700189my_system_server_compiler_filter := $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)
190ifeq (,$(my_system_server_compiler_filter))
191my_system_server_compiler_filter := speed
192endif
193
Mathieu Chartierb8d3cc02017-06-16 11:17:53 -0700194ifeq (,$(filter --compiler-filter=%, $(LOCAL_DEX_PREOPT_FLAGS)))
Mathieu Chartier6a902102017-06-23 10:44:45 -0700195 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
196 # Jars of system server, use the product option if it is set, speed otherwise.
197 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=$(my_system_server_compiler_filter)
Mathieu Chartierb8d3cc02017-06-16 11:17:53 -0700198 else
Mathieu Chartier6a902102017-06-23 10:44:45 -0700199 ifneq (,$(filter $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(LOCAL_MODULE)))
200 # Apps loaded into system server, and apps the product default to being compiled with the
201 # 'speed' compiler filter.
202 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed
Mathieu Chartierc5536ff2017-05-05 14:59:06 -0700203 else
Mathieu Chartier6a902102017-06-23 10:44:45 -0700204 ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE))
205 # For non system server jars, use speed-profile when we have a profile.
206 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed-profile
207 else
208 # If no compiler filter is specified, default to 'quicken' to save on storage.
209 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=quicken
210 endif
Mathieu Chartierc5536ff2017-05-05 14:59:06 -0700211 endif
Nicolas Geoffray24f54692017-03-30 13:50:12 +0100212 endif
Nicolas Geoffrayb08ada12017-03-22 12:36:05 +0000213endif
214
Mathieu Chartier94f5f932017-06-23 14:47:56 -0700215# PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
216my_system_server_debug_info := $(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)
217ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
218# Only enable for non-eng builds.
219ifeq (,$(my_system_server_debug_info))
220my_system_server_debug_info := true
221endif
222endif
223
224ifeq (true, $(my_system_server_debug_info))
225 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
226 LOCAL_DEX_PREOPT_FLAGS += --generate-mini-debug-info
227 endif
228endif
229
Ying Wang20ebd2e2014-10-07 18:07:23 -0700230$(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
David Brazdil70470162016-08-25 13:50:15 +0100231$(built_vdex): $(built_odex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800232$(built_art): $(built_odex)
Brian Carlstromced4bff2013-11-14 23:44:56 -0800233endif
234
235# Add the installed_odex to the list of installed files for this module.
Ying Wang74c98502014-05-19 13:03:36 -0700236ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex)
David Brazdil70470162016-08-25 13:50:15 +0100237ALL_MODULES.$(my_register_name).INSTALLED += $(installed_vdex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800238ALL_MODULES.$(my_register_name).INSTALLED += $(installed_art)
Mathieu Chartier44c9c072017-05-09 19:17:33 -0700239ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_profile)
Ying Wang74c98502014-05-19 13:03:36 -0700240ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex)
David Brazdil70470162016-08-25 13:50:15 +0100241ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_vdex)
Mathieu Chartier192b91c2017-02-08 18:30:31 -0800242ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_art)
Mathieu Chartier44c9c072017-05-09 19:17:33 -0700243ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(build_installed_profile)
Ying Wang74c98502014-05-19 13:03:36 -0700244
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800245# Record dex-preopt config.
246DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT)
247DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB)
248DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
249DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE)
Dan Willemsen05a2b932017-03-20 18:31:17 -0700250DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE)
Ying Wangfbc5b9f2016-03-11 10:32:01 -0800251DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH)
252DEXPREOPT.$(LOCAL_MODULE).INSTALLED := $(installed_odex)
253DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE)
254DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \
255 $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE))
256
257
David Brazdil70470162016-08-25 13:50:15 +0100258# Make sure to install the .odex and .vdex when you run "make <module_name>"
Mathieu Chartier44c9c072017-05-09 19:17:33 -0700259$(my_all_targets): $(installed_odex) $(installed_vdex) $(installed_art) $(my_installed_profile)
Ying Wang5c7fed22014-01-22 16:50:21 -0800260
Brian Carlstromced4bff2013-11-14 23:44:56 -0800261endif # LOCAL_DEX_PREOPT