blob: 1a23db700c7d613dc8479f24d8fbe68d97e99562 [file] [log] [blame]
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -04001// Copyright 2021 Google Inc. All rights reserved.
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 bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/apex"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040020 "android/soong/cc"
21 "android/soong/java"
22
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040023 "testing"
24)
25
26func runApexTestCase(t *testing.T, tc bp2buildTestCase) {
27 t.Helper()
28 runBp2BuildTestCase(t, registerApexModuleTypes, tc)
29}
30
31func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040032 // CC module types needed as they can be APEX dependencies
33 cc.RegisterCCBuildComponents(ctx)
34
35 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
36 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
37 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
38 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040039}
40
41func TestApexBundleSimple(t *testing.T) {
42 runApexTestCase(t, bp2buildTestCase{
43 description: "apex - simple example",
44 moduleTypeUnderTest: "apex",
45 moduleTypeUnderTestFactory: apex.BundleFactory,
46 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
47 filesystem: map[string]string{},
48 blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040049apex_key {
50 name: "com.android.apogee.key",
51 public_key: "com.android.apogee.avbpubkey",
52 private_key: "com.android.apogee.pem",
53 bazel_module: { bp2build_available: false },
54}
55
56android_app_certificate {
57 name: "com.android.apogee.certificate",
58 certificate: "com.android.apogee",
59 bazel_module: { bp2build_available: false },
60}
61
62cc_library {
63 name: "native_shared_lib_1",
64 bazel_module: { bp2build_available: false },
65}
66
67cc_library {
68 name: "native_shared_lib_2",
69 bazel_module: { bp2build_available: false },
70}
71
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040072// TODO(b/194878861): Add bp2build support for prebuilt_etc
73cc_library {
74 name: "pretend_prebuilt_1",
75 bazel_module: { bp2build_available: false },
76}
77
78// TODO(b/194878861): Add bp2build support for prebuilt_etc
79cc_library {
80 name: "pretend_prebuilt_2",
81 bazel_module: { bp2build_available: false },
82}
83
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040084filegroup {
85 name: "com.android.apogee-file_contexts",
86 srcs: [
87 "com.android.apogee-file_contexts",
88 ],
89 bazel_module: { bp2build_available: false },
90}
91
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040092apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040093 name: "com.android.apogee",
94 manifest: "apogee_manifest.json",
95 androidManifest: "ApogeeAndroidManifest.xml",
96 file_contexts: "com.android.apogee-file_contexts",
97 min_sdk_version: "29",
98 key: "com.android.apogee.key",
99 certificate: "com.android.apogee.certificate",
100 updatable: false,
101 installable: false,
102 native_shared_libs: [
103 "native_shared_lib_1",
104 "native_shared_lib_2",
105 ],
106 binaries: [
107 "binary_1",
108 "binary_2",
109 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400110 prebuilts: [
111 "pretend_prebuilt_1",
112 "pretend_prebuilt_2",
113 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400114}
115`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500116 expectedBazelTargets: []string{
117 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
118 "android_manifest": `"ApogeeAndroidManifest.xml"`,
119 "binaries": `[
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400120 "binary_1",
121 "binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500122 ]`,
123 "certificate": `":com.android.apogee.certificate"`,
124 "file_contexts": `":com.android.apogee-file_contexts"`,
125 "installable": "False",
126 "key": `":com.android.apogee.key"`,
127 "manifest": `"apogee_manifest.json"`,
128 "min_sdk_version": `"29"`,
129 "native_shared_libs": `[
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400130 ":native_shared_lib_1",
131 ":native_shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500132 ]`,
133 "prebuilts": `[
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400134 ":pretend_prebuilt_1",
135 ":pretend_prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500136 ]`,
137 "updatable": "False",
138 }),
139 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400140}
141
142func TestApexBundleDefaultPropertyValues(t *testing.T) {
143 runApexTestCase(t, bp2buildTestCase{
144 description: "apex - default property values",
145 moduleTypeUnderTest: "apex",
146 moduleTypeUnderTestFactory: apex.BundleFactory,
147 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
148 filesystem: map[string]string{},
149 blueprint: `
150apex {
151 name: "com.android.apogee",
152 manifest: "apogee_manifest.json",
153}
154`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500155 expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{
156 "manifest": `"apogee_manifest.json"`,
157 }),
158 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400159}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000160
161func TestApexBundleHasBazelModuleProps(t *testing.T) {
162 runApexTestCase(t, bp2buildTestCase{
163 description: "apex - has bazel module props",
164 moduleTypeUnderTest: "apex",
165 moduleTypeUnderTestFactory: apex.BundleFactory,
166 moduleTypeUnderTestBp2BuildMutator: apex.ApexBundleBp2Build,
167 filesystem: map[string]string{},
168 blueprint: `
169apex {
170 name: "apogee",
171 manifest: "manifest.json",
172 bazel_module: { bp2build_available: true },
173}
174`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500175 expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{
176 "manifest": `"manifest.json"`,
177 }),
178 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000179}