1DEX_PREOPT_CONFIG := $(SOONG_OUT_DIR)/dexpreopt.config
2
3# The default value for LOCAL_DEX_PREOPT
4DEX_PREOPT_DEFAULT ?= true
5
6# The default filter for which files go into the system_other image (if it is
7# being used). Note that each pattern p here matches both '/<p>' and /system/<p>'.
8# To bundle everything one should set this to '%'.
9SYSTEM_OTHER_ODEX_FILTER ?= \
10    app/% \
11    priv-app/% \
12    system_ext/app/% \
13    system_ext/priv-app/% \
14    product/app/% \
15    product/priv-app/% \
16
17# Conditional to building on linux, as dex2oat currently does not work on darwin.
18ifeq ($(HOST_OS),linux)
19  ifeq (eng,$(TARGET_BUILD_VARIANT))
20    # For an eng build only pre-opt the boot image and system server. This gives reasonable performance
21    # and still allows a simple workflow: building in frameworks/base and syncing.
22    WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true
23  endif
24  # Add mini-debug-info to the boot classpath unless explicitly asked not to.
25  ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO))
26    PRODUCT_DEX_PREOPT_BOOT_FLAGS += --generate-mini-debug-info
27  endif
28
29  # Non eng linux builds must have preopt enabled so that system server doesn't run as interpreter
30  # only. b/74209329
31  ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
32    ifneq (true,$(WITH_DEXPREOPT))
33      ifneq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY))
34        $(call pretty-error, DEXPREOPT must be enabled for user and userdebug builds)
35      endif
36    endif
37  endif
38endif
39
40# Use the first preloaded-classes file in PRODUCT_COPY_FILES.
41PRELOADED_CLASSES := $(call word-colon,1,$(firstword \
42    $(filter %system/etc/preloaded-classes,$(PRODUCT_COPY_FILES))))
43
44# Use the first dirty-image-objects file in PRODUCT_COPY_FILES.
45DIRTY_IMAGE_OBJECTS := $(call word-colon,1,$(firstword \
46    $(filter %system/etc/dirty-image-objects,$(PRODUCT_COPY_FILES))))
47
48define get-product-default-property
49$(strip \
50  $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))))\
51  $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_DEFAULT_PROPERTIES)))))
52endef
53
54DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms)
55DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx)
56DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms)
57DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx)
58
59ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
60# MIPS specific overrides.
61# For MIPS the ART image is loaded at a lower address. This causes issues
62# with the image overlapping with memory on the host cross-compiling and
63# building the image. We therefore limit the Xmx value. This isn't done
64# via a property as we want the larger Xmx value if we're running on a
65# MIPS device.
66DEX2OAT_XMX := 128m
67endif
68
69ifeq ($(WRITE_SOONG_VARIABLES),true)
70
71  $(call json_start)
72
73  $(call add_json_bool, DisablePreopt,                      $(call invert_bool,$(and $(filter true,$(PRODUCT_USES_DEFAULT_ART_CONFIG)),$(filter true,$(WITH_DEXPREOPT)))))
74  $(call add_json_list, DisablePreoptModules,               $(DEXPREOPT_DISABLED_MODULES))
75  $(call add_json_bool, OnlyPreoptBootImageAndSystemServer, $(filter true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY)))
76  $(call add_json_bool, UseArtImage,                        $(filter true,$(DEXPREOPT_USE_ART_IMAGE)))
77  $(call add_json_bool, DontUncompressPrivAppsDex,          $(filter true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS)))
78  $(call add_json_list, ModulesLoadedByPrivilegedModules,   $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES))
79  $(call add_json_bool, HasSystemOther,                     $(BOARD_USES_SYSTEM_OTHER_ODEX))
80  $(call add_json_list, PatternsOnSystemOther,              $(SYSTEM_OTHER_ODEX_FILTER))
81  $(call add_json_bool, DisableGenerateProfile,             $(filter false,$(WITH_DEX_PREOPT_GENERATE_PROFILE)))
82  $(call add_json_str,  ProfileDir,                         $(PRODUCT_DEX_PREOPT_PROFILE_DIR))
83  $(call add_json_list, BootJars,                           $(PRODUCT_BOOT_JARS))
84  $(call add_json_list, UpdatableBootJars,                  $(PRODUCT_UPDATABLE_BOOT_JARS))
85  $(call add_json_list, ArtApexJars,                        $(ART_APEX_JARS))
86  $(call add_json_list, SystemServerJars,                   $(PRODUCT_SYSTEM_SERVER_JARS))
87  $(call add_json_list, SystemServerApps,                   $(PRODUCT_SYSTEM_SERVER_APPS))
88  $(call add_json_list, UpdatableSystemServerJars,          $(PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS))
89  $(call add_json_list, SpeedApps,                          $(PRODUCT_DEXPREOPT_SPEED_APPS))
90  $(call add_json_list, PreoptFlags,                        $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS))
91  $(call add_json_str,  DefaultCompilerFilter,              $(PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER))
92  $(call add_json_str,  SystemServerCompilerFilter,         $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER))
93  $(call add_json_bool, GenerateDmFiles,                    $(PRODUCT_DEX_PREOPT_GENERATE_DM_FILES))
94  $(call add_json_bool, NeverAllowStripping,                $(PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING))
95  $(call add_json_bool, NoDebugInfo,                        $(filter false,$(WITH_DEXPREOPT_DEBUG_INFO)))
96  $(call add_json_bool, DontResolveStartupStrings,          $(filter false,$(PRODUCT_DEX_PREOPT_RESOLVE_STARTUP_STRINGS)))
97  $(call add_json_bool, AlwaysSystemServerDebugInfo,        $(filter true,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)))
98  $(call add_json_bool, NeverSystemServerDebugInfo,         $(filter false,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)))
99  $(call add_json_bool, AlwaysOtherDebugInfo,               $(filter true,$(PRODUCT_OTHER_JAVA_DEBUG_INFO)))
100  $(call add_json_bool, NeverOtherDebugInfo,                $(filter false,$(PRODUCT_OTHER_JAVA_DEBUG_INFO)))
101  $(call add_json_bool, IsEng,                              $(filter eng,$(TARGET_BUILD_VARIANT)))
102  $(call add_json_bool, SanitizeLite,                       $(SANITIZE_LITE))
103  $(call add_json_bool, DefaultAppImages,                   $(WITH_DEX_PREOPT_APP_IMAGE))
104  $(call add_json_str,  Dex2oatXmx,                         $(DEX2OAT_XMX))
105  $(call add_json_str,  Dex2oatXms,                         $(DEX2OAT_XMS))
106  $(call add_json_str,  EmptyDirectory,                     $(OUT_DIR)/empty)
107
108  $(call add_json_map,  CpuVariant)
109  $(call add_json_str,  $(TARGET_ARCH), $(DEX2OAT_TARGET_CPU_VARIANT))
110  ifdef TARGET_2ND_ARCH
111    $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT))
112  endif
113  $(call end_json_map)
114
115  $(call add_json_map,  InstructionSetFeatures)
116  $(call add_json_str,  $(TARGET_ARCH), $(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES))
117  ifdef TARGET_2ND_ARCH
118    $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES))
119  endif
120  $(call end_json_map)
121
122  $(call add_json_str,  DirtyImageObjects,                  $(DIRTY_IMAGE_OBJECTS))
123  $(call add_json_list, BootImageProfiles,                  $(PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION))
124  $(call add_json_str,  BootFlags,                          $(PRODUCT_DEX_PREOPT_BOOT_FLAGS))
125  $(call add_json_str,  Dex2oatImageXmx,                    $(DEX2OAT_IMAGE_XMX))
126  $(call add_json_str,  Dex2oatImageXms,                    $(DEX2OAT_IMAGE_XMS))
127
128  $(call json_end)
129
130  $(shell mkdir -p $(dir $(DEX_PREOPT_CONFIG)))
131  $(file >$(DEX_PREOPT_CONFIG).tmp,$(json_contents))
132
133  $(shell \
134    if ! cmp -s $(DEX_PREOPT_CONFIG).tmp $(DEX_PREOPT_CONFIG); then \
135      mv $(DEX_PREOPT_CONFIG).tmp $(DEX_PREOPT_CONFIG); \
136    else \
137      rm $(DEX_PREOPT_CONFIG).tmp; \
138    fi)
139endif
140