auto import from //depot/cupcake/@136594
diff --git a/cleanspec.mk b/cleanspec.mk
index 794c9cd..7c178ec 100644
--- a/cleanspec.mk
+++ b/cleanspec.mk
@@ -68,6 +68,7 @@
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libjni_andpyime_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/share)
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libwebcore_intermediates)
 
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
diff --git a/core/combo/linux-arm.mk b/core/combo/linux-arm.mk
index 507e4dd..fa5f67e 100644
--- a/core/combo/linux-arm.mk
+++ b/core/combo/linux-arm.mk
@@ -15,7 +15,8 @@
 
 $(combo_target)NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
 
-TARGET_arm_release_CFLAGS :=    -fomit-frame-pointer \
+TARGET_arm_release_CFLAGS :=    -O2 \
+                                -fomit-frame-pointer \
                                 -fstrict-aliasing    \
                                 -funswitch-loops     \
                                 -finline-limit=300
@@ -62,7 +63,7 @@
 
 $(combo_target)RELEASE_CFLAGS := \
 			-DSK_RELEASE -DNDEBUG \
-			-O2 -g \
+			-g \
 			-Wstrict-aliasing=2 \
 			-finline-functions \
 			-fno-inline-functions-called-once \
diff --git a/core/node_fns.mk b/core/node_fns.mk
index 202bb0d..8b026f5 100644
--- a/core/node_fns.mk
+++ b/core/node_fns.mk
@@ -182,8 +182,9 @@
 # $(2): makefile representing this node
 # $(3): list of node variable names
 #
-#TODO: keep a debug stack to make error messages more helpful
+# _include_stack contains the list of included files, with the most recent files first.
 define _import-node
+  $(eval _include_stack := $(2) $$(_include_stack))
   $(call clear-var-list, $(3))
   $(eval include $(2))
   $(call copy-var-list, $(1).$(2), $(3))
@@ -196,6 +197,7 @@
   $(call _expand-inherited-values,$(1),$(2),$(3))
 
   $(eval $(1).$(2).inherited :=)
+  $(eval _include_stack := $(wordlist 2,9999,$$(_include_stack)))
 endef
 
 #
@@ -229,10 +231,15 @@
 $(if \
   $(foreach _in,$(2), \
     $(eval _node_import_context := _nic.$(1).[[$(_in)]]) \
+    $(if $(_include_stack),$(eval $(error ASSERTION FAILED: _include_stack \
+                should be empty here: $(_include_stack))),) \
+    $(eval _include_stack := ) \
     $(call _import-nodes-inner,$(_node_import_context),$(_in),$(3)) \
     $(call move-var-list,$(_node_import_context).$(_in),$(1).$(_in),$(3)) \
     $(eval _node_import_context :=) \
     $(eval $(1) := $($(1)) $(_in)) \
+    $(if $(_include_stack),$(eval $(error ASSERTION FAILED: _include_stack \
+                should be empty here: $(_include_stack))),) \
    ) \
 ,)
 endef
diff --git a/core/product.mk b/core/product.mk
index 8f5dc7b..2e85f04 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -80,9 +80,19 @@
 #
 # $(1): product to inherit
 #
+# Does three things:
+#  1. Inherits all of the variables from $1.
+#  2. Records the inheritance in the .INHERITS_FROM variable
+#  3. Records that we've visited this node, in ALL_PRODUCTS
+#
 define inherit-product
   $(foreach v,$(_product_var_list), \
-      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1))))
+      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1)))) \
+  $(eval inherit_var := \
+      PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \
+  $(eval $(inherit_var) := $(sort $($(inherit_var)) $(strip $(1)))) \
+  $(eval inherit_var:=) \
+  $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack))))
 endef
 
 #
diff --git a/core/tasks/cts.mk b/core/tasks/cts.mk
index 9ef99db..4008fac 100644
--- a/core/tasks/cts.mk
+++ b/core/tasks/cts.mk
@@ -40,7 +40,8 @@
 	CtsViewTestCases \
 	CtsWidgetTestCases \
 	CtsNetTestCases \
-	SignatureTest
+	SignatureTest \
+	android.core.tests
 
 DEFAULT_TEST_PLAN := $(PRIVATE_DIR)/resource/plans
 
@@ -64,6 +65,55 @@
 	$(hide) $(ACP) -fp $(cts_tools_src_dir)/utils/startcts $(PRIVATE_DIR)/tools/
 	$(hide) touch $@
 
+# Generate the test plan for the core-tests
+CORE_TEST_PLAN := $(cts_dir)/$(cts_name)/repository/testcases/android.core.tests
+
+CORE_INTERMEDIATES :=$(call intermediates-dir-for,JAVA_LIBRARIES,core,,COMMON)
+TESTS_INTERMEDIATES :=$(call intermediates-dir-for,JAVA_LIBRARIES,core-tests,,COMMON)
+
+GEN_CLASSPATH := $(CORE_INTERMEDIATES)/classes.jar:$(TESTS_INTERMEDIATES)/classes.jar:$(CORE_INTERMEDIATES)/javalib.jar:$(TESTS_INTERMEDIATES)/javalib.jar:$(HOST_OUT_JAVA_LIBRARIES)/descGen.jar:$(HOST_JDK_TOOLS_JAR)
+
+$(CORE_TEST_PLAN): PRIVATE_CLASSPATH:=$(GEN_CLASSPATH)
+$(CORE_TEST_PLAN): PRIVATE_PARAMS:=-Dcts.useSuppliedTestResult=true
+$(CORE_TEST_PLAN): PRIVATE_PARAMS+=-Dcts.useEnhancedJunit=true
+$(CORE_TEST_PLAN): PRIVATE_CUSTOM_TOOL := java -classpath $(PRIVATE_CLASSPATH) \
+	$(PRIVATE_PARAMS) CollectAllTests $(CORE_TEST_PLAN) \
+	cts/tests/core/AndroidManifest.xml tests.AllTests
+# Why does this depend on javalib.jar instead of classes.jar?  Because
+# even though the tool will operate on the classes.jar files, the
+# build system requires that dependencies use javalib.jar.  If
+# javalib.jar is up-to-date, then classes.jar is as well.  Depending
+# on classes.jar will build the files incorrectly.
+$(CORE_TEST_PLAN): android.core.tests $(HOST_OUT_JAVA_LIBRARIES)/descGen.jar $(CORE_INTERMEDIATES)/javalib.jar $(TESTS_INTERMEDIATES)/javalib.jar $(cts_dir)/all_cts_files_stamp
+	@echo "Generate the CTS test plan: $@"
+	@echo $(PRIVATE_CUSTOM_TOOL)
+	$(transform-generated-source)
+
+
+# ----- Generate the test plan for the vm-tests -----
+#
+CORE_VM_TEST_PLAN := $(cts_dir)/$(cts_name)/repository/testcases/android.core.vm-tests
+
+VMTESTS_INTERMEDIATES :=$(call intermediates-dir-for,EXECUTABLES,vm-tests,1,)
+# core tests only needed to get hold of junit-framework-classes
+TESTS_INTERMEDIATES :=$(call intermediates-dir-for,JAVA_LIBRARIES,core-tests,,COMMON)
+CORE_INTERMEDIATES :=$(call intermediates-dir-for,JAVA_LIBRARIES,core,,COMMON)
+
+GEN_CLASSPATH := $(CORE_INTERMEDIATES)/classes.jar:$(TESTS_INTERMEDIATES)/classes.jar:$(VMTESTS_INTERMEDIATES)/android.core.vm-tests.jar:$(HOST_OUT_JAVA_LIBRARIES)/descGen.jar:$(HOST_JDK_TOOLS_JAR)
+
+$(CORE_VM_TEST_PLAN): PRIVATE_CLASSPATH:=$(GEN_CLASSPATH)
+$(CORE_VM_TEST_PLAN): PRIVATE_PARAMS:=-Dcts.useSuppliedTestResult=true
+$(CORE_VM_TEST_PLAN): PRIVATE_PARAMS+=-Dcts.useEnhancedJunit=true
+$(CORE_VM_TEST_PLAN): PRIVATE_CUSTOM_TOOL := java -classpath $(PRIVATE_CLASSPATH) \
+	$(PRIVATE_PARAMS) CollectAllTests $(CORE_VM_TEST_PLAN) \
+	cts/tests/vm-tests/AndroidManifest.xml dot.junit.AllJunitHostTests
+# Please see big comment above on why this line depends on javalib.jar instead of classes.jar
+$(CORE_VM_TEST_PLAN): vm-tests $(HOST_OUT_JAVA_LIBRARIES)/descGen.jar $(CORE_INTERMEDIATES)/javalib.jar $(VMTESTS_INTERMEDIATES)/android.core.vm-tests.jar $(TESTS_INTERMEDIATES)/javalib.jar $(cts_dir)/all_cts_files_stamp | $(ACP)
+	@echo "Generate the CTS vm-test plan: $@"
+	@echo $(PRIVATE_CUSTOM_TOOL)
+	$(transform-generated-source)
+	$(ACP) -fv $(VMTESTS_INTERMEDIATES)/android.core.vm-tests.jar $(PRIVATE_DIR)/repository/testcases/android.core.vm-tests.jar
+
 # Generate the default test plan for User.
 $(DEFAULT_TEST_PLAN): $(cts_dir)/all_cts_files_stamp $(cts_tools_src_dir)/utils/genDefaultTestPlan.sh
 	$(hide) bash $(cts_tools_src_dir)/utils/genDefaultTestPlan.sh cts/tests/tests/ \
@@ -78,7 +128,7 @@
 $(INTERNAL_CTS_TARGET): PRIVATE_CTS_DIR := $(cts_dir)
 $(INTERNAL_CTS_TARGET): PRIVATE_DIR := $(cts_dir)/$(cts_name)
 $(INTERNAL_CTS_TARGET): TMP_DIR := $(cts_dir)/temp
-$(INTERNAL_CTS_TARGET): $(cts_dir)/all_cts_files_stamp $(DEFAULT_TEST_PLAN)
+$(INTERNAL_CTS_TARGET): $(cts_dir)/all_cts_files_stamp $(DEFAULT_TEST_PLAN) $(CORE_TEST_PLAN) $(CORE_VM_TEST_PLAN)
 	@echo "Package CTS: $@"
 	$(hide) cd $(dir $@) && zip -rq $(notdir $@) $(PRIVATE_NAME)
 
@@ -92,4 +142,3 @@
 	$(PRIVATE_DIR)/repository/testcases/$(1).apk
 
 endef
-
diff --git a/core/tasks/product-graph.mk b/core/tasks/product-graph.mk
new file mode 100644
index 0000000..ead1406
--- /dev/null
+++ b/core/tasks/product-graph.mk
@@ -0,0 +1,35 @@
+#
+# Copyright (C) 2009 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.
+#
+
+products_pdf := $(OUT_DIR)/products.pdf
+
+# This rule doens't include any nodes that don't inherit from
+# anything or don't have anything inherit from them, to make the
+# graph more readable.  To add that, add this line to the rule
+# below:
+#		$(foreach p,$(ALL_PRODUCTS), echo \"$(p)\";) \
+
+$(products_pdf):
+	$(hide) ( \
+		echo 'digraph {'; \
+		$(foreach p,$(ALL_PRODUCTS), \
+			$(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), \
+			echo \"$(d)\" -\> \"$(p)\";)) \
+		echo '}' \
+	) | dot -Tpdf -Nshape=box -o $@
+
+product-graph: $(products_pdf)
+