Resubmit without common rules to build tradefed.zip

Only active if main project isn't present.

Test: make tradefed-all dist
Bug: 173508636
Change-Id: I19a70aee04af383eec4be19aebad40acc936f088
diff --git a/filegroups/tradefed/Android.bp b/filegroups/tradefed/Android.bp
index f974771..7a75c38 100644
--- a/filegroups/tradefed/Android.bp
+++ b/filegroups/tradefed/Android.bp
@@ -23,36 +23,6 @@
 }
 
 filegroup {
-    name: "tradefed-tests-prebuilt",
-    srcs: ["tradefed-tests.jar"],
-}
-
-filegroup {
     name: "tradefed-test-framework-prebuilt",
     srcs: ["tradefed-test-framework.jar"],
 }
-
-filegroup {
-    name: "tradefed-isolation-prebuilt",
-    srcs: ["tradefed-isolation.jar"],
-}
-
-filegroup {
-    name: "tradefed-contrib-prebuilt",
-    srcs: ["tradefed-contrib.jar"],
-}
-
-filegroup {
-    name: "tf-contrib-tests-prebuilt",
-    srcs: ["tf-contrib-tests.jar"],
-}
-
-filegroup {
-    name: "loganalysis-prebuilt",
-    srcs: ["loganalysis.jar"],
-}
-
-filegroup {
-    name: "loganalysis-tests-prebuilt",
-    srcs: ["loganalysis-tests.jar"],
-}
diff --git a/test_harness/Android.bp b/test_harness/Android.bp
index f45f047..9a42f03 100644
--- a/test_harness/Android.bp
+++ b/test_harness/Android.bp
@@ -14,8 +14,17 @@
  * limitations under the License.
  */
 
+// This file contains all the build target that we expect tests writers
+// to need to build tests.
+
 java_import_host {
     name: "tradefed",
     jars: [":tradefed-prebuilt"],
     installable: true,
 }
+
+java_import_host {
+    name: "tradefed-test-framework",
+    jars: [":tradefed-test-framework-prebuilt"],
+    installable: true,
+}
diff --git a/test_harness/Android.mk b/test_harness/Android.mk
new file mode 100644
index 0000000..8180f7c
--- /dev/null
+++ b/test_harness/Android.mk
@@ -0,0 +1,44 @@
+# Copyright (C) 2020 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.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+ifeq (,$(wildcard $(LOCAL_PATH)/../../core))
+.PHONY: tradefed-all
+tradefed-all-prebuilt: tradefed
+
+tradefed_dist_artifacts := tradefed.jar tradefed-tests.jar tradefed-test-framework.jar loganalysis.jar loganalysis-tests.jar tradefed-contrib.jar tf-contrib-tests.jar tradefed-isolation.jar tradefed.sh tradefed_win.bat script_help.sh atest_tradefed.sh TradeFedUiTestApp.apk TradeFedTestApp.apk version.txt
+
+tradefed_dist_copy_pairs := $(foreach m, $(tradefed_dist_artifacts), $(LOCAL_PATH)/../filegroups/tradefed/$(m):$(m))
+
+tradefed_dist_artifacts :=
+
+tradefed_dist_intermediates := $(call intermediates-dir-for,PACKAGING,tradefed_dist,HOST,COMMON)
+tradefed_dist_zip := $(tradefed_dist_intermediates)/tradefed.zip
+$(tradefed_dist_zip) : PRIVATE_COPY_PAIRS := $(tradefed_dist_copy_pairs)
+$(tradefed_dist_zip) : $(SOONG_ZIP) $(foreach f,$(tradefed_dist_copy_pairs),$(call word-colon,1,$(f)))
+	rm -rf $(dir $@)/tmp && mkdir -p $(dir $@)/tmp
+	$(foreach f,$(PRIVATE_COPY_PAIRS), \
+	  cp -f $(call word-colon,1,$(f)) $(dir $@)/tmp/$(call word-colon,2,$(f)) &&) true
+
+$(call dist-for-goals, tradefed, $(tradefed_dist_zip))
+
+tradefed_dist_copy_pairs :=
+tradefed_dist_intermediates :=
+tradefed_dist_zip :=
+endif
+
+# Build all sub-directories
+include $(call all-makefiles-under,$(LOCAL_PATH))