build: Preliminary support for CM product builds

If building a cm_* product, skip crawling the filesystem for
AndroidProduct makefiles (and, of course, parsing their contents)
and aim directly for the device/cm/<product> device configuration

Change-Id: I2a5e70dda973a6fcdbba0d5e26b35b99d3f1aea2

Change how we search for CM makefiles.

build: Fix fastpath code for CM_BUILD

 * We need to adjust to the new validations

Change-Id: I9066d4f437beb9597027ee6bbb52504b5e7e84c5
diff --git a/core/product_config.mk b/core/product_config.mk
index a87d0c6..1cafc89 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -184,11 +184,16 @@
 all_product_configs := $(call get-product-makefiles,\
     $(SRC_TARGET_DIR)/product/AndroidProducts.mk)
 else
-# Read in all of the product definitions specified by the AndroidProducts.mk
-# files in the tree.
-all_product_configs := $(get-all-product-makefiles)
+  ifneq ($(CM_BUILD),)
+    all_product_configs := $(shell ls device/*/$(CM_BUILD)/cm.mk)
+  else
+    # Read in all of the product definitions specified by the AndroidProducts.mk
+    # files in the tree.
+    all_product_configs := $(get-all-product-makefiles)
+  endif
 endif
 
+ifeq ($(CM_BUILD),)
 # Find the product config makefile for the current product.
 # all_product_configs consists items like:
 # <product_name>:<path_to_the_product_makefile>
@@ -207,12 +212,18 @@
         $(eval all_product_makefiles += $(f))\
         $(if $(filter $(TARGET_PRODUCT),$(basename $(notdir $(f)))),\
             $(eval current_product_makefile += $(f)),)))
+
 _cpm_words :=
 _cpm_word1 :=
 _cpm_word2 :=
+else
+    current_product_makefile := $(strip $(all_product_configs))
+    all_product_makefiles := $(strip $(all_product_configs))
+endif
 current_product_makefile := $(strip $(current_product_makefile))
 all_product_makefiles := $(strip $(all_product_makefiles))
 
+
 ifneq (,$(filter product-graph dump-products, $(MAKECMDGOALS)))
 # Import all product makefiles.
 $(call import-products, $(all_product_makefiles))
diff --git a/envsetup.sh b/envsetup.sh
index d126ebc..ae1e4c5 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -72,6 +72,14 @@
         echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
         return
     fi
+
+    if (echo -n $1 | grep -q -e "^cm_") ; then
+       CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
+    else
+       CM_BUILD=
+    fi
+    export CM_BUILD
+
         TARGET_PRODUCT=$1 \
         TARGET_BUILD_VARIANT= \
         TARGET_BUILD_TYPE= \