Strengthen dependencies on LOCAL_REQUIRED_MODULES
Bug: 6418863
This change expands the PRODUCT_PACKAGES with the required modules.
Before this change, since the required modules are not in the
PRODUCT_PACKAGES, they are not directly depended on by the image files.
If the dependent is not to be included in the image but the required
modules are to be included, the dependency of the image on the required
modules gets lost!
That would lead to build race condition.
Change-Id: I0b656db1538ca43d3785dbf17364ffa88b80ac41
diff --git a/core/definitions.mk b/core/definitions.mk
index 9943d5f..f82bfa5 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1999,6 +1999,19 @@
,)
endef
+###########################################################
+## Expand a module name list with REQUIRED modules
+###########################################################
+# $(1): The variable name that holds the initial module name list.
+# the variable will be modified to hold the expanded results.
+# $(2): The initial module name list.
+# Returns empty string (maybe with some whitespaces).
+define expand-required-modules
+$(eval _erm_new_modules := $(sort $(filter-out $($(1)),\
+ $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED)))))\
+$(if $(_erm_new_modules),$(eval $(1) += $(_erm_new_modules))\
+ $(call expand-required-modules,$(1),$(_erm_new_modules)))
+endef
###########################################################
## Other includes