Check conformity of VNDK version

Allow BOARD_VNDK_VERSION=<version> only if the prebuilt VNDK for
the <version> is provided.

If PRODUCT_EXTRA_VNDK_VERSIONS is set, all the versions in the list
will be checked as well.

Bug: 38304393
Bug: 65377115
Bug: 68123344
Test: Set BOARD_VNDK_VERSION := current and check build
Test: Set PRODUCT_EXTRA_VNDK_VERSIONS := 27 and check if it returns
      error when prebuilts/vndk/v27/Android.mk is not provided

Change-Id: I2e43d71f1ea3717ab8c45de84c926ecc43193307
diff --git a/core/envsetup.mk b/core/envsetup.mk
index ddf903c..c02a5a3 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -285,9 +285,14 @@
 endif
 
 # Check BOARD_VNDK_VERSION
+define check_vndk_version
+  $(eval vndk_path := prebuilts/vndk/v$(1)) \
+  $(if $(wildcard $(vndk_path)/Android.bp),,$(error VNDK version $(1) not found))
+endef
+
 ifdef BOARD_VNDK_VERSION
   ifneq ($(BOARD_VNDK_VERSION),current)
-    $(error BOARD_VNDK_VERSION: Only "current" is implemented)
+    $(call check_vndk_version,$(BOARD_VNDK_VERSION))
   endif
 
   TARGET_VENDOR_TEST_SUFFIX := /vendor
@@ -295,6 +300,10 @@
   TARGET_VENDOR_TEST_SUFFIX :=
 endif
 
+ifdef PRODUCT_EXTRA_VNDK_VERSIONS
+  $(foreach v,$(PRODUCT_EXTRA_VNDK_VERSIONS),$(call check_vndk_version,$(v)))
+endif
+
 # ---------------------------------------------------------------
 # Set up configuration for target machine.
 # The following must be set: