Merge "Convert copying of .txt files to .bp" am: 71fd29d891
am: 20c23b511d

Change-Id: Id49795d2fef415bbf264aa2690c05a5d64109c34
diff --git a/tests/signature/api-check/build_signature_apk.mk b/tests/signature/api-check/build_signature_apk.mk
index 4b002cc..98ff55f 100644
--- a/tests/signature/api-check/build_signature_apk.mk
+++ b/tests/signature/api-check/build_signature_apk.mk
@@ -33,40 +33,26 @@
 LOCAL_JNI_SHARED_LIBRARIES += libclassdescriptors
 LOCAL_MULTILIB := both
 
-LOCAL_ADDITIONAL_DEPENDENCIES += \
-    $(addprefix $(COMPATIBILITY_TESTCASES_OUT_cts)/,$(LOCAL_SIGNATURE_API_FILES))
-
 # Add dependencies needed to build/run the test with atest.
 #
-# This is a temporary workaround as described in b/123393637. It adds the dependencies that
-# atest requires for each of the modules specified in the LOCAL_SIGNATURE_API_FILES. The
-# mapping from module name to the dependency is slightly complicated due to inconsistencies
-# in the mapping for the different file types, i.e. .api, .csv and .zip. Those
-# inconsistencies will be resolved by build improvement work mentioned in b/123393637.
-#
 # Converts:
-#     current.api -> $(TARGET_OUT_TESTCASES)/cts-current-api/current.api
-#     hiddenapi_flags.csv -> $(TARGET_OUT_TESTCASES)/cts-hiddenapi_flags-csv/hiddenapi_flags.csv
-#     system-all.api.zip -> $(TARGET_OUT_TESTCASES)/cts-system-all.api/system-all.api.zip
+#     current.api -> $(SOONG_OUT_DIR)/.intermediates/cts/tests/signature/api/cts-current-txt/gen/current.txt
 
-# Construct module name directory from file name, matches behavior in the
-# build_xml_api_file function in ../api/Android.mk plus some extra rules for handling slight
-# inconsistencies with that behavior for the ..all.zip files used by some signature tests.
+# Construct module name directory from file name, matches location of output of genrules
+# in ../api/Android.bp.
 #   Replace . with -
 #   Prefix every entry with cts-
-#   Replace -all-api-zip with -all.api to handle ...all.zip files
 #
 cts_signature_module_deps := $(LOCAL_SIGNATURE_API_FILES)
 cts_signature_module_deps := $(subst .,-,$(cts_signature_module_deps))
 cts_signature_module_deps := $(addprefix cts-,$(cts_signature_module_deps))
-cts_signature_module_deps := $(subst -all-txt-zip,-all.txt,$(cts_signature_module_deps))
 
 # Construct path to the generated files and add them as java resources.
-cts_signature_module_resources := $(addprefix $(PRODUCT_OUT)/obj/ETC/,$(cts_signature_module_deps))
-cts_signature_module_resources := $(addsuffix _intermediates/,$(cts_signature_module_resources))
+cts_signature_module_resources := $(addprefix $(SOONG_OUT_DIR)/.intermediates/cts/tests/signature/api/,$(cts_signature_module_deps))
+cts_signature_module_resources := $(addsuffix /gen/,$(cts_signature_module_resources))
 cts_signature_module_resources := $(join $(cts_signature_module_resources),$(LOCAL_SIGNATURE_API_FILES))
 
-LOCAL_JAVA_RESOURCE_FILES := $(cts_signature_module_resources)
+LOCAL_JAVA_RESOURCE_FILES += $(cts_signature_module_resources)
 
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
diff --git a/tests/signature/api-check/shared-libs-api/Android.mk b/tests/signature/api-check/shared-libs-api/Android.mk
index acc9570..35c79ec 100644
--- a/tests/signature/api-check/shared-libs-api/Android.mk
+++ b/tests/signature/api-check/shared-libs-api/Android.mk
@@ -41,6 +41,8 @@
 	$(hide) rm -f $@
 	$(hide) $(SOONG_ZIP) -o $@ -P out -C $(OUT_DIR) $(addprefix -f ,$(PRIVATE_SHARED_LIBS_FILES))
 
+all_shared_libs_zip_file := $(LOCAL_BUILT_MODULE)
+
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
@@ -62,9 +64,7 @@
 
 LOCAL_PACKAGE_NAME := CtsSharedLibsApiSignatureTestCases
 
-LOCAL_SIGNATURE_API_FILES := \
-    shared-libs-all.txt.zip \
-    $(all_shared_libs_modules)
+LOCAL_JAVA_RESOURCE_FILES := $(all_shared_libs_zip_file)
 
 LOCAL_STATIC_JAVA_LIBRARIES := cts-api-signature-multilib-test
 
@@ -73,4 +73,4 @@
 LOCAL_JAVA_SDK_LIBRARIES :=
 all_shared_libs_files :=
 all_shared_libs_modules :=
-
+all_shared_libs_zip_file :=
diff --git a/tests/signature/api-check/system-api/Android.mk b/tests/signature/api-check/system-api/Android.mk
index d699b83..7605f85 100644
--- a/tests/signature/api-check/system-api/Android.mk
+++ b/tests/signature/api-check/system-api/Android.mk
@@ -14,7 +14,7 @@
 
 LOCAL_PATH := $(call my-dir)
 
-all_system_api_modules := system-current.txt system-removed.txt
+all_system_api_modules :=
 $(foreach ver,$(PLATFORM_SYSTEMSDK_VERSIONS),\
   $(if $(call math_is_number,$(ver)),\
     $(eval all_system_api_modules += system-$(ver).txt)\
@@ -37,18 +37,23 @@
 	$(hide) rm -f $@
 	$(hide) $(SOONG_ZIP) -o $@ -P out -C $(OUT_DIR) $(addprefix -f ,$(PRIVATE_SYSTEM_API_FILES))
 
+all_system_api_zip_file := $(LOCAL_BUILT_MODULE)
+
 include $(CLEAR_VARS)
 
 LOCAL_PACKAGE_NAME := CtsSystemApiSignatureTestCases
 
+LOCAL_JAVA_RESOURCE_FILES := $(all_system_api_zip_file)
+
 LOCAL_SIGNATURE_API_FILES := \
     current.txt \
     android-test-mock-current.txt \
     android-test-runner-current.txt \
-    $(all_sytem_api_modules) \
-    system-all.txt.zip
+    system-current.txt \
+    system-removed.txt \
 
 include $(LOCAL_PATH)/../build_signature_apk.mk
 
 all_system_api_files :=
 all_system_api_modules :=
+all_system_api_zip_file :=
diff --git a/tests/signature/api-check/system-api/AndroidTest.xml b/tests/signature/api-check/system-api/AndroidTest.xml
index 54c2bd0a..3368b77 100644
--- a/tests/signature/api-check/system-api/AndroidTest.xml
+++ b/tests/signature/api-check/system-api/AndroidTest.xml
@@ -27,7 +27,7 @@
         <option name="runner" value="repackaged.android.test.InstrumentationTestRunner" />
         <option name="class" value="android.signature.cts.api.system.SignatureTest" />
         <option name="instrumentation-arg" key="base-api-files" value="current.txt" />
-        <option name="instrumentation-arg" key="expected-api-files" value="system-all.txt.zip" />
+        <option name="instrumentation-arg" key="expected-api-files" value="system-current.txt,system-removed.txt,system-all.txt.zip" />
         <option name="instrumentation-arg" key="unexpected-api-files" value="android-test-mock-current.txt,android-test-runner-current.txt" />
         <option name="runtime-hint" value="30s" />
     </test>
diff --git a/tests/signature/api/Android.bp b/tests/signature/api/Android.bp
new file mode 100644
index 0000000..ea39759
--- /dev/null
+++ b/tests/signature/api/Android.bp
@@ -0,0 +1,125 @@
+// Copyright (C) 2019 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.
+
+default_visibility = [
+    "//cts/tests/signature/api-check:__subpackages__",
+]
+
+genrule {
+    name: "cts-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":frameworks-base-api-current.txt",
+    ],
+    out: [
+        "current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-system-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":frameworks-base-api-system-current.txt",
+    ],
+    out: [
+        "system-current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-system-removed-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":frameworks-base-api-system-removed.txt",
+    ],
+    out: [
+        "system-removed.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-android-test-base-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":android-test-base-current.txt",
+    ],
+    out: [
+        "android-test-base-current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-android-test-mock-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":android-test-mock-current.txt",
+    ],
+    out: [
+        "android-test-mock-current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-android-test-runner-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":android-test-runner-current.txt",
+    ],
+    out: [
+        "android-test-runner-current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-apache-http-legacy-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":apache-http-legacy-current.txt",
+    ],
+    out: [
+        "apache-http-legacy-current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-car-system-current-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":car-api-system-current.txt",
+    ],
+    out: [
+        "car-system-current.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
+
+genrule {
+    name: "cts-car-system-removed-txt",
+    visibility: default_visibility,
+    srcs: [
+        ":car-api-system-removed.txt",
+    ],
+    out: [
+        "car-system-removed.txt",
+    ],
+    cmd: "cp $(in) $(out)",
+}
diff --git a/tests/signature/api/Android.mk b/tests/signature/api/Android.mk
index c3aca10..9863798 100644
--- a/tests/signature/api/Android.mk
+++ b/tests/signature/api/Android.mk
@@ -26,22 +26,15 @@
 LOCAL_COMPATIBILITY_SUITE := arcts cts vts general-tests
 include $(BUILD_SYSTEM)/base_rules.mk
 $$(LOCAL_BUILT_MODULE): $(2) | $(APICHECK)
-#	@echo "Convert API file $$< -> $$@"
-#	@mkdir -p $$(dir $$@)
-#	$(hide) $(APICHECK_COMMAND) -convert2xmlnostrip $$< $$@
 	@echo "Copying API file $$< -> $$@"
 	$$(copy-file-to-target)
 endef
 
+# Kept for CtsIntentSignatureTestCases
 $(eval $(call copy_api_txt_file,current.txt,frameworks/base/api/current.txt))
 $(eval $(call copy_api_txt_file,system-current.txt,frameworks/base/api/system-current.txt))
 $(eval $(call copy_api_txt_file,system-removed.txt,frameworks/base/api/system-removed.txt))
-$(eval $(call copy_api_txt_file,apache-http-legacy-current.txt,external/apache-http/api/current.txt))
-$(eval $(call copy_api_txt_file,android-test-base-current.txt,frameworks/base/test-base/api/current.txt))
-$(eval $(call copy_api_txt_file,android-test-mock-current.txt,frameworks/base/test-mock/api/current.txt))
-$(eval $(call copy_api_txt_file,android-test-runner-current.txt,frameworks/base/test-runner/api/current.txt))
-$(eval $(call copy_api_txt_file,car-system-current.txt,packages/services/Car/car-lib/api/system-current.txt))
-$(eval $(call copy_api_txt_file,car-system-removed.txt,packages/services/Car/car-lib/api/system-removed.txt))
+
 $(foreach ver,$(PLATFORM_SYSTEMSDK_VERSIONS),\
   $(if $(call math_is_number,$(ver)),\
     $(eval $(call copy_api_txt_file,system-$(ver).txt,prebuilts/sdk/$(ver)/system/api/android.txt))\