Clean up product definitions reading.
Bug: 220379303 Test: treehugger Change-Id: I6b9b3bd486a1680ace8278eb5160e09885543f4b
This commit is contained in:
@@ -14,98 +14,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# Functions for including AndroidProducts.mk files
|
|
||||||
# PRODUCT_MAKEFILES is set up in AndroidProducts.mks.
|
|
||||||
# Format of PRODUCT_MAKEFILES:
|
|
||||||
# <product_name>:<path_to_the_product_makefile>
|
|
||||||
# If the <product_name> is the same as the base file name (without dir
|
|
||||||
# and the .mk suffix) of the product makefile, "<product_name>:" can be
|
|
||||||
# omitted.
|
|
||||||
|
|
||||||
#
|
|
||||||
# Returns the list of all AndroidProducts.mk files.
|
|
||||||
# $(call ) isn't necessary.
|
|
||||||
#
|
|
||||||
define _find-android-products-files
|
|
||||||
$(file <$(OUT_DIR)/.module_paths/AndroidProducts.mk.list) \
|
|
||||||
$(SRC_TARGET_DIR)/product/AndroidProducts.mk
|
|
||||||
endef
|
|
||||||
|
|
||||||
#
|
|
||||||
# For entries returned by get-product-makefiles, decode an entry to a short
|
|
||||||
# product name. These either may be in the form of <name>:path/to/file.mk or
|
|
||||||
# path/to/<name>.mk
|
|
||||||
# $(1): The entry to decode
|
|
||||||
#
|
|
||||||
# Returns two words:
|
|
||||||
# <name> <file>
|
|
||||||
#
|
|
||||||
define _decode-product-name
|
|
||||||
$(strip \
|
|
||||||
$(eval _cpm_words := $(subst :,$(space),$(1))) \
|
|
||||||
$(if $(word 2,$(_cpm_words)), \
|
|
||||||
$(wordlist 1,2,$(_cpm_words)), \
|
|
||||||
$(basename $(notdir $(1))) $(1)))
|
|
||||||
endef
|
|
||||||
|
|
||||||
#
|
|
||||||
# Validates the new common lunch choices -- ensures that they're in an
|
|
||||||
# appropriate form, and are paired with definitions of their products.
|
|
||||||
# $(1): The new list of COMMON_LUNCH_CHOICES
|
|
||||||
# $(2): The new list of PRODUCT_MAKEFILES
|
|
||||||
#
|
|
||||||
define _validate-common-lunch-choices
|
|
||||||
$(strip $(foreach choice,$(1),\
|
|
||||||
$(eval _parts := $(subst -,$(space),$(choice))) \
|
|
||||||
$(if $(call math_lt,$(words $(_parts)),2), \
|
|
||||||
$(error $(LOCAL_DIR): $(choice): Invalid lunch choice)) \
|
|
||||||
$(if $(call math_gt_or_eq,$(words $(_parts)),4), \
|
|
||||||
$(error $(LOCAL_DIR): $(choice): Invalid lunch choice)) \
|
|
||||||
$(if $(filter-out eng userdebug user,$(word 2,$(_parts))), \
|
|
||||||
$(error $(LOCAL_DIR): $(choice): Invalid variant: $(word 2,$(_parts)))) \
|
|
||||||
$(if $(filter-out $(foreach p,$(2),$(call _decode-product-name,$(p))),$(word 1,$(_parts))), \
|
|
||||||
$(error $(LOCAL_DIR): $(word 1,$(_parts)): Product not defined in this file)) \
|
|
||||||
))
|
|
||||||
endef
|
|
||||||
|
|
||||||
#
|
|
||||||
# Returns the sorted concatenation of PRODUCT_MAKEFILES
|
|
||||||
# variables set in the given AndroidProducts.mk files.
|
|
||||||
# $(1): the list of AndroidProducts.mk files.
|
|
||||||
#
|
|
||||||
# As a side-effect, COMMON_LUNCH_CHOICES will be set to a
|
|
||||||
# union of all of the COMMON_LUNCH_CHOICES definitions within
|
|
||||||
# each AndroidProducts.mk file.
|
|
||||||
#
|
|
||||||
define get-product-makefiles
|
|
||||||
$(sort \
|
|
||||||
$(eval _COMMON_LUNCH_CHOICES :=) \
|
|
||||||
$(foreach f,$(1), \
|
|
||||||
$(eval PRODUCT_MAKEFILES :=) \
|
|
||||||
$(eval COMMON_LUNCH_CHOICES :=) \
|
|
||||||
$(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
|
|
||||||
$(eval include $(f)) \
|
|
||||||
$(call _validate-common-lunch-choices,$(COMMON_LUNCH_CHOICES),$(PRODUCT_MAKEFILES)) \
|
|
||||||
$(eval _COMMON_LUNCH_CHOICES += $(COMMON_LUNCH_CHOICES)) \
|
|
||||||
$(PRODUCT_MAKEFILES) \
|
|
||||||
) \
|
|
||||||
$(eval PRODUCT_MAKEFILES :=) \
|
|
||||||
$(eval LOCAL_DIR :=) \
|
|
||||||
$(eval COMMON_LUNCH_CHOICES := $(sort $(_COMMON_LUNCH_CHOICES))) \
|
|
||||||
$(eval _COMMON_LUNCH_CHOICES :=) \
|
|
||||||
)
|
|
||||||
endef
|
|
||||||
|
|
||||||
#
|
|
||||||
# Returns the sorted concatenation of all PRODUCT_MAKEFILES
|
|
||||||
# variables set in all AndroidProducts.mk files.
|
|
||||||
# $(call ) isn't necessary.
|
|
||||||
#
|
|
||||||
define get-all-product-makefiles
|
|
||||||
$(call get-product-makefiles,$(_find-android-products-files))
|
|
||||||
endef
|
|
||||||
|
|
||||||
# Variables that are meant to hold only a single value.
|
# Variables that are meant to hold only a single value.
|
||||||
# - The value set in the current makefile takes precedence over inherited values
|
# - The value set in the current makefile takes precedence over inherited values
|
||||||
# - If multiple inherited makefiles set the var, the first-inherited value wins
|
# - If multiple inherited makefiles set the var, the first-inherited value wins
|
||||||
|
@@ -146,32 +146,64 @@ include $(BUILD_SYSTEM)/node_fns.mk
|
|||||||
include $(BUILD_SYSTEM)/product.mk
|
include $(BUILD_SYSTEM)/product.mk
|
||||||
include $(BUILD_SYSTEM)/device.mk
|
include $(BUILD_SYSTEM)/device.mk
|
||||||
|
|
||||||
# Read in all of the product definitions specified by the AndroidProducts.mk
|
# Read all product definitions.
|
||||||
# files in the tree.
|
#
|
||||||
all_product_configs := $(get-all-product-makefiles)
|
# Products are defined in AndroidProducts.mk files:
|
||||||
|
android_products_makefiles := $(file <$(OUT_DIR)/.module_paths/AndroidProducts.mk.list) \
|
||||||
|
$(SRC_TARGET_DIR)/product/AndroidProducts.mk
|
||||||
|
|
||||||
all_named_products :=
|
# An AndroidProduct.mk file sets the following variables:
|
||||||
|
# PRODUCT_MAKEFILES specifies product makefiles. Each item in this list
|
||||||
|
# is either a <product>:path/to/file.mk, or just path/to/<product.mk>
|
||||||
|
# COMMON_LUNCH_CHOICES specifies <product>-<variant> values to be shown
|
||||||
|
# in the `lunch` menu
|
||||||
|
|
||||||
# Find the product config makefile for the current product.
|
# Builds a list of first/second elements of each pair:
|
||||||
# all_product_configs consists items like:
|
# $(call _first,a:A b:B,:) returns 'a b'
|
||||||
# <product_name>:<path_to_the_product_makefile>
|
# $(call _second,a-A b-B,-) returns 'A B'
|
||||||
# or just <path_to_the_product_makefile> in case the product name is the
|
_first=$(filter-out $(2)%,$(subst $(2),$(space)$(2),$(1)))
|
||||||
# same as the base filename of the product config makefile.
|
_second=$(filter-out %$(2),$(subst $(2),$(2)$(space),$(1)))
|
||||||
current_product_makefile :=
|
|
||||||
all_product_makefiles :=
|
# Returns <product>:<path> pair from a PRODUCT_MAKEFILE item.
|
||||||
$(foreach f, $(all_product_configs),\
|
# If an item is <product>:path/to/file.mk, return it as is,
|
||||||
$(eval _cpm_words := $(call _decode-product-name,$(f)))\
|
# otherwise assume that an item is path/to/<product>.mk and
|
||||||
$(eval _cpm_word1 := $(word 1,$(_cpm_words)))\
|
# return <product>:path/to/<product>.mk
|
||||||
$(eval _cpm_word2 := $(word 2,$(_cpm_words)))\
|
_product-spec=$(strip $(if $(findstring :,$(1)),$(1),$(basename $(notdir $(1))):$(1)))
|
||||||
$(eval all_product_makefiles += $(_cpm_word2))\
|
|
||||||
$(eval all_named_products += $(_cpm_word1))\
|
# Reads given AndroidProduct.mk file and sets the following variables:
|
||||||
$(if $(filter $(TARGET_PRODUCT),$(_cpm_word1)),\
|
# ap_product_paths -- the list of <product>:<path> pairs
|
||||||
$(eval current_product_makefile += $(_cpm_word2)),))
|
# ap_common_lunch_choices -- the list of <product>-<build variant> items
|
||||||
_cpm_words :=
|
# In addition, validates COMMON_LUNCH_CHOICES values
|
||||||
_cpm_word1 :=
|
define _read-ap-file
|
||||||
_cpm_word2 :=
|
$(eval PRODUCT_MAKEFILES :=) \
|
||||||
current_product_makefile := $(strip $(current_product_makefile))
|
$(eval COMMON_LUNCH_CHOICES :=) \
|
||||||
all_product_makefiles := $(strip $(all_product_makefiles))
|
$(eval ap_product_paths :=) \
|
||||||
|
$(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
|
||||||
|
$(eval include $(f)) \
|
||||||
|
$(foreach p, $(PRODUCT_MAKEFILES),$(eval ap_product_paths += $(call _product-spec,$(p)))) \
|
||||||
|
$(eval ap_common_lunch_choices := $(COMMON_LUNCH_CHOICES)) \
|
||||||
|
$(eval _products := $(call _first,$(ap_product_paths),:)) \
|
||||||
|
$(eval _bad := $(filter-out $(_products),$(call _first,$(ap_common_lunch_choices),-))) \
|
||||||
|
$(if $(_bad),$(error COMMON_LUNCH_CHOICES contains products(s) not defined in this file: $(_bad))) \
|
||||||
|
$(eval _bad := $(filter-out %-eng %-userdebug %-user,$(ap_common_lunch_choices))) \
|
||||||
|
$(if $(_bad),$(error invalid variant in COMMON_LUNCH_CHOICES: $(_bad)))
|
||||||
|
endef
|
||||||
|
|
||||||
|
# Build cumulative lists of all product specs/lunch choices
|
||||||
|
product_paths :=
|
||||||
|
common_lunch_choices :=
|
||||||
|
$(foreach f,$(android_products_makefiles), \
|
||||||
|
$(call _read-ap-file,$(f)) \
|
||||||
|
$(eval product_paths += $(ap_product_paths)) \
|
||||||
|
$(eval common_lunch_choices += $(ap_common_lunch_choices)) \
|
||||||
|
)
|
||||||
|
|
||||||
|
# Dedup, extract product names, etc.
|
||||||
|
product_paths :=$(sort $(product_paths))
|
||||||
|
all_named_products := $(call _first,$(product_paths),:)
|
||||||
|
all_product_makefiles := $(call _second,$(product_paths),:)
|
||||||
|
current_product_makefile := $(call _second,$(filter $(TARGET_PRODUCT):%,$(product_paths)),:)
|
||||||
|
COMMON_LUNCH_CHOICES := $(sort $(common_lunch_choices))
|
||||||
|
|
||||||
load_all_product_makefiles :=
|
load_all_product_makefiles :=
|
||||||
ifneq (,$(filter product-graph, $(MAKECMDGOALS)))
|
ifneq (,$(filter product-graph, $(MAKECMDGOALS)))
|
||||||
@@ -195,13 +227,7 @@ ifeq ($(load_all_product_makefiles),true)
|
|||||||
$(call import-products, $(all_product_makefiles))
|
$(call import-products, $(all_product_makefiles))
|
||||||
else
|
else
|
||||||
# Import just the current product.
|
# Import just the current product.
|
||||||
ifndef current_product_makefile
|
$(if $(current_product_makefile),,$(error Can not locate config makefile for product "$(TARGET_PRODUCT)"))
|
||||||
$(error Can not locate config makefile for product "$(TARGET_PRODUCT)")
|
|
||||||
endif
|
|
||||||
ifneq (1,$(words $(current_product_makefile)))
|
|
||||||
$(error Product "$(TARGET_PRODUCT)" ambiguous: matches $(current_product_makefile))
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef RBC_PRODUCT_CONFIG
|
ifndef RBC_PRODUCT_CONFIG
|
||||||
$(call import-products, $(current_product_makefile))
|
$(call import-products, $(current_product_makefile))
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user