brillo_config: pull PRODUCT_VERSION from cfgtree

Add support to read the product version from
  config/brillo/product_version

(cherry picked from commit f01bc2175998a3d13e47dc6afe913ae8f036a89e)
BUG=25516395

Change-Id: Id1277112ce7f7c89c9d984ff372bc43007d41016
diff --git a/brillo_config/Android.mk b/brillo_config/Android.mk
index 87ea7cb..8946e78 100644
--- a/brillo_config/Android.mk
+++ b/brillo_config/Android.mk
@@ -40,9 +40,18 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
 include $(BUILD_SYSTEM)/base_rules.mk
 
-# The version is set to 0.0.0 if the user did not set the actual version.
+
+# The version is set to 0.0.0 if the user did not set the actual version and
+# a version cannot be loaded from the product cfgtree.
 # This allows us to have a valid version number while being easy to filter.
-BRILLO_PRODUCT_VERSION ?= "0.0.0"
+ifeq ($(BRILLO_PRODUCT_VERSION),)
+# Load from file first
+BRILLO_PRODUCT_VERSION := $(call cfgtree-get-if-exists,brillo/product_version)
+endif
+# If the version is still empty, override it with 0.0.0
+ifeq ($(BRILLO_PRODUCT_VERSION),)
+BRILLO_PRODUCT_VERSION := "0.0.0"
+endif
 ifeq ($(shell echo $(BRILLO_PRODUCT_VERSION) | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$$'),)
 $(error Invalid BRILLO_PRODUCT_VERSION "$(BRILLO_PRODUCT_VERSION)", must be \
   three numbers separated by dots. Example: "1.2.0")