Move from WITH_ART to PRODUCT_RUNTIMES

Change-Id: I3a9217b4aafc1f59d095169deb9eaeae17320505
diff --git a/buildspec.mk.default b/buildspec.mk.default
index 397194c..6f9e755 100644
--- a/buildspec.mk.default
+++ b/buildspec.mk.default
@@ -104,9 +104,15 @@
 #ENABLE_SVG:=false
 endif
 
-# To enable ART define WITH_ART:=true
-ifndef WITH_ART
-#WITH_ART:=true
+# OVERRIDE_RUNTIMES allows you to locally override PRODUCT_RUNTIMES.
+#
+# To only build ART, use "runtime_libart_default"
+# To use Dalvik but also include ART, use "runtime_libdvm_default runtime_libart"
+# To use ART but also include Dalvik, use "runtime_libart_default runtime_libdvm"
+ifndef OVERRIDE_RUNTIMES
+#OVERRIDE_RUNTIMES:=runtime_libart_default
+#OVERRIDE_RUNTIMES:=runtime_libdvm_default runtime_libart
+#OVERRIDE_RUNTIMES:=runtime_libart_default runtime_libdvm
 endif
 
 # when the build system changes such that this file must be updated, this
diff --git a/core/config.mk b/core/config.mk
index e7ee49f..beb4b31 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -123,7 +123,7 @@
 
 # ---------------------------------------------------------------
 # Try to include buildspec.mk, which will try to set stuff up.
-# If this file doesn't exist, the environemnt variables will
+# If this file doesn't exist, the environment variables will
 # be used, and if that doesn't work, then the default is an
 # arm build
 ifndef ANDROID_BUILDSPEC
diff --git a/core/product.mk b/core/product.mk
index bbd0c31..89bce1d 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -95,7 +95,8 @@
     PRODUCT_RESTRICT_VENDOR_FILES \
     PRODUCT_VENDOR_KERNEL_HEADERS \
     PRODUCT_FACTORY_RAMDISK_MODULES \
-    PRODUCT_FACTORY_BUNDLE_MODULES
+    PRODUCT_FACTORY_BUNDLE_MODULES \
+    PRODUCT_RUNTIMES
 
 
 define dump-product
diff --git a/core/product_config.mk b/core/product_config.mk
index c8955f6..5c6975e 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -170,10 +170,6 @@
 endif
 endif
 
-ifeq ($(WITH_ART),)
-  WITH_ART := false
-endif
-
 # ---------------------------------------------------------------
 # Include the product definitions.
 # We need to do this to translate TARGET_PRODUCT into its
@@ -356,11 +352,6 @@
 PRODUCT_VENDOR_KERNEL_HEADERS := \
     $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_KERNEL_HEADERS)
 
-# Add the product-defined properties to the build properties.
-ADDITIONAL_BUILD_PROPERTIES := \
-    $(ADDITIONAL_BUILD_PROPERTIES) \
-    $(PRODUCT_PROPERTY_OVERRIDES)
-
 # The OTA key(s) specified by the product config, if any.  The names
 # of these keys are stored in the target-files zip so that post-build
 # signing tools can substitute them for the test key embedded by
@@ -370,3 +361,29 @@
 
 PRODUCT_EXTRA_RECOVERY_KEYS := $(sort \
     $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_EXTRA_RECOVERY_KEYS))
+
+# Set PRODUCT_RUNTIME, allowing buildspec to override using OVERRIDE_RUNTIMES
+PRODUCT_RUNTIMES := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_RUNTIMES))
+ifneq ($(OVERRIDE_RUNTIMES),)
+    $(info Overriding PRODUCT_RUNTIMES=$(PRODUCT_RUNTIMES) with $(OVERRIDE_RUNTIMES))
+    PRODUCT_RUNTIMES := $(OVERRIDE_RUNTIMES)
+endif
+$(foreach runtime, $(PRODUCT_RUNTIMES), $(eval include $(SRC_TARGET_DIR)/product/$(runtime).mk))
+PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES += $(PRODUCT_PACKAGES)
+PRODUCT_PACKAGES :=
+
+# Add the product-defined properties to the build properties.
+#
+# Note that PRODUCT_PROPERTY_OVERRIDES can be extended by processing
+# the PRODUCT_PACKAGES which is why this is below that.
+#
+ADDITIONAL_BUILD_PROPERTIES := \
+    $(ADDITIONAL_BUILD_PROPERTIES) \
+    $(PRODUCT_PROPERTY_OVERRIDES)
+
+# ************************************************************************ 
+# ADD NEW PRODUCT_* VARIABLES ABOVE PRODUCT_RUNTIMES
+#
+# This is because including the PRODUCT_RUNTIMES can add to other
+# PRODUCT_* variables.
+# ************************************************************************ 
diff --git a/target/product/core_minimal.mk b/target/product/core_minimal.mk
index 3dab1a9..cf499cb 100644
--- a/target/product/core_minimal.mk
+++ b/target/product/core_minimal.mk
@@ -57,5 +57,6 @@
     sensorservice \
     uiautomator
 
+PRODUCT_RUNTIMES := runtime_libdvm_default
+
 $(call inherit-product, $(SRC_TARGET_DIR)/product/base.mk)
-$(call inherit-product, $(SRC_TARGET_DIR)/product/dalvikvm.mk)
diff --git a/target/product/dalvikvm.mk b/target/product/runtime_common.mk
similarity index 73%
rename from target/product/dalvikvm.mk
rename to target/product/runtime_common.mk
index beed32b..8b12bf6 100644
--- a/target/product/dalvikvm.mk
+++ b/target/product/runtime_common.mk
@@ -14,21 +14,7 @@
 # limitations under the License.
 #
 
-# Provides a functioning dalvikvm without Android frameworks
-
-ifeq ($(WITH_ART),false)
-    PRODUCT_PACKAGES += \
-        core \
-        libdvm \
-        dexopt
-else
-    PRODUCT_PACKAGES += \
-        core-libart \
-        libart \
-        dex2oat
-    PRODUCT_PROPERTY_OVERRIDES += \
-        dalvik.vm.lib=libart.so
-endif
+# Common runtime modules for both Dalvik and ART
 
 PRODUCT_PACKAGES += \
     apache-xml \
@@ -57,13 +43,6 @@
 
 # host-only dependencies
 ifeq ($(WITH_HOST_DALVIK),true)
-    ifeq ($(WITH_ART),false)
-        PRODUCT_PACKAGES += \
-            core-hostdex
-    else
-        PRODUCT_PACKAGES += \
-            core-libart-hostdex
-    endif
     PRODUCT_PACKAGES += \
         apache-xml-hostdex \
         bouncycastle-hostdex \
diff --git a/target/product/runtime_libart.mk b/target/product/runtime_libart.mk
new file mode 100644
index 0000000..ce09166
--- /dev/null
+++ b/target/product/runtime_libart.mk
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Provides a functioning ART environment without Android frameworks
+
+PRODUCT_PACKAGES += \
+        core-libart \
+        libart \
+        dex2oat
+PRODUCT_PROPERTY_OVERRIDES += \
+    dalvik.vm.lib=libart.so
+
+# host-only dependencies
+ifeq ($(WITH_HOST_DALVIK),true)
+    PRODUCT_PACKAGES += \
+        core-libart-hostdex
+endif
+
+include $(SRC_TARGET_DIR)/product/runtime_common.mk
diff --git a/target/product/runtime_libart_default.mk b/target/product/runtime_libart_default.mk
new file mode 100644
index 0000000..49f4f45
--- /dev/null
+++ b/target/product/runtime_libart_default.mk
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Set ART as the default runtime environment
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    dalvik.vm.lib=libart.so
+
+include $(SRC_TARGET_DIR)/product/runtime_libart.mk
diff --git a/target/product/runtime_libdvm.mk b/target/product/runtime_libdvm.mk
new file mode 100644
index 0000000..e7647b8
--- /dev/null
+++ b/target/product/runtime_libdvm.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Provides a functioning Dalvik environment without Android frameworks
+
+PRODUCT_PACKAGES += \
+    core \
+    libdvm \
+    dexopt
+
+# host-only dependencies
+ifeq ($(WITH_HOST_DALVIK),true)
+    PRODUCT_PACKAGES += \
+        core-hostdex
+endif
+
+include $(SRC_TARGET_DIR)/product/runtime_common.mk
diff --git a/target/product/runtime_libdvm_default.mk b/target/product/runtime_libdvm_default.mk
new file mode 100644
index 0000000..bbe13bb
--- /dev/null
+++ b/target/product/runtime_libdvm_default.mk
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2013 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Set Dalvik as the default runtime environment
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    dalvik.vm.lib=libdvm.so
+
+include $(SRC_TARGET_DIR)/product/runtime_libdvm.mk