• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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, LOCAL_UNCOMPRESS_DEX
4
5ifeq (true,$(LOCAL_USE_EMBEDDED_DEX))
6  LOCAL_UNCOMPRESS_DEX := true
7else
8  LOCAL_UNCOMPRESS_DEX :=
9endif
10
11# We explicitly uncompress APKs of privileged apps, and used by
12# privileged apps
13ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS))
14  ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
15    LOCAL_UNCOMPRESS_DEX := true
16  endif
17
18  ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
19    LOCAL_UNCOMPRESS_DEX := true
20  endif
21endif  # DONT_UNCOMPRESS_PRIV_APPS_DEXS
22
23# Setting LOCAL_DEX_PREOPT based on WITH_DEXPREOPT, LOCAL_DEX_PREOPT, etc
24LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT))
25ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined
26  LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT)
27endif
28
29ifeq (false,$(LOCAL_DEX_PREOPT))
30  LOCAL_DEX_PREOPT :=
31endif
32
33# Only enable preopt for non tests.
34ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests))
35  LOCAL_DEX_PREOPT :=
36endif
37
38# If we have product-specific config for this module?
39ifneq (,$(filter $(LOCAL_MODULE),$(DEXPREOPT_DISABLED_MODULES)))
40  LOCAL_DEX_PREOPT :=
41endif
42
43# Disable preopt for TARGET_BUILD_APPS
44ifneq (,$(TARGET_BUILD_APPS))
45  LOCAL_DEX_PREOPT :=
46endif
47
48# Disable preopt if not WITH_DEXPREOPT
49ifneq (true,$(WITH_DEXPREOPT))
50  LOCAL_DEX_PREOPT :=
51endif
52
53ifdef LOCAL_UNINSTALLABLE_MODULE
54  LOCAL_DEX_PREOPT :=
55endif
56
57ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file)$(LOCAL_SOONG_DEX_JAR))) # contains no java code
58  LOCAL_DEX_PREOPT :=
59endif
60
61# if WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true and module is not in boot class path skip
62# Also preopt system server jars since selinux prevents system server from loading anything from
63# /data. If we don't do this they will need to be extracted which is not favorable for RAM usage
64# or performance. If my_preopt_for_extracted_apk is true, we ignore the only preopt boot image
65# options.
66ifneq (true,$(my_preopt_for_extracted_apk))
67  ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))
68    ifeq ($(filter $(PRODUCT_SYSTEM_SERVER_JARS) $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),)
69      LOCAL_DEX_PREOPT :=
70    endif
71  endif
72endif
73
74my_process_profile :=
75my_profile_is_text_listing :=
76
77ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE))
78  LOCAL_DEX_PREOPT_GENERATE_PROFILE := false
79endif
80
81ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE
82  # If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the
83  # profile class listing. TODO: Use product specific directory here.
84  my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR)
85  LOCAL_DEX_PREOPT_PROFILE := $(my_classes_directory)/$(LOCAL_MODULE).prof
86
87  ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE)))
88    my_process_profile := true
89    my_profile_is_text_listing :=
90  endif
91else
92  my_process_profile := $(LOCAL_DEX_PREOPT_GENERATE_PROFILE)
93  my_profile_is_text_listing := true
94  LOCAL_DEX_PREOPT_PROFILE := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
95endif
96
97ifeq (true,$(my_process_profile))
98  ifndef LOCAL_DEX_PREOPT_PROFILE
99    $(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE))
100  endif
101  ifeq (,$(dex_preopt_profile_src_file))
102    $(call pretty-error, Internal error: dex_preopt_profile_src_file must be set)
103  endif
104endif
105
106# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or
107# LOCAL_OPTIONAL_USES_LIBRARIES are specified.
108ifeq (,$(LOCAL_ENFORCE_USES_LIBRARIES))
109  # Will change the default to true unconditionally in the future.
110  ifneq (,$(LOCAL_OPTIONAL_USES_LIBRARIES))
111    LOCAL_ENFORCE_USES_LIBRARIES := true
112  endif
113  ifneq (,$(LOCAL_USES_LIBRARIES))
114    LOCAL_ENFORCE_USES_LIBRARIES := true
115  endif
116endif
117
118my_dexpreopt_archs :=
119my_dexpreopt_images :=
120my_dexpreopt_infix := boot
121ifeq (true, $(DEXPREOPT_USE_APEX_IMAGE))
122  my_dexpreopt_infix := apex
123endif
124
125ifdef LOCAL_DEX_PREOPT
126  ifeq (,$(filter PRESIGNED,$(LOCAL_CERTIFICATE)))
127    # Store uncompressed dex files preopted in /system
128    ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
129      ifeq ($(call install-on-system-other, $(my_module_path)),)
130        LOCAL_UNCOMPRESS_DEX := true
131      endif  # install-on-system-other
132    else  # BOARD_USES_SYSTEM_OTHER_ODEX
133      LOCAL_UNCOMPRESS_DEX := true
134    endif
135  endif
136
137  ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
138    my_module_multilib := $(LOCAL_MULTILIB)
139    # If the module is not an SDK library and it's a system server jar, only preopt the primary arch.
140    ifeq (,$(filter $(JAVA_SDK_LIBRARIES),$(LOCAL_MODULE)))
141      # For a Java library, by default we build odex for both 1st arch and 2nd arch.
142      # But it can be overridden with "LOCAL_MULTILIB := first".
143      ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE)))
144        # For system server jars, we build for only "first".
145        my_module_multilib := first
146      endif
147    endif
148
149    # Only preopt primary arch for translated arch since there is only an image there.
150    ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true)
151      my_module_multilib := first
152    endif
153
154    # #################################################
155    # Odex for the 1st arch
156    my_dexpreopt_archs += $(TARGET_ARCH)
157    my_dexpreopt_images += $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_ARCH))
158    # Odex for the 2nd arch
159    ifdef TARGET_2ND_ARCH
160      ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
161        ifneq (first,$(my_module_multilib))
162          my_dexpreopt_archs += $(TARGET_2ND_ARCH)
163          my_dexpreopt_images += $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_2ND_ARCH))
164        endif  # my_module_multilib is not first.
165      endif  # TARGET_TRANSLATE_2ND_ARCH not true
166    endif  # TARGET_2ND_ARCH
167    # #################################################
168  else  # must be APPS
169    # The preferred arch
170    # Save the module multilib since setup_one_odex modifies it.
171    my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
172    my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH)
173    my_dexpreopt_images += \
174        $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH))
175    ifdef TARGET_2ND_ARCH
176      ifeq ($(my_module_multilib),both)
177        # The non-preferred arch
178        my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX))
179        my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH)
180        my_dexpreopt_images += \
181            $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH))
182      endif  # LOCAL_MULTILIB is both
183    endif  # TARGET_2ND_ARCH
184  endif  # LOCAL_MODULE_CLASS
185
186  # Record dex-preopt config.
187  DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT)
188  DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB)
189  DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
190  DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE)
191  DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE)
192  DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH)
193  DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE)
194  DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \
195    $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE))
196
197  $(call json_start)
198
199  # DexPath, StripInputPath, and StripOutputPath are not set, they will
200  # be filled in by dexpreopt_gen.
201
202  $(call add_json_str,  Name,                           $(LOCAL_MODULE))
203  $(call add_json_str,  DexLocation,                    $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE)))
204  $(call add_json_str,  BuildPath,                      $(LOCAL_BUILT_MODULE))
205  $(call add_json_str,  ExtrasOutputPath,               $$2)
206  $(call add_json_bool, Privileged,                     $(filter true,$(LOCAL_PRIVILEGED_MODULE)))
207  $(call add_json_bool, UncompressedDex,                $(filter true,$(LOCAL_UNCOMPRESS_DEX)))
208  $(call add_json_bool, HasApkLibraries,                $(LOCAL_APK_LIBRARIES))
209  $(call add_json_list, PreoptFlags,                    $(LOCAL_DEX_PREOPT_FLAGS))
210  $(call add_json_str,  ProfileClassListing,            $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE)))
211  $(call add_json_bool, ProfileIsTextListing,           $(my_profile_is_text_listing))
212  $(call add_json_bool, EnforceUsesLibraries,           $(LOCAL_ENFORCE_USES_LIBRARIES))
213  $(call add_json_list, OptionalUsesLibraries,          $(LOCAL_OPTIONAL_USES_LIBRARIES))
214  $(call add_json_list, UsesLibraries,                  $(LOCAL_USES_LIBRARIES))
215  $(call add_json_map,  LibraryPaths)
216  $(foreach lib,$(sort $(LOCAL_USES_LIBRARIES) $(LOCAL_OPTIONAL_USES_LIBRARIES) org.apache.http.legacy android.hidl.base-V1.0-java android.hidl.manager-V1.0-java),\
217    $(call add_json_str, $(lib), $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar))
218  $(call end_json_map)
219  $(call add_json_list, Archs,                          $(my_dexpreopt_archs))
220  $(call add_json_list, DexPreoptImages,                $(my_dexpreopt_images))
221  $(call add_json_list, PreoptBootClassPathDexFiles,    $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES))
222  $(call add_json_list, PreoptBootClassPathDexLocations,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS))
223  $(call add_json_bool, PreoptExtractedApk,             $(my_preopt_for_extracted_apk))
224  $(call add_json_bool, NoCreateAppImage,               $(filter false,$(LOCAL_DEX_PREOPT_APP_IMAGE)))
225  $(call add_json_bool, ForceCreateAppImage,            $(filter true,$(LOCAL_DEX_PREOPT_APP_IMAGE)))
226  $(call add_json_bool, PresignedPrebuilt,              $(filter PRESIGNED,$(LOCAL_CERTIFICATE)))
227
228  $(call add_json_bool, NoStripping,                    $(filter nostripping,$(LOCAL_DEX_PREOPT)))
229
230  $(call json_end)
231
232  my_dexpreopt_config := $(intermediates)/dexpreopt.config
233  my_dexpreopt_script := $(intermediates)/dexpreopt.sh
234  my_strip_script := $(intermediates)/strip.sh
235  my_dexpreopt_zip := $(intermediates)/dexpreopt.zip
236
237  $(my_dexpreopt_config): PRIVATE_MODULE := $(LOCAL_MODULE)
238  $(my_dexpreopt_config): PRIVATE_CONTENTS := $(json_contents)
239  $(my_dexpreopt_config):
240	@echo "$(PRIVATE_MODULE) dexpreopt.config"
241	echo -e -n '$(subst $(newline),\n,$(subst ','\'',$(subst \,\\,$(PRIVATE_CONTENTS))))' > $@
242
243  .KATI_RESTAT: $(my_dexpreopt_script) $(my_strip_script)
244  $(my_dexpreopt_script): PRIVATE_MODULE := $(LOCAL_MODULE)
245  $(my_dexpreopt_script): PRIVATE_GLOBAL_CONFIG := $(PRODUCT_OUT)/dexpreopt.config
246  $(my_dexpreopt_script): PRIVATE_MODULE_CONFIG := $(my_dexpreopt_config)
247  $(my_dexpreopt_script): PRIVATE_STRIP_SCRIPT := $(my_strip_script)
248  $(my_dexpreopt_script): .KATI_IMPLICIT_OUTPUTS := $(my_strip_script)
249  $(my_dexpreopt_script): $(DEXPREOPT_GEN)
250  $(my_dexpreopt_script): $(my_dexpreopt_config) $(PRODUCT_OUT)/dexpreopt.config
251	@echo "$(PRIVATE_MODULE) dexpreopt gen"
252	$(DEXPREOPT_GEN) -global $(PRIVATE_GLOBAL_CONFIG) -module $(PRIVATE_MODULE_CONFIG) \
253	-dexpreopt_script $@ -strip_script $(PRIVATE_STRIP_SCRIPT) \
254	-out_dir $(OUT_DIR)
255
256  my_dexpreopt_deps := $(my_dex_jar)
257  my_dexpreopt_deps += $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE))
258  my_dexpreopt_deps += \
259    $(foreach lib,$(sort $(LOCAL_USES_LIBRARIES) $(LOCAL_OPTIONAL_USES_LIBRARIES) org.apache.http.legacy android.hidl.base-V1.0-java android.hidl.manager-V1.0-java),\
260      $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar)
261  my_dexpreopt_deps += $(my_dexpreopt_images)
262  my_dexpreopt_deps += $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)
263
264  $(my_dexpreopt_zip): PRIVATE_MODULE := $(LOCAL_MODULE)
265  $(my_dexpreopt_zip): $(my_dexpreopt_deps)
266  $(my_dexpreopt_zip): | $(DEXPREOPT_GEN_DEPS)
267  $(my_dexpreopt_zip): .KATI_DEPFILE := $(my_dexpreopt_zip).d
268  $(my_dexpreopt_zip): PRIVATE_DEX := $(my_dex_jar)
269  $(my_dexpreopt_zip): PRIVATE_SCRIPT := $(my_dexpreopt_script)
270  $(my_dexpreopt_zip): $(my_dexpreopt_script)
271	@echo "$(PRIVATE_MODULE) dexpreopt"
272	bash $(PRIVATE_SCRIPT) $(PRIVATE_DEX) $@
273
274  ifdef LOCAL_POST_INSTALL_CMD
275    # Add a shell command separator
276    LOCAL_POST_INSTALL_CMD += &&
277  endif
278
279  LOCAL_POST_INSTALL_CMD += \
280    for i in $$(zipinfo -1 $(my_dexpreopt_zip)); \
281      do mkdir -p $(PRODUCT_OUT)/$$(dirname $$i); \
282    done && \
283    ( unzip -qo -d $(PRODUCT_OUT) $(my_dexpreopt_zip) 2>&1 | grep -v "zipfile is empty"; exit $${PIPESTATUS[0]} ) || \
284      ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi )
285
286  $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
287  $(LOCAL_INSTALLED_MODULE): $(my_dexpreopt_zip)
288
289  $(my_all_targets): $(my_dexpreopt_zip)
290
291  my_dexpreopt_config :=
292  my_dexpreopt_script :=
293  my_strip_script :=
294  my_dexpreopt_zip :=
295endif # LOCAL_DEX_PREOPT
296