Clean up the makefile to build android.core.vm-tests-tf.jar.

Bug: 7019588
Change-Id: I4c0b5a5b0d1b22628140106a05dfdd046aefecb6
diff --git a/tools/vm-tests-tf/Android.mk b/tools/vm-tests-tf/Android.mk
index 1bb79b3..cdfac28 100644
--- a/tools/vm-tests-tf/Android.mk
+++ b/tools/vm-tests-tf/Android.mk
@@ -14,18 +14,11 @@
 
 LOCAL_PATH := $(call my-dir)
 
-define all-src-files
-$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find src -name '*.java'))
-endef
-
 # buildutil java library
 # ============================================================
 include $(CLEAR_VARS)
 
-LOCAL_TEST_TYPE := vmHostTest
-LOCAL_JAR_PATH := android.core.vm-tests-tf.jar
-
-LOCAL_SRC_FILES := $(call all-src-files)
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_MODULE := cts-tf-dalvik-buildutil
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
@@ -36,77 +29,37 @@
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
-$(LOCAL_BUILT_MODULE): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates)/classes
+# Buid android.core.vm-tests-tf.jar
+# ============================================================
+#
+intermediates := $(call intermediates-dir-for,JAVA_LIBRARIES,vm-tests-tf,HOST)
+vmteststf_jar := $(intermediates)/android.core.vm-tests-tf.jar
+vmteststf_dep_jars := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/, cts-tf-dalvik-buildutil.jar dasm.jar dx.jar cfassembler.jar junit.jar)
+$(vmteststf_jar): PRIVATE_SRC_FOLDER := $(LOCAL_PATH)/src
+$(vmteststf_jar): PRIVATE_LIB_FOLDER := $(LOCAL_PATH)/lib
+$(vmteststf_jar): PRIVATE_INTERMEDIATES_CLASSES := $(call intermediates-dir-for,JAVA_LIBRARIES,cts-tf-dalvik-buildutil,HOST)/classes
+$(vmteststf_jar): PRIVATE_INTERMEDIATES := $(intermediates)/tests
+$(vmteststf_jar): PRIVATE_INTERMEDIATES_DEXCORE_JAR := $(intermediates)/tests/dot/junit/dexcore.jar
+$(vmteststf_jar): PRIVATE_INTERMEDIATES_MAIN_FILES := $(intermediates)/main_files
+$(vmteststf_jar): PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES := $(intermediates)/hostjunit_files
+$(vmteststf_jar): PRIVATE_CLASS_PATH := $(subst $(space),:,$(vmteststf_dep_jars)):$(HOST_JDK_TOOLS_JAR)
+$(vmteststf_jar) : $(vmteststf_dep_jars) $(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
+	$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
+	$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit $(dir $(PRIVATE_INTERMEDIATES_DEXCORE_JAR))
+	# generated and compile the host side junit tests
+	@echo "Write generated Main_*.java files to $(PRIVATE_INTERMEDIATES_MAIN_FILES)"
+	$(hide) java -cp $(PRIVATE_CLASS_PATH) util.build.BuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
+		$(HOST_OUT_JAVA_LIBRARIES)/cts-tf-dalvik-buildutil.jar:$(PRIVATE_LIB_FOLDER)/junit.jar:$(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar \
+		$(PRIVATE_INTERMEDIATES_MAIN_FILES) $(PRIVATE_INTERMEDIATES_CLASSES) $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES) $$RUN_VM_TESTS_RTO
+	@echo "Generate $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)"
+	$(hide) jar -cf $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar \
+		$(addprefix -C $(PRIVATE_INTERMEDIATES_CLASSES) , dot/junit/DxUtil.class dot/junit/DxAbstractMain.class)
+	$(hide) $(DX) -JXms16M -JXmx768M --dex --output=$(PRIVATE_INTERMEDIATES_DEXCORE_JAR) \
+		$(if $(NO_OPTIMIZE_DX), --no-optimize) $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar && rm -f $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar
+	$(hide) cd $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/classes && zip -q -r ../../android.core.vm-tests-tf.jar .
+	$(hide) cd $(dir $@) && zip -q -r android.core.vm-tests-tf.jar tests
 
-TF_BUILD_UTIL_INTERMEDIATES_CLASSES := $(intermediates)/classes
-
-include $(CLEAR_VARS)
-
-LOCAL_UNINSTALLABLE_MODULE := true
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_MODULE := vm-tests-tf
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-GENERATED_FILES:=$(intermediates)/tests
-
-$(LOCAL_BUILT_MODULE): $(GENERATED_FILES)
-
-colon:= :
-empty:=
-space:= $(empty) $(empty)
-
-
-$(GENERATED_FILES): PRIVATE_SRC_FOLDER := $(LOCAL_PATH)/src
-$(GENERATED_FILES): PRIVATE_LIB_FOLDER := $(LOCAL_PATH)/lib
-$(GENERATED_FILES): PRIVATE_INTERMEDIATES := $(intermediates)/tests
-$(GENERATED_FILES): PRIVATE_INTERMEDIATES_MAIN_FILES := $(intermediates)/main_files
-$(GENERATED_FILES): PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES := $(intermediates)/hostjunit_files
-$(GENERATED_FILES): $(HOST_OUT_JAVA_LIBRARIES)/cts-tf-dalvik-buildutil.jar $(HOST_OUT_JAVA_LIBRARIES)/dasm.jar $(HOST_OUT_JAVA_LIBRARIES)/dx.jar $(HOST_OUT_JAVA_LIBRARIES)/cfassembler.jar $(HOST_OUT_JAVA_LIBRARIES)/junit.jar
-
-	$(hide) mkdir -p $@
-	$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit
-# generated and compile the host side junit tests
-	$(hide) java -cp $(subst $(space),$(colon),$^):$(HOST_JDK_TOOLS_JAR) util.build.BuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) $<:$(PRIVATE_LIB_FOLDER)/junit.jar:$(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar $(PRIVATE_INTERMEDIATES_MAIN_FILES) $(TF_BUILD_UTIL_INTERMEDIATES_CLASSES) $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES) $$RUN_VM_TESTS_RTO
-	@echo "wrote generated Main_*.java files to $(PRIVATE_INTERMEDIATES_MAIN_FILES)"
-INSTALLED_TESTS := $(dir $(LOCAL_BUILT_MODULE))../cts_dalviktests_tf/timestamp
-
-$(LOCAL_BUILT_MODULE):  $(INSTALLED_TESTS)
-
-$(INSTALLED_TESTS): PRIVATE_INTERMEDIATES := $(intermediates)/tests
-$(INSTALLED_TESTS): $(GENERATED_FILES) $(GENERATED_FILES)/dot/junit/dexcore.jar
-	$(hide) mkdir -p $(dir $@)tests
-	$(hide) $(ACP) -r $(PRIVATE_INTERMEDIATES)/dot $(dir $@)tests
-	@touch $@
-
-$(intermediates)/android.core.vm-tests-tf.jar: PRIVATE_INTERMEDIATES := $(intermediates)
-$(intermediates)/android.core.vm-tests-tf.jar: $(INSTALLED_TESTS)
-	$(hide) cd $(PRIVATE_INTERMEDIATES)/hostjunit_files/classes && \
-	zip -q -r ../../android.core.vm-tests-tf.jar . && \
-	cd -
-	$(hide) cd $(PRIVATE_INTERMEDIATES) && \
-	zip -q -r android.core.vm-tests-tf.jar tests && \
-	cd -
-	
-
-define get-class-path
-	$(TF_BUILD_UTIL_INTERMEDIATES_CLASSES)/$(strip $(1))
-endef
-
-define dex-classes
-	@mkdir -p $(dir $@)
-	@jar -cf $(dir $@)/$(notdir $@).jar $(addprefix -C $(1) ,$(2))
-	$(hide) $(DX) -JXms16M -JXmx768M \
-    --dex --output=$@ \
-    $(if $(NO_OPTIMIZE_DX), \
-        --no-optimize) \
-    $(dir $@)/$(notdir $@).jar
-    @rm -f $(dir $@)/$(notdir $@).jar
-endef
-
-$(call get-class-path,dot/junit/DxUtil.class) $(call get-class-path,dot/junit/DxAbstractMain.class):  $(HOST_OUT_JAVA_LIBRARIES)/cts-tf-dalvik-buildutil.jar $(DX)
-
-$(GENERATED_FILES)/dot/junit/dexcore.jar: $(call get-class-path,dot/junit/DxUtil.class) $(call get-class-path,dot/junit/DxAbstractMain.class)
-	$(call dex-classes,$(TF_BUILD_UTIL_INTERMEDIATES_CLASSES),dot/junit/DxUtil.class dot/junit/DxAbstractMain.class)
+# Clean up temp vars
+intermediates :=
+vmteststf_jar :=
+vmteststf_dep_jars :=