Merge "Preserve <uses-library> order in dexpreopt.config files."

This commit is contained in:
Ulyana Trafimovich 2021-02-12 10:22:39 +00:00 committed by Gerrit Code Review
commit e5511ed739
3 changed files with 19 additions and 15 deletions

View File

@ -24,7 +24,10 @@ add_json_list =$= $(call add_json_val,$(1),$(call json_list,$(patsubst %,%,$(2))
add_json_csv =$= $(call add_json_val,$(1),$(call csv_to_json_list,$(strip $(2))))
add_json_bool =$= $(call add_json_val,$(1),$(if $(strip $(2)),true,false))
add_json_map =$= $(eval _json_contents := $$(_json_contents)$$(_json_indent)"$$(strip $$(1))": {$$(newline))$(json_increase_indent)
add_json_map_anon =$= $(eval _json_contents := $$(_json_contents)$$(_json_indent){$$(newline))$(json_increase_indent)
end_json_map =$= $(json_decrease_indent)$(eval _json_contents := $$(_json_contents)$$(if $$(filter %$$(comma),$$(lastword $$(_json_contents))),__SV_END)$$(_json_indent)},$$(newline))
add_json_array =$= $(eval _json_contents := $$(_json_contents)$$(_json_indent)"$$(strip $$(1))": [$$(newline))$(json_increase_indent)
end_json_array =$= $(json_decrease_indent)$(eval _json_contents := $$(_json_contents)$$(if $$(filter %$$(comma),$$(lastword $$(_json_contents))),__SV_END)$$(_json_indent)],$$(newline))
# Clears _json_contents to start a new json file
json_start =$= $(eval _json_contents := {$$(newline))$(eval _json_indent := $$(4space))

View File

@ -67,24 +67,25 @@ def main():
# the loop in case this changes in the future.
for sdk_ver in clc_map:
clcs = clc_map[sdk_ver]
clcs2 = OrderedDict()
for lib in clcs:
clc = clcs[lib]
clcs2 = []
for clc in clcs:
lib = clc['Name']
if lib in uses_libs:
ulib = uses_libs[lib]
# The real <uses-library> name (may be different from the module name).
clc['Name'] = ulib['ProvidesUsesLibrary']
# On-device (install) path to the dependency DEX jar file.
clc['Device'] = ulib['DexLocation']
# CLC of the dependency becomes a subcontext. We only need sub-CLC for
# 'any' version because all other versions are for compatibility
# libraries, which exist only for apps and not for libraries.
clc['Subcontexts'] = ulib['ClassLoaderContexts'].get('any')
# Patch the library name in the CLC as well.
clcs2[ulib['ProvidesUsesLibrary']] = clc
else:
# dexpreopt.config for this <uses-library> is not among the script
# arguments, which may be the case with compatibility libraries that
# don't need patching anyway. Just use the original CLC.
clcs2[lib] = clc
pass
clcs2.append(clc)
clc_map2[sdk_ver] = clcs2
# Overwrite the original class loader context with the patched one.

View File

@ -196,8 +196,8 @@ ifdef LOCAL_DEX_PREOPT
# to load dexpreopt code on device. We should fix this, either by deferring
# dependency computation until the full list of product packages is known, or
# by adding product-specific lists of missing libraries.
my_filtered_optional_uses_libraries := $(filter $(my_filtered_optional_uses_libraries), \
$(PRODUCT_PACKAGES))
my_filtered_optional_uses_libraries := $(filter $(PRODUCT_PACKAGES), \
$(my_filtered_optional_uses_libraries))
ifeq ($(LOCAL_MODULE_CLASS),APPS)
# compatibility libraries are added to class loader context of an app only if
@ -222,10 +222,9 @@ ifdef LOCAL_DEX_PREOPT
my_dexpreopt_libs_compat :=
endif
my_dexpreopt_libs := $(sort \
my_dexpreopt_libs := \
$(LOCAL_USES_LIBRARIES) \
$(my_filtered_optional_uses_libraries) \
)
$(my_filtered_optional_uses_libraries)
# 1: SDK version
# 2: list of libraries
@ -243,14 +242,15 @@ ifdef LOCAL_DEX_PREOPT
# which are special and not handled by dex_preopt_config_merger.py.
#
add_json_class_loader_context = \
$(call add_json_map, $(1)) \
$(call add_json_array, $(1)) \
$(foreach lib, $(2),\
$(call add_json_map, $(lib)) \
$(call add_json_map_anon) \
$(call add_json_str, Name, $(lib)) \
$(call add_json_str, Host, $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar) \
$(call add_json_str, Device, /system/framework/$(lib).jar) \
$(call add_json_map, Subcontexts, ${$}) $(call end_json_map) \
$(call add_json_val, Subcontexts, null) \
$(call end_json_map)) \
$(call end_json_map)
$(call end_json_array)
# Record dex-preopt config.
DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT)