Refactor *-select-bitness-of-required-modules

* Streamline required module bitness resolution

If a module is for cross host OS, the required modules are also for that
OS.
Otherwise if the requirer module is native and the required module is
shared library or native test, then the required module resolves to the
same bitness.
Otherwise the required module resolves to both variants, if they exist.

* Factor out the common logic and merge
  <target|host|host-cross>-select-bitness-of-required-modules

This lays the road for follow-up changes to add bitness suffix support.
This slightly reduces readibility. To make up for the loss, the
bitness-resolving logic is easier to maintain since we don't have
multiple copies of *-select-bitness-of-required-modules.

Bug: 155869107
Test: check the diff of product_target_FILES and product_host_FILES
Test: check the diff of ALL_MODULES.*.REQUIRED_FROM_(TARGET|HOST)
Change-Id: Ib2f4b548535e983d621dad71cb920101111140f2
This commit is contained in:
Yo Chiang 2020-06-03 17:03:26 +08:00
parent 5638065faa
commit 1b8283358e
1 changed files with 42 additions and 58 deletions

View File

@ -551,6 +551,13 @@ ifneq ($(PRODUCT_ENFORCE_RRO_TARGETS),)
$(call generate_all_enforce_rro_packages) $(call generate_all_enforce_rro_packages)
endif endif
# -------------------------------------------------------------------
# Sort ALL_MODULES to remove duplicate entries.
# -------------------------------------------------------------------
ALL_MODULES := $(sort $(ALL_MODULES))
# Cannot set to readonly because Makefile extends ALL_MODULES
# .KATI_READONLY := ALL_MODULES
# ------------------------------------------------------------------- # -------------------------------------------------------------------
# Fix up CUSTOM_MODULES to refer to installed files rather than # Fix up CUSTOM_MODULES to refer to installed files rather than
# just bare module names. Leave unknown modules alone in case # just bare module names. Leave unknown modules alone in case
@ -618,65 +625,43 @@ $(sort $(foreach m,$(1),\
$(m)))) $(m))))
endef endef
# If a module is for a cross host os, the required modules must be for # TODO(b/7456955): error if a required module doesn't exist.
# that OS too. # Resolve the required module names in ALL_MODULES.*.REQUIRED_FROM_TARGET,
# If a module is built for 32-bit, the required modules must be 32-bit too; # ALL_MODULES.*.REQUIRED_FROM_HOST and ALL_MODULES.*.REQUIRED_FROM_HOST_CROSS
# Otherwise if the module is an executable or shared library, # to 32-bit or 64-bit variant.
# the required modules must be 64-bit; # If a module is for cross host OS, the required modules are also for that OS.
# otherwise we require both 64-bit and 32-bit variant, if one exists. # Otherwise if the requiring module is native and the required module is shared
define target-select-bitness-of-required-modules # library or native test, then the required module resolves to the same bitness.
$(foreach m,$(ALL_MODULES),\ # Otherwise the required module resolves to both variants, if they exist.
$(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_TARGET))\ # $(1): TARGET, HOST or HOST_CROSS
$(if $(r),\ define select-bitness-of-required-modules
$(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\ $(foreach m,$(ALL_MODULES), \
$(eval r_r := $(call get-32-bit-modules-if-we-can,$(r))),\ $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_$(1))) \
$(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS)),\ $(if $(r), \
$(eval r_r := $(r)),\ $(if $(filter HOST_CROSS,$(1)), \
$(eval r_r := $(r) $(call get-32-bit-modules,$(r)))\ $(if $(ALL_MODULES.$(m).FOR_HOST_CROSS),,$(error Only expected REQUIRED_FROM_HOST_CROSS on FOR_HOST_CROSS modules - $(m))) \
)\ $(eval r := $(addprefix host_cross_,$(r)))) \
)\ $(eval module_is_native := \
$(eval ALL_MODULES.$(m).REQUIRED_FROM_TARGET := $(strip $(r_r)))\ $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS))) \
)\ $(eval r_r := $(foreach r_i,$(r), \
$(eval r_m := \
$(eval r_i_2nd := $(call get-modules-for-2nd-arch,$(1),$(r_i))) \
$(eval required_is_shared_library_or_native_test := \
$(filter SHARED_LIBRARIES NATIVE_TESTS, \
$(ALL_MODULES.$(r_i).CLASS) $(ALL_MODULES.$(r_i_2nd).CLASS))) \
$(if $(and $(module_is_native),$(required_is_shared_library_or_native_test)), \
$(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),$(r_i_2nd),$(r_i)), \
$(r_i) $(r_i_2nd))) \
$(eval ### TODO(b/7456955): error if r_m is empty / does not exist) \
$(r_m))) \
$(eval ALL_MODULES.$(m).REQUIRED_FROM_$(1) := $(sort $(r_r))) \
) \
) )
endef endef
$(call target-select-bitness-of-required-modules)
define host-select-bitness-of-required-modules $(call select-bitness-of-required-modules,TARGET)
$(foreach m,$(ALL_MODULES),\ $(call select-bitness-of-required-modules,HOST)
$(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_HOST))\ $(call select-bitness-of-required-modules,HOST_CROSS)
$(if $(r),\
$(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
$(eval r_r := $(call get-host-32-bit-modules-if-we-can,$(r))),\
$(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS)),\
$(eval r_r := $(r)),\
$(eval r_r := $(r) $(call get-host-32-bit-modules,$(r)))\
)\
)\
$(eval ALL_MODULES.$(m).REQUIRED_FROM_HOST := $(strip $(r_r)))\
)\
)
endef
$(call host-select-bitness-of-required-modules)
define host-cross-select-bitness-of-required-modules
$(foreach m,$(ALL_MODULES),\
$(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_HOST_CROSS))\
$(if $(r),\
$(if $(ALL_MODULES.$(m).FOR_HOST_CROSS),,$(error Only expected REQUIRED_FROM_HOST_CROSS on FOR_HOST_CROSS modules - $(m)))\
$(eval r := $(addprefix host_cross_,$(r)))\
$(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
$(eval r_r := $(call get-host-32-bit-modules-if-we-can,$(r))),\
$(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS)),\
$(eval r_r := $(r)),\
$(eval r_r := $(r) $(call get-host-32-bit-modules,$(r)))\
)\
)\
$(eval ALL_MODULES.$(m).REQUIRED_FROM_HOST_CROSS := $(strip $(r_r)))\
)\
)
endef
$(call host-cross-select-bitness-of-required-modules)
r_r :=
define add-required-deps define add-required-deps
$(1): | $(2) $(1): | $(2)
@ -1181,8 +1166,7 @@ endef
# foo resolves to both foo and foo_32 (if foo_32 is defined). # foo resolves to both foo and foo_32 (if foo_32 is defined).
# #
# Name resolution for LOCAL_REQUIRED_MODULES: # Name resolution for LOCAL_REQUIRED_MODULES:
# If a module is built for 2nd arch, its required module resolves to # See the select-bitness-of-required-modules definition.
# 32-bit variant, if it exits. See the select-bitness-of-required-modules definition.
# $(1): product makefile # $(1): product makefile
define product-installed-files define product-installed-files
$(eval _pif_modules := \ $(eval _pif_modules := \