Speed up lunch/tapas/etc. shell utility functions.
1. Combined ~10 calls to the make build system to only one.
We added a phony target "dump-many-vars" to the build system to dump
"<var>=<value>" pairs. We then store the pairs as shell variables.
With this cache get_build_var/get_abs_build_var can just return
the shell variables instead of querying the build system.
2. Prune .git when we search for AndroidProduct.mks.
In internal source tree lunch time was reduced from ~15s to ~1.5s.
Bug: 27429759
Change-Id: I24e88598f6fab598ef26518885fd5e86e71a772d
diff --git a/core/dumpvar.mk b/core/dumpvar.mk
index cfb031f..36fd08a 100644
--- a/core/dumpvar.mk
+++ b/core/dumpvar.mk
@@ -1,3 +1,35 @@
+
+# List of variables we want to print in the build banner.
+print_build_config_vars := \
+ PLATFORM_VERSION_CODENAME \
+ PLATFORM_VERSION \
+ TARGET_PRODUCT \
+ TARGET_BUILD_VARIANT \
+ TARGET_BUILD_TYPE \
+ TARGET_BUILD_APPS \
+ TARGET_ARCH \
+ TARGET_ARCH_VARIANT \
+ TARGET_CPU_VARIANT \
+ TARGET_2ND_ARCH \
+ TARGET_2ND_ARCH_VARIANT \
+ TARGET_2ND_CPU_VARIANT \
+ HOST_ARCH \
+ HOST_2ND_ARCH \
+ HOST_OS \
+ HOST_OS_EXTRA \
+ HOST_CROSS_OS \
+ HOST_CROSS_ARCH \
+ HOST_CROSS_2ND_ARCH \
+ HOST_BUILD_TYPE \
+ BUILD_ID \
+ OUT_DIR
+
+ifeq ($(TARGET_BUILD_PDK),true)
+print_build_config_vars += \
+ TARGET_BUILD_PDK \
+ PDK_FUSION_PLATFORM_ZIP
+endif
+
# ---------------------------------------------------------------
# the setpath shell function in envsetup.sh uses this to figure out
# what to add to the path given the config we have chosen.
@@ -59,38 +91,37 @@
PRINT_BUILD_CONFIG:=
endif
-endif # CALLED_FROM_SETUP
-
-
-ifneq ($(PRINT_BUILD_CONFIG),)
-HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
-$(info ============================================)
-$(info PLATFORM_VERSION_CODENAME=$(PLATFORM_VERSION_CODENAME))
-$(info PLATFORM_VERSION=$(PLATFORM_VERSION))
-$(info TARGET_PRODUCT=$(TARGET_PRODUCT))
-$(info TARGET_BUILD_VARIANT=$(TARGET_BUILD_VARIANT))
-$(info TARGET_BUILD_TYPE=$(TARGET_BUILD_TYPE))
-$(info TARGET_BUILD_APPS=$(TARGET_BUILD_APPS))
-$(info TARGET_ARCH=$(TARGET_ARCH))
-$(info TARGET_ARCH_VARIANT=$(TARGET_ARCH_VARIANT))
-$(info TARGET_CPU_VARIANT=$(TARGET_CPU_VARIANT))
-$(info TARGET_2ND_ARCH=$(TARGET_2ND_ARCH))
-$(info TARGET_2ND_ARCH_VARIANT=$(TARGET_2ND_ARCH_VARIANT))
-$(info TARGET_2ND_CPU_VARIANT=$(TARGET_2ND_CPU_VARIANT))
-$(info HOST_ARCH=$(HOST_ARCH))
-$(info HOST_2ND_ARCH=$(HOST_2ND_ARCH))
-$(info HOST_OS=$(HOST_OS))
-$(info HOST_OS_EXTRA=$(HOST_OS_EXTRA))
-$(info HOST_CROSS_OS=$(HOST_CROSS_OS))
-$(info HOST_CROSS_ARCH=$(HOST_CROSS_ARCH))
-$(info HOST_CROSS_2ND_ARCH=$(HOST_CROSS_2ND_ARCH))
-$(info HOST_BUILD_TYPE=$(HOST_BUILD_TYPE))
-$(info BUILD_ID=$(BUILD_ID))
-$(info OUT_DIR=$(OUT_DIR))
-ifeq ($(TARGET_BUILD_PDK),true)
-$(info TARGET_BUILD_PDK=$(TARGET_BUILD_PDK))
-$(info PDK_FUSION_PLATFORM_ZIP=$(PDK_FUSION_PLATFORM_ZIP))
+ifneq ($(filter report_config,$(DUMP_MANY_VARS)),)
+# Construct the shell commands that print the config banner.
+report_config_sh := echo '============================================';
+report_config_sh += $(foreach v,$(print_build_config_vars),echo '$v=$($(v))';)
+report_config_sh += echo '============================================';
endif
+# Dump mulitple variables to "<var>=<value>" pairs, one per line.
+# The output may be executed as bash script.
+# Input variables:
+# DUMP_MANY_VARS: the list of variable names.
+# DUMP_VAR_PREFIX: an optional prefix of the variable name added to the output.
+# DUMP_MANY_ABS_VARS: the list of abs variable names.
+# DUMP_ABS_VAR_PREFIX: an optional prefix of the abs variable name added to the output.
+.PHONY: dump-many-vars
+dump-many-vars :
+ @$(foreach v, $(filter-out report_config, $(DUMP_MANY_VARS)),\
+ echo "$(DUMP_VAR_PREFIX)$(v)='$($(v))'";)
+ifneq ($(filter report_config, $(DUMP_MANY_VARS)),)
+ @# Construct a special variable for report_config.
+ @# Escape \` to defer the execution of report_config_sh to preserve the line breaks.
+ @echo "$(DUMP_VAR_PREFIX)report_config=\`$(report_config_sh)\`"
+endif
+ @$(foreach v, $(sort $(DUMP_MANY_ABS_VARS)),\
+ echo "$(DUMP_ABS_VAR_PREFIX)$(v)='$(PWD)/$($(v))'";)
+
+endif # CALLED_FROM_SETUP
+
+ifneq ($(PRINT_BUILD_CONFIG),)
+$(info ============================================)
+$(foreach v, $(print_build_config_vars),\
+ $(info $v=$($(v))))
$(info ============================================)
endif
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 4456809..e8fa6a7 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -54,6 +54,8 @@
HOST_OS := darwin
endif
+HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
+
# BUILD_OS is the real host doing the build.
BUILD_OS := $(HOST_OS)
diff --git a/core/product.mk b/core/product.mk
index 4d35704..7043cff 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -23,14 +23,21 @@
# and the .mk suffix) of the product makefile, "<product_name>:" can be
# omitted.
+# Search for AndroidProducts.mks in the given dir.
+# $(1): the path to the dir
+define _search-android-products-files-in-dir
+$(sort $(shell test -d $(1) && find -L $(1) \
+ -maxdepth 6 \
+ -name .git -prune \
+ -o -name AndroidProducts.mk -print))
+endef
+
#
# Returns the list of all AndroidProducts.mk files.
# $(call ) isn't necessary.
#
define _find-android-products-files
-$(sort $(shell test -d device && find -L device -maxdepth 6 -name AndroidProducts.mk)) \
- $(sort $(shell test -d vendor && find -L vendor -maxdepth 6 -name AndroidProducts.mk)) \
- $(sort $(shell test -d product && find -L product -maxdepth 6 -name AndroidProducts.mk)) \
+$(foreach d, device vendor product,$(call _search-android-products-files-in-dir,$(d))) \
$(SRC_TARGET_DIR)/product/AndroidProducts.mk
endef