1DEX_PREOPT_CONFIG := $(SOONG_OUT_DIR)/dexpreopt.config
2
3ENABLE_PREOPT := true
4ENABLE_PREOPT_BOOT_IMAGES := true
5ifneq (true,$(filter true,$(WITH_DEXPREOPT)))
6  # Disable dexpreopt for libraries/apps and for boot images.
7  ENABLE_PREOPT :=
8  ENABLE_PREOPT_BOOT_IMAGES :=
9else ifneq (true,$(filter true,$(PRODUCT_USES_DEFAULT_ART_CONFIG)))
10  # Disable dexpreopt for libraries/apps and for boot images: not having default
11  # ART config means that some important system properties are not set, which
12  # would result in passing bad arguments to dex2oat and failing the build.
13  ENABLE_PREOPT :=
14  ENABLE_PREOPT_BOOT_IMAGES :=
15else
16  ifeq (true,$(DISABLE_PREOPT))
17    # Disable dexpreopt for libraries/apps, but may compile boot images.
18    ENABLE_PREOPT :=
19  endif
20  ifeq (true,$(DISABLE_PREOPT_BOOT_IMAGES))
21    # Disable dexpreopt for boot images, but may compile libraries/apps.
22    ENABLE_PREOPT_BOOT_IMAGES :=
23  endif
24endif
25
26# The default value for LOCAL_DEX_PREOPT
27DEX_PREOPT_DEFAULT ?= $(ENABLE_PREOPT)
28
29# Whether to fail immediately if verify_uses_libraries check fails, or to keep
30# going and restrict dexpreopt to not compile any code for the failed module.
31#
32# The intended use case for this flag is to have a smoother migration path for
33# the Java modules that need to add <uses-library> information in their build
34# files. The flag allows to quickly silence build errors. This flag should be
35# used with caution and only as a temporary measure, as it masks real errors
36# and affects performance.
37ifndef RELAX_USES_LIBRARY_CHECK
38  RELAX_USES_LIBRARY_CHECK := $(if \
39    $(filter true,$(PRODUCT_BROKEN_VERIFY_USES_LIBRARIES)),true,false)
40else
41  # Let the environment variable override PRODUCT_BROKEN_VERIFY_USES_LIBRARIES.
42endif
43.KATI_READONLY := RELAX_USES_LIBRARY_CHECK
44
45# The default filter for which files go into the system_other image (if it is
46# being used). Note that each pattern p here matches both '/<p>' and /system/<p>'.
47# To bundle everything one should set this to '%'.
48SYSTEM_OTHER_ODEX_FILTER ?= \
49    app/% \
50    priv-app/% \
51    system_ext/app/% \
52    system_ext/priv-app/% \
53    product/app/% \
54    product/priv-app/% \
55
56# Global switch to control if updatable boot jars are included in dexpreopt.
57DEX_PREOPT_WITH_UPDATABLE_BCP := true
58
59# Conditional to building on linux, as dex2oat currently does not work on darwin.
60ifeq ($(HOST_OS),linux)
61  # Add mini-debug-info to the boot classpath unless explicitly asked not to.
62  ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO))
63    PRODUCT_DEX_PREOPT_BOOT_FLAGS += --generate-mini-debug-info
64  endif
65endif
66
67# Get value of a property. It is first searched from PRODUCT_VENDOR_PROPERTIES
68# and then falls back to PRODUCT_SYSTEM_PROPERTIES
69# $1: name of the property
70define get-product-default-property
71$(strip \
72  $(eval _prop := $(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_VENDOR_PROPERTIES))))\
73  $(if $(_prop),$(_prop),$(patsubst $(1)=%,%,$(filter $(1)=%,$(PRODUCT_SYSTEM_PROPERTIES)))))
74endef
75
76DEX2OAT_IMAGE_XMS := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xms)
77DEX2OAT_IMAGE_XMX := $(call get-product-default-property,dalvik.vm.image-dex2oat-Xmx)
78DEX2OAT_XMS := $(call get-product-default-property,dalvik.vm.dex2oat-Xms)
79DEX2OAT_XMX := $(call get-product-default-property,dalvik.vm.dex2oat-Xmx)
80
81ifeq ($(WRITE_SOONG_VARIABLES),true)
82
83  $(call json_start)
84
85  $(call add_json_bool, DisablePreopt,                           $(call invert_bool,$(ENABLE_PREOPT)))
86  $(call add_json_bool, DisablePreoptBootImages,                 $(call invert_bool,$(ENABLE_PREOPT_BOOT_IMAGES)))
87  $(call add_json_list, DisablePreoptModules,                    $(DEXPREOPT_DISABLED_MODULES))
88  $(call add_json_bool, OnlyPreoptArtBootImage            ,      $(filter true,$(WITH_DEXPREOPT_ART_BOOT_IMG_ONLY)))
89  $(call add_json_bool, PreoptWithUpdatableBcp,                  $(filter true,$(DEX_PREOPT_WITH_UPDATABLE_BCP)))
90  $(call add_json_bool, DontUncompressPrivAppsDex,               $(filter true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS)))
91  $(call add_json_list, ModulesLoadedByPrivilegedModules,        $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES))
92  $(call add_json_bool, HasSystemOther,                          $(BOARD_USES_SYSTEM_OTHER_ODEX))
93  $(call add_json_list, PatternsOnSystemOther,                   $(SYSTEM_OTHER_ODEX_FILTER))
94  $(call add_json_bool, DisableGenerateProfile,                  $(filter false,$(WITH_DEX_PREOPT_GENERATE_PROFILE)))
95  $(call add_json_str,  ProfileDir,                              $(PRODUCT_DEX_PREOPT_PROFILE_DIR))
96  $(call add_json_list, BootJars,                                $(PRODUCT_BOOT_JARS))
97  $(call add_json_list, ApexBootJars,                            $(filter-out $(APEX_BOOT_JARS_EXCLUDED), $(PRODUCT_APEX_BOOT_JARS)))
98  $(call add_json_list, ArtApexJars,                             $(filter $(PRODUCT_BOOT_JARS),$(ART_APEX_JARS)))
99  $(call add_json_list, TestOnlyArtBootImageJars,                $(PRODUCT_TEST_ONLY_ART_BOOT_IMAGE_JARS))
100  $(call add_json_list, SystemServerJars,                        $(PRODUCT_SYSTEM_SERVER_JARS))
101  $(call add_json_list, SystemServerApps,                        $(PRODUCT_SYSTEM_SERVER_APPS))
102  $(call add_json_list, ApexSystemServerJars,                    $(PRODUCT_APEX_SYSTEM_SERVER_JARS))
103  $(call add_json_list, StandaloneSystemServerJars,              $(PRODUCT_STANDALONE_SYSTEM_SERVER_JARS))
104  $(call add_json_list, ApexStandaloneSystemServerJars,          $(PRODUCT_APEX_STANDALONE_SYSTEM_SERVER_JARS))
105  $(call add_json_bool, BrokenSuboptimalOrderOfSystemServerJars, $(PRODUCT_BROKEN_SUBOPTIMAL_ORDER_OF_SYSTEM_SERVER_JARS))
106  $(call add_json_list, SpeedApps,                               $(PRODUCT_DEXPREOPT_SPEED_APPS))
107  $(call add_json_list, PreoptFlags,                             $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS))
108  $(call add_json_str,  DefaultCompilerFilter,                   $(PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER))
109  $(call add_json_str,  SystemServerCompilerFilter,              $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER))
110  $(call add_json_bool, GenerateDmFiles,                         $(PRODUCT_DEX_PREOPT_GENERATE_DM_FILES))
111  $(call add_json_bool, NeverAllowStripping,                     $(PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING))
112  $(call add_json_bool, NoDebugInfo,                             $(filter false,$(WITH_DEXPREOPT_DEBUG_INFO)))
113  $(call add_json_bool, DontResolveStartupStrings,               $(filter false,$(PRODUCT_DEX_PREOPT_RESOLVE_STARTUP_STRINGS)))
114  $(call add_json_bool, AlwaysSystemServerDebugInfo,             $(filter true,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)))
115  $(call add_json_bool, NeverSystemServerDebugInfo,              $(filter false,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO)))
116  $(call add_json_bool, AlwaysOtherDebugInfo,                    $(filter true,$(PRODUCT_OTHER_JAVA_DEBUG_INFO)))
117  $(call add_json_bool, NeverOtherDebugInfo,                     $(filter false,$(PRODUCT_OTHER_JAVA_DEBUG_INFO)))
118  $(call add_json_bool, IsEng,                                   $(filter eng,$(TARGET_BUILD_VARIANT)))
119  $(call add_json_bool, SanitizeLite,                            $(SANITIZE_LITE))
120  $(call add_json_bool, DefaultAppImages,                        $(WITH_DEX_PREOPT_APP_IMAGE))
121  $(call add_json_bool, RelaxUsesLibraryCheck,                   $(filter true,$(RELAX_USES_LIBRARY_CHECK)))
122  $(call add_json_str,  Dex2oatXmx,                              $(DEX2OAT_XMX))
123  $(call add_json_str,  Dex2oatXms,                              $(DEX2OAT_XMS))
124  $(call add_json_str,  EmptyDirectory,                          $(OUT_DIR)/empty)
125  $(call add_json_str,  EnableUffdGc,                            $(ENABLE_UFFD_GC))
126
127ifdef TARGET_ARCH
128  $(call add_json_map,  CpuVariant)
129  $(call add_json_str,  $(TARGET_ARCH), $(DEX2OAT_TARGET_CPU_VARIANT))
130  ifdef TARGET_2ND_ARCH
131    $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_CPU_VARIANT))
132  endif
133  $(call end_json_map)
134
135  $(call add_json_map,  InstructionSetFeatures)
136  $(call add_json_str,  $(TARGET_ARCH), $(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES))
137  ifdef TARGET_2ND_ARCH
138    $(call add_json_str, $(TARGET_2ND_ARCH), $($(TARGET_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES))
139  endif
140  $(call end_json_map)
141endif
142
143  $(call add_json_list, BootImageProfiles,                  $(PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION))
144  $(call add_json_str,  BootFlags,                          $(PRODUCT_DEX_PREOPT_BOOT_FLAGS))
145  $(call add_json_str,  Dex2oatImageXmx,                    $(DEX2OAT_IMAGE_XMX))
146  $(call add_json_str,  Dex2oatImageXms,                    $(DEX2OAT_IMAGE_XMS))
147
148  $(call json_end)
149
150  $(shell mkdir -p $(dir $(DEX_PREOPT_CONFIG)))
151  $(file >$(DEX_PREOPT_CONFIG).tmp,$(json_contents))
152
153  $(shell \
154    if ! cmp -s $(DEX_PREOPT_CONFIG).tmp $(DEX_PREOPT_CONFIG); then \
155      mv $(DEX_PREOPT_CONFIG).tmp $(DEX_PREOPT_CONFIG); \
156    else \
157      rm $(DEX_PREOPT_CONFIG).tmp; \
158    fi)
159endif
160