Convert RSTest*/Android.mk to Android.bp

1. Converted the RsTest/Android.mk to Android.bp;
2. Converted the RsTest_CompatLib/Android.mk and
RSTestBackward/Android.mk as well, since they are some common
dependencies as the module in 1.

Bug: 124261647
Test: compared the two apk files built by Make and Soong
Test: m RSTest
Test: m RSTest_Compat
Test: m RSTestBackward
Test: TreeHugger
Change-Id: If70108413ca1312b42f565aaaa33042b68d8473b
diff --git a/tests/java_api/RSTestBackward/Android.bp b/tests/java_api/RSTestBackward/Android.bp
new file mode 100644
index 0000000..c962be7
--- /dev/null
+++ b/tests/java_api/RSTestBackward/Android.bp
@@ -0,0 +1,38 @@
+//
+// Copyright (C) 2017 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.
+//
+
+package {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: [
+        "Android-Apache-2.0",
+    ],
+}
+
+android_test {
+    name: "RSTestBackward",
+    sdk_version: "current",
+    srcs: [
+        "src/**/*.java",
+        ":RSUnitTests_java_srcs",
+        ":RSTest-rscript{RSTest.srcjar}",
+    ],
+    resource_zips: [
+        ":RSTest-rscript{RSTest.res.zip}",
+    ],
+    static_libs: ["androidx.test.rules"],
+    test_suites: ["device-tests"],
+    min_sdk_version: "21",
+}
diff --git a/tests/java_api/RSTestBackward/Android.mk b/tests/java_api/RSTestBackward/Android.mk
deleted file mode 100644
index b3111a6..0000000
--- a/tests/java_api/RSTestBackward/Android.mk
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# Copyright (C) 2017 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)
-
-LOCAL_PACKAGE_NAME := RSTestBackward
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-    $(call all-java-files-under, src)\
-    $(call all-java-files-under, ../RSUnitTests/src)\
-    $(call all-renderscript-files-under, ../RSUnitTests/src)\
-
-LOCAL_STATIC_JAVA_LIBRARIES := androidx.test.rules
-LOCAL_COMPATIBILITY_SUITE := device-tests
-
-LOCAL_RENDERSCRIPT_TARGET_API := current
-LOCAL_MIN_SDK_VERSION := 21
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_PACKAGE)
diff --git a/tests/java_api/RSTest_CompatLib/Android.bp b/tests/java_api/RSTest_CompatLib/Android.bp
new file mode 100644
index 0000000..74dc966
--- /dev/null
+++ b/tests/java_api/RSTest_CompatLib/Android.bp
@@ -0,0 +1,66 @@
+//
+// Copyright (C) 2017 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.
+//
+
+package {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: [
+        "Android-Apache-2.0",
+    ],
+}
+
+android_test {
+    name: "RSTest_Compat",
+    sdk_version: "current",
+    srcs: [
+        "src/**/*.java",
+        ":RSUnitTests_java_gui",
+        ":RSUnitTests_java_supportlibsrc_gen",
+        ":RSTest_Compat-rscript{RSTest_Compat.srcjar}",
+    ],
+    resource_zips: [
+        ":RSTest_Compat-rscript{RSTest_Compat.res.zip}",
+    ],
+    static_libs: [
+        "androidx.test.rules",
+        "android-support-v8-renderscript",
+    ],
+    min_sdk_version: "8",
+}
+
+genrule {
+    name: "RSTest_Compat-rscript",
+    srcs: [
+        ":RSUnitTests_rscript_supportlibsrc_gen",
+        ":rs_script_api",
+        ":rs_clang_headers",
+    ],
+    tools: [
+        "llvm-rs-cc",
+        "soong_zip",
+    ],
+    out: [
+        "RSTest_Compat.srcjar",
+        "RSTest_Compat.res.zip",
+    ],
+    cmd: "for f in $(locations :RSUnitTests_rscript_supportlibsrc_gen); do " +
+        "  $(location llvm-rs-cc) -o $(genDir)/res/raw -p $(genDir)/src " +
+        "  -rs-package-name=androidx.renderscript " +
+        "  -I $$(dirname $$(echo $(locations :rs_script_api) | awk '{ print $$1 }')) " +
+        "  -I $$(dirname $$(echo $(locations :rs_clang_headers) | awk '{ print $$1 }')) $${f}; " +
+        "done && " +
+        "$(location soong_zip) -srcjar -o $(location RSTest_Compat.srcjar) -C $(genDir)/src -D $(genDir)/src &&" +
+        "$(location soong_zip) -o $(location RSTest_Compat.res.zip) -C $(genDir)/res -D $(genDir)/res",
+}
diff --git a/tests/java_api/RSTest_CompatLib/Android.mk b/tests/java_api/RSTest_CompatLib/Android.mk
deleted file mode 100644
index 2df8904..0000000
--- a/tests/java_api/RSTest_CompatLib/Android.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Copyright (C) 2017 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)
-
-LOCAL_PACKAGE_NAME := RSTest_Compat
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := \
-    $(call all-java-files-under,src) \
-    $(call all-java-files-under,../RSUnitTests/gui) \
-    $(call all-java-files-under,../RSUnitTests/supportlibsrc_gen) \
-    $(call all-renderscript-files-under,../RSUnitTests/supportlibsrc_gen) \
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    androidx.test.rules \
-    android-support-v8-renderscript \
-
-LOCAL_RENDERSCRIPT_TARGET_API := current
-LOCAL_RENDERSCRIPT_COMPATIBILITY := true
-LOCAL_SDK_VERSION := current
-LOCAL_MIN_SDK_VERSION := 8
-
-LOCAL_RENDERSCRIPT_FLAGS := -rs-package-name=androidx.renderscript
-
-include $(BUILD_PACKAGE)
diff --git a/tests/java_api/RSUnitTests/Android.bp b/tests/java_api/RSUnitTests/Android.bp
new file mode 100644
index 0000000..a661df1
--- /dev/null
+++ b/tests/java_api/RSUnitTests/Android.bp
@@ -0,0 +1,50 @@
+//
+// Copyright (C) 2008 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.
+//
+
+filegroup {
+    name: "RSUnitTests_java_srcs",
+    srcs: [
+        "src/**/*.java",
+    ],
+}
+
+filegroup {
+    name: "RSUnitTests_rscript_srcs",
+    srcs: [
+        "src/**/*.rscript",
+    ],
+}
+
+filegroup {
+    name: "RSUnitTests_java_gui",
+    srcs: [
+        "gui/**/*.java",
+    ],
+}
+
+filegroup {
+    name: "RSUnitTests_java_supportlibsrc_gen",
+    srcs: [
+        "supportlibsrc_gen/**/*.java",
+    ],
+}
+
+filegroup {
+    name: "RSUnitTests_rscript_supportlibsrc_gen",
+    srcs: [
+        "supportlibsrc_gen/**/*.rscript",
+    ],
+}
diff --git a/tests/java_api/RsTest/Android.bp b/tests/java_api/RsTest/Android.bp
new file mode 100644
index 0000000..3695234
--- /dev/null
+++ b/tests/java_api/RsTest/Android.bp
@@ -0,0 +1,62 @@
+//
+// Copyright (C) 2008 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.
+//
+
+package {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: [
+        "Android-Apache-2.0",
+    ],
+}
+
+android_test {
+    name: "RSTest",
+    static_libs: ["androidx.test.rules"],
+    srcs: [
+        "src/**/*.java",
+        ":RSUnitTests_java_srcs",
+        ":RSUnitTests_java_gui",
+        ":RSTest-rscript{RSTest.srcjar}",
+    ],
+    resource_zips: [
+        ":RSTest-rscript{RSTest.res.zip}",
+    ],
+    sdk_version: "current",
+    test_suites: ["device-tests"],
+}
+
+genrule {
+    name: "RSTest-rscript",
+    srcs: [
+        ":RSUnitTests_rscript_srcs",
+        ":rs_script_api",
+        ":rs_clang_headers",
+    ],
+    tools: [
+        "llvm-rs-cc",
+        "soong_zip",
+    ],
+    out: [
+        "RSTest.srcjar",
+        "RSTest.res.zip",
+    ],
+    cmd: "for f in $(locations :RSUnitTests_rscript_srcs); do " +
+        "  $(location llvm-rs-cc) -o $(genDir)/res/raw -p $(genDir)/src " +
+        "  -I $$(dirname $$(echo $(locations :rs_script_api) | awk '{ print $$1 }')) " +
+        "  -I $$(dirname $$(echo $(locations :rs_clang_headers) | awk '{ print $$1 }')) $${f}; " +
+        "done && " +
+        "$(location soong_zip) -srcjar -o $(location RSTest.srcjar) -C $(genDir)/src -D $(genDir)/src &&" +
+        "$(location soong_zip) -o $(location RSTest.res.zip) -C $(genDir)/res -D $(genDir)/res",
+}
diff --git a/tests/java_api/RsTest/Android.mk b/tests/java_api/RsTest/Android.mk
deleted file mode 100644
index 4f231b5..0000000
--- a/tests/java_api/RsTest/Android.mk
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Copyright (C) 2008 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)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_STATIC_JAVA_LIBRARIES := androidx.test.rules
-
-LOCAL_SRC_FILES := \
-    $(call all-java-files-under,src) \
-    $(call all-java-files-under,../RSUnitTests/gui) \
-    $(call all-java-files-under,../RSUnitTests/src) \
-    $(call all-renderscript-files-under,../RSUnitTests/src) \
-
-LOCAL_RENDERSCRIPT_TARGET_API := current
-
-LOCAL_PACKAGE_NAME := RSTest
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-LOCAL_COMPATIBILITY_SUITE := device-tests
-
-include $(BUILD_PACKAGE)