1// Copyright (C) 2020 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package { 16 default_applicable_licenses: ["Android-Apache-2.0"], 17} 18 19java_test_host { 20 name: "CtsUsesNativeLibraryTest", 21 defaults: ["cts_defaults"], 22 srcs: ["src/**/*.java"], 23 test_suites: [ 24 "cts", 25 "general-tests", 26 ], 27 libs: [ 28 "cts-tradefed", 29 "tradefed", 30 "compatibility-host-util", 31 ], 32 java_resource_dirs: ["res"], 33 data: [":CtsUesNativeLibraryBuildPackage"], 34} 35 36// Note that this app is built as a java library. The actual app is built 37// by the test (CtsUsesNativeLibraryTest) while the test is running. 38// This java library is appended to the built apk by the test. 39java_library { 40 name: "CtsUsesNativeLibraryTestApp", 41 srcs: ["src_target/**/*.java"], 42 static_libs: [ 43 "androidx.test.core", 44 "androidx.test.runner", 45 "androidx.test.rules", 46 "compatibility-device-util-axt", 47 ], 48 sdk_version: "test_current", 49 compile_dex: true, 50 installable: false, 51 visibility: ["//visibility:private"], 52} 53 54// These are collection of tools and libraries that are required to build 55// an apk by the test. This zip file is extracted by the test and files 56// in the zip are executed from there. 57// 58// There are two tricks used here: 1) host tools such as aapt2 are listed 59// in the `tools` property although they technically are inputs of the zip, 60// not the tools for creating the zip. However, since the java test is not 61// specific to arch, it can't (transitively) depend on arch-specific (x86) 62// host tools. To work-around the problem, they are listed in the `tools` 63// property, and then used as inputs in the `cmd`. 64// 65// 2) signapk and libconscrypt_openjdk_jni are listed in the `host_required` 66// property instead of `tools` or `srcs`. This is because those modules are 67// neither specific to arch (thus can't be in tools), nor provide source (thus 68// can't be in srcs). To access them, their location in the soong intermediate 69// directory is manually searched in the cmd, while dependencies to them are 70// created using the `required` property. 71genrule { 72 name: "CtsUesNativeLibraryBuildPackage", 73 // srcs, tools, required are all "essentially" inputs of the zip 74 // (except for soong_zip which is actually the tool) 75 srcs: [ 76 ":CtsUsesNativeLibraryTestApp", 77 ":sdk_public_30_android", 78 "testkey.pk8", 79 "testkey.x509.pem", 80 ], 81 tools: [ 82 "aapt2", 83 "soong_zip", 84 "merge_zips", 85 // To make signapk.jar be generated under HOST_SOONG_OUT before this rule runes 86 "signapk", 87 ], 88 host_required: [ 89 "signapk", 90 "libconscrypt_openjdk_jni", 91 ], 92 out: ["CtsUesNativeLibraryBuildPackage.zip"], 93 // Copied from system/apex/apexer/Android.bp 94 cmd: "HOST_OUT_BIN=$$(dirname $(location soong_zip)) && " + 95 "HOST_SOONG_OUT=$$(dirname $$(dirname $$HOST_OUT_BIN)) && " + 96 "SIGNAPK_JAR=$$(find $$HOST_SOONG_OUT -name \"signapk*\") && " + 97 "LIBCONSCRYPT_OPENJDK_JNI=$$(find $$HOST_SOONG_OUT -name \"libconscrypt_openjdk_jni.*\") && " + 98 "rm -rf $(genDir)/content && " + 99 "mkdir -p $(genDir)/content && " + 100 "cp $(location aapt2) $(genDir)/content && " + 101 "cp $(location merge_zips) $(genDir)/content && " + 102 "cp $(location :sdk_public_30_android) $(genDir)/content && " + 103 "cp $(location :CtsUsesNativeLibraryTestApp) $(genDir)/content && " + 104 "cp $(location testkey.pk8) $(genDir)/content && " + 105 "cp $(location testkey.x509.pem) $(genDir)/content && " + 106 "cp $$SIGNAPK_JAR $(genDir)/content && " + 107 "cp $$LIBCONSCRYPT_OPENJDK_JNI $(genDir)/content && " + 108 "$(location soong_zip) -C $(genDir)/content -D $(genDir)/content -o $(out) && " + 109 "rm -rf $(genDir)/content ", 110 visibility: ["//visibility:private"], 111} 112