xref: /aosp_15_r20/cts/hostsidetests/library/Android.bp (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
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    default_team: "trendy_team_native_tools_libraries",
18}
19
20java_test_host {
21    name: "CtsUsesNativeLibraryTest",
22    defaults: ["cts_defaults"],
23    srcs: ["src/**/*.java"],
24    test_suites: [
25        "cts",
26        "general-tests",
27    ],
28    libs: [
29        "cts-tradefed",
30        "tradefed",
31        "compatibility-host-util",
32    ],
33    java_resource_dirs: ["res"],
34    device_common_data: [":CtsUseNativeLibraryBuildPackage"],
35}
36
37// Note that this app is built as a java library. The actual app is built
38// by the test (CtsUsesNativeLibraryTest) while the test is running.
39// This java library is appended to the built apk by the test.
40java_library {
41    name: "CtsUsesNativeLibraryTestApp",
42    srcs: ["src_target/**/*.java"],
43    static_libs: [
44        "androidx.test.core",
45        "androidx.test.runner",
46        "androidx.test.rules",
47        "compatibility-device-util-axt",
48    ],
49    sdk_version: "test_current",
50    compile_dex: true,
51    installable: false,
52    visibility: ["//visibility:private"],
53}
54
55// These are collection of tools and libraries that are required to build
56// an apk by the test. This zip file is extracted by the test and files
57// in the zip are executed from there.
58//
59// There are two tricks used here: 1) host tools such as aapt2 are listed
60// in the `tools` property although they technically are inputs of the zip,
61// not the tools for creating the zip. However, since the java test is not
62// specific to arch, it can't (transitively) depend on arch-specific (x86)
63// host tools. To work-around the problem, they are listed in the `tools`
64// property, and then used as inputs in the `cmd`.
65//
66// 2) signapk and libconscrypt_openjdk_jni are listed in the `host_required`
67// property instead of `tools` or `srcs`. This is because those modules are
68// neither specific to arch (thus can't be in tools), nor provide source (thus
69// can't be in srcs). To access them, their location in the soong intermediate
70// directory is manually searched in the cmd, while dependencies to them are
71// created using the `required` property.
72java_genrule {
73    name: "CtsUseNativeLibraryBuildPackage",
74    // srcs, tools, required are all "essentially" inputs of the zip
75    // (except for soong_zip which is actually the tool)
76    srcs: [
77        ":CtsUsesNativeLibraryTestApp",
78        ":sdk_public_30_android.jar",
79        "testkey.pk8",
80        "testkey.x509.pem",
81    ],
82    tools: [
83        "aapt2",
84        "soong_zip",
85        "merge_zips",
86        // To make signapk.jar be generated under HOST_SOONG_OUT before this rule runes
87        "signapk",
88    ],
89    host_required: [
90        "signapk",
91        "libconscrypt_openjdk_jni",
92    ],
93    out: ["CtsUseNativeLibraryBuildPackage.zip"],
94    // Copied from system/apex/apexer/Android.bp
95    cmd: "HOST_OUT_BIN=$$(dirname $(location soong_zip)) && " +
96        "HOST_SOONG_OUT=$$(dirname $$(dirname $$HOST_OUT_BIN)) && " +
97        "SIGNAPK_JAR=$$(find $$HOST_SOONG_OUT -name \"signapk*\") && " +
98        "LIBCONSCRYPT_OPENJDK_JNI=$$(find $$HOST_SOONG_OUT -name \"libconscrypt_openjdk_jni.*\") && " +
99        "rm -rf $(genDir)/content && " +
100        "mkdir -p $(genDir)/content && " +
101        "cp $(location aapt2) $(genDir)/content && " +
102        "cp $(location merge_zips) $(genDir)/content && " +
103        "cp $(location :sdk_public_30_android.jar) $(genDir)/content && " +
104        "cp $(location :CtsUsesNativeLibraryTestApp) $(genDir)/content && " +
105        "cp $(location testkey.pk8) $(genDir)/content && " +
106        "cp $(location testkey.x509.pem) $(genDir)/content && " +
107        "cp $$SIGNAPK_JAR $(genDir)/content && " +
108        "cp $$LIBCONSCRYPT_OPENJDK_JNI $(genDir)/content && " +
109        "$(location soong_zip) -C $(genDir)/content -D $(genDir)/content -o $(out) && " +
110        "rm -rf $(genDir)/content ",
111    visibility: ["//visibility:private"],
112}
113