Merge "Start moving add_lunch_combo to Make"

This commit is contained in:
Treehugger Robot 2018-04-05 03:14:07 +00:00 committed by Gerrit Code Review
commit a975fe9c24
4 changed files with 70 additions and 22 deletions

View file

@ -41,21 +41,68 @@ $(foreach d, device vendor product,$(call _search-android-products-files-in-dir,
$(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) $(LUNCH_MENU_CHOICES))) \
$(eval _COMMON_LUNCH_CHOICES :=) \
)
endef

View file

@ -195,18 +195,13 @@ all_named_products :=
current_product_makefile :=
all_product_makefiles :=
$(foreach f, $(all_product_configs),\
$(eval _cpm_words := $(subst :,$(space),$(f)))\
$(eval _cpm_words := $(call _decode-product-name,$(f)))\
$(eval _cpm_word1 := $(word 1,$(_cpm_words)))\
$(eval _cpm_word2 := $(word 2,$(_cpm_words)))\
$(if $(_cpm_word2),\
$(eval all_product_makefiles += $(_cpm_word2))\
$(eval all_named_products += $(_cpm_word1))\
$(if $(filter $(TARGET_PRODUCT),$(_cpm_word1)),\
$(eval current_product_makefile += $(_cpm_word2)),),\
$(eval all_product_makefiles += $(f))\
$(eval all_named_products += $(basename $(notdir $(f))))\
$(if $(filter $(TARGET_PRODUCT),$(basename $(notdir $(f)))),\
$(eval current_product_makefile += $(f)),)))
$(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 :=

View file

@ -543,14 +543,6 @@ function add_lunch_combo()
LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
}
# add the default one here
add_lunch_combo aosp_arm-eng
add_lunch_combo aosp_arm64-eng
add_lunch_combo aosp_mips-eng
add_lunch_combo aosp_mips64-eng
add_lunch_combo aosp_x86-eng
add_lunch_combo aosp_x86_64-eng
function print_lunch_menu()
{
local uname=$(uname)
@ -561,7 +553,7 @@ function print_lunch_menu()
local i=1
local choice
for choice in ${LUNCH_MENU_CHOICES[@]}
for choice in $(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
do
echo " $i. $choice"
i=$(($i+1))
@ -589,9 +581,10 @@ function lunch()
selection=aosp_arm-eng
elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
then
if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
if [ $answer -le ${#choices[@]} ]
then
selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
selection=${choices[$(($answer-1))]}
fi
else
selection=$answer
@ -642,6 +635,7 @@ function lunch()
destroy_build_var_cache
}
unset COMMON_LUNCH_CHOICES_CACHE
# Tab completion for lunch.
function _lunch()
{
@ -650,7 +644,11 @@ function _lunch()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
fi
COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
return 0
}
complete -F _lunch lunch

View file

@ -79,3 +79,11 @@ PRODUCT_MAKEFILES := \
$(LOCAL_DIR)/sdk_arm64.mk \
$(LOCAL_DIR)/sdk_x86_64.mk
endif
COMMON_LUNCH_CHOICES := \
aosp_arm-eng \
aosp_arm64-eng \
aosp_mips-eng \
aosp_mips64-eng \
aosp_x86-eng \
aosp_x86_64-eng