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