Merge "Merge Android 12L"
diff --git a/core/product.mk b/core/product.mk
index 43724a8..60b2dc9 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -14,98 +14,6 @@
# 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.
# - The value set in the current makefile takes precedence over inherited values
# - If multiple inherited makefiles set the var, the first-inherited value wins
diff --git a/core/product_config.mk b/core/product_config.mk
index 1deb39b..be4aded 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -146,32 +146,73 @@
include $(BUILD_SYSTEM)/product.mk
include $(BUILD_SYSTEM)/device.mk
-# Read in all of the product definitions specified by the AndroidProducts.mk
-# files in the tree.
-all_product_configs := $(get-all-product-makefiles)
+# Read all product definitions.
+#
+# 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
+# STARLARK_OPT_IN_PRODUCTS specifies products to use Starlark-based
+# product configuration by default
-# Find the product config makefile for the current product.
-# all_product_configs consists items like:
-# <product_name>:<path_to_the_product_makefile>
-# or just <path_to_the_product_makefile> in case the product name is the
-# same as the base filename of the product config makefile.
-current_product_makefile :=
-all_product_makefiles :=
-$(foreach f, $(all_product_configs),\
- $(eval _cpm_words := $(call _decode-product-name,$(f)))\
- $(eval _cpm_word1 := $(word 1,$(_cpm_words)))\
- $(eval _cpm_word2 := $(word 2,$(_cpm_words)))\
- $(eval all_product_makefiles += $(_cpm_word2))\
- $(eval all_named_products += $(_cpm_word1))\
- $(if $(filter $(TARGET_PRODUCT),$(_cpm_word1)),\
- $(eval current_product_makefile += $(_cpm_word2)),))
-_cpm_words :=
-_cpm_word1 :=
-_cpm_word2 :=
-current_product_makefile := $(strip $(current_product_makefile))
-all_product_makefiles := $(strip $(all_product_makefiles))
+# Builds a list of first/second elements of each pair:
+# $(call _first,a:A b:B,:) returns 'a b'
+# $(call _second,a-A b-B,-) returns 'A B'
+_first=$(filter-out $(2)%,$(subst $(2),$(space)$(2),$(1)))
+_second=$(filter-out %$(2),$(subst $(2),$(2)$(space),$(1)))
+
+# Returns <product>:<path> pair from a PRODUCT_MAKEFILE item.
+# If an item is <product>:path/to/file.mk, return it as is,
+# otherwise assume that an item is path/to/<product>.mk and
+# return <product>:path/to/<product>.mk
+_product-spec=$(strip $(if $(findstring :,$(1)),$(1),$(basename $(notdir $(1))):$(1)))
+
+# Reads given AndroidProduct.mk file and sets the following variables:
+# ap_product_paths -- the list of <product>:<path> pairs
+# ap_common_lunch_choices -- the list of <product>-<build variant> items
+# ap_products_using_starlark_config -- the list of products using starlark config
+# In addition, validates COMMON_LUNCH_CHOICES and STARLARK_OPT_IN_PRODUCTS values
+define _read-ap-file
+ $(eval PRODUCT_MAKEFILES :=) \
+ $(eval COMMON_LUNCH_CHOICES :=) \
+ $(eval STARLARK_OPT_IN_PRODUCTS := ) \
+ $(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 ap_products_using_starlark_config := $(STARLARK_OPT_IN_PRODUCTS)) \
+ $(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)))
+ $(eval _bad := $(filter-out $(_products),$(ap_products_using_starlark_config))) \
+ $(if $(_bad),$(error STARLARK_OPT_IN_PRODUCTS contains product(s) not defined in this file: $(_bad)))
+endef
+
+# Build cumulative lists of all product specs/lunch choices/Starlark-based products.
+product_paths :=
+common_lunch_choices :=
+products_using_starlark_config :=
+$(foreach f,$(android_products_makefiles), \
+ $(call _read-ap-file,$(f)) \
+ $(eval product_paths += $(ap_product_paths)) \
+ $(eval common_lunch_choices += $(ap_common_lunch_choices)) \
+ $(eval products_using_starlark_config += $(ap_products_using_starlark_config)) \
+)
+
+# 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 :=
ifneq (,$(filter product-graph, $(MAKECMDGOALS)))
@@ -195,11 +236,10 @@
$(call import-products, $(all_product_makefiles))
else
# Import just the current product.
-ifndef current_product_makefile
-$(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))
+$(if $(current_product_makefile),,$(error Can not locate config makefile for product "$(TARGET_PRODUCT)"))
+ifneq (,$(filter $(TARGET_PRODUCT),$(products_using_starlark_config)))
+ RBC_PRODUCT_CONFIG := true
+ RBC_BOARD_CONFIG := true
endif
ifndef RBC_PRODUCT_CONFIG
diff --git a/core/soong_config.mk b/core/soong_config.mk
index c24df60..fd957c3 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -119,6 +119,7 @@
$(call add_json_bool, GcovCoverage, $(filter true,$(NATIVE_COVERAGE)))
$(call add_json_bool, ClangCoverage, $(filter true,$(CLANG_COVERAGE)))
+$(call add_json_bool, ClangCoverageContinuousMode, $(filter true,$(CLANG_COVERAGE_CONTINUOUS_MODE)))
$(call add_json_list, NativeCoveragePaths, $(NATIVE_COVERAGE_PATHS))
$(call add_json_list, NativeCoverageExcludePaths, $(NATIVE_COVERAGE_EXCLUDE_PATHS))