blob: 2a58d01037dc2471a8a1d4f3bd9e60c64fc12b52 [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"
Jingwen Chendf165c92022-06-08 16:00:39 +000021 "android/soong/etc"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040022 "android/soong/java"
Jingwen Chenb07c9012021-12-08 10:05:45 +000023 "android/soong/sh"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040024
Vinh Tran8f5310f2022-10-07 18:16:47 -040025 "fmt"
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040026 "testing"
27)
28
Sam Delmerico3177a6e2022-06-21 19:28:33 +000029func runApexTestCase(t *testing.T, tc Bp2buildTestCase) {
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040030 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000031 RunBp2BuildTestCase(t, registerApexModuleTypes, tc)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040032}
33
34func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040035 // CC module types needed as they can be APEX dependencies
36 cc.RegisterCCBuildComponents(ctx)
37
Jingwen Chenb07c9012021-12-08 10:05:45 +000038 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
39 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040040 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
41 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
42 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
43 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Jingwen Chen81c67d32022-06-08 16:08:25 +000044 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Yu Liu4c212ce2022-10-14 12:20:20 -070045 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040046}
47
Sam Delmerico3177a6e2022-06-21 19:28:33 +000048func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) {
Wei Li1c66fc72022-05-09 23:59:14 -070049 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000050 RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc)
Wei Li1c66fc72022-05-09 23:59:14 -070051}
52
53func registerOverrideApexModuleTypes(ctx android.RegistrationContext) {
54 // CC module types needed as they can be APEX dependencies
55 cc.RegisterCCBuildComponents(ctx)
56
57 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
58 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
59 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
60 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
Liz Kammer1a1c9df2023-03-28 11:39:50 -040061 ctx.RegisterModuleType("apex_test", apex.TestApexBundleFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070062 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
63 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
64 ctx.RegisterModuleType("apex", apex.BundleFactory)
Cole Faust912bc882023-03-08 12:29:50 -080065 ctx.RegisterModuleType("apex_defaults", apex.DefaultsFactory)
Jingwen Chendf165c92022-06-08 16:00:39 +000066 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Cole Faust912bc882023-03-08 12:29:50 -080067 ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory)
68 ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070069}
70
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040071func TestApexBundleSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000072 runApexTestCase(t, Bp2buildTestCase{
73 Description: "apex - example with all props, file_context is a module in same Android.bp",
74 ModuleTypeUnderTest: "apex",
75 ModuleTypeUnderTestFactory: apex.BundleFactory,
76 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +000077 StubbedBuildDefinitions: []string{"com.android.apogee.key", "com.android.apogee.certificate", "native_shared_lib_1", "native_shared_lib_2",
78 "prebuilt_1", "prebuilt_2", "com.android.apogee-file_contexts", "cc_binary_1", "sh_binary_2"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +000079 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040080apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000081 name: "com.android.apogee.key",
82 public_key: "com.android.apogee.avbpubkey",
83 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040084}
85
86android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000087 name: "com.android.apogee.certificate",
88 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040089}
90
91cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000092 name: "native_shared_lib_1",
Jingwen Chenb07c9012021-12-08 10:05:45 +000093}
94
95cc_library {
96 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040097}
98
Jingwen Chen81c67d32022-06-08 16:08:25 +000099prebuilt_etc {
100 name: "prebuilt_1",
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400101}
102
Jingwen Chen81c67d32022-06-08 16:08:25 +0000103prebuilt_etc {
104 name: "prebuilt_2",
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400105}
106
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400107filegroup {
108 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000109 srcs: [
Wei Li1c66fc72022-05-09 23:59:14 -0700110 "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000111 ],
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400112}
113
Chris Parsonscd209032023-09-19 01:12:48 +0000114cc_binary { name: "cc_binary_1"}
115sh_binary { name: "sh_binary_2"}
Jingwen Chenb07c9012021-12-08 10:05:45 +0000116
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400117apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400118 name: "com.android.apogee",
119 manifest: "apogee_manifest.json",
120 androidManifest: "ApogeeAndroidManifest.xml",
Sam Delmericoe860d142023-06-06 15:47:30 -0400121 apex_available_name: "apogee_apex_name",
Wei Li1c66fc72022-05-09 23:59:14 -0700122 file_contexts: ":com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400123 min_sdk_version: "29",
124 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000125 certificate: ":com.android.apogee.certificate",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400126 updatable: false,
127 installable: false,
Wei Lif034cb42022-01-19 15:54:31 -0800128 compressible: false,
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400129 native_shared_libs: [
130 "native_shared_lib_1",
131 "native_shared_lib_2",
132 ],
133 binaries: [
Jingwen Chenb07c9012021-12-08 10:05:45 +0000134 "cc_binary_1",
135 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400136 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400137 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000138 "prebuilt_1",
139 "prebuilt_2",
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400140 ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000141 package_name: "com.android.apogee.test.package",
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000142 logging_parent: "logging.parent",
Sam Delmericoe860d142023-06-06 15:47:30 -0400143 variant_version: "3",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400144}
145`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000146 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000147 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Sam Delmericoe860d142023-06-06 15:47:30 -0400148 "android_manifest": `"ApogeeAndroidManifest.xml"`,
149 "apex_available_name": `"apogee_apex_name"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500150 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000151 ":cc_binary_1",
152 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500153 ]`,
154 "certificate": `":com.android.apogee.certificate"`,
155 "file_contexts": `":com.android.apogee-file_contexts"`,
156 "installable": "False",
157 "key": `":com.android.apogee.key"`,
158 "manifest": `"apogee_manifest.json"`,
159 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400160 "native_shared_libs_32": `select({
161 "//build/bazel/platforms/arch:arm": [
162 ":native_shared_lib_1",
163 ":native_shared_lib_2",
164 ],
165 "//build/bazel/platforms/arch:x86": [
166 ":native_shared_lib_1",
167 ":native_shared_lib_2",
168 ],
169 "//conditions:default": [],
170 })`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800171 "native_shared_libs_64": `select({
172 "//build/bazel/platforms/arch:arm64": [
173 ":native_shared_lib_1",
174 ":native_shared_lib_2",
175 ],
176 "//build/bazel/platforms/arch:x86_64": [
177 ":native_shared_lib_1",
178 ":native_shared_lib_2",
179 ],
180 "//conditions:default": [],
181 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500182 "prebuilts": `[
Jingwen Chen81c67d32022-06-08 16:08:25 +0000183 ":prebuilt_1",
184 ":prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500185 ]`,
Sam Delmericoe860d142023-06-06 15:47:30 -0400186 "updatable": "False",
187 "compressible": "False",
188 "package_name": `"com.android.apogee.test.package"`,
189 "logging_parent": `"logging.parent"`,
190 "variant_version": `"3"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500191 }),
192 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400193}
194
Wei Li1c66fc72022-05-09 23:59:14 -0700195func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000196 runApexTestCase(t, Bp2buildTestCase{
197 Description: "apex - file contexts is a module in another Android.bp",
198 ModuleTypeUnderTest: "apex",
199 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000200 StubbedBuildDefinitions: []string{"//a/b:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000201 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700202 "a/b/Android.bp": `
203filegroup {
204 name: "com.android.apogee-file_contexts",
205 srcs: [
206 "com.android.apogee-file_contexts",
207 ],
Wei Li1c66fc72022-05-09 23:59:14 -0700208}
209`,
210 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000211 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700212apex {
213 name: "com.android.apogee",
214 file_contexts: ":com.android.apogee-file_contexts",
215}
216`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000217 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000218 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700219 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700220 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700221 }),
222 }})
223}
224
225func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000226 runApexTestCase(t, Bp2buildTestCase{
227 Description: "apex - file contexts is a file",
228 ModuleTypeUnderTest: "apex",
229 ModuleTypeUnderTestFactory: apex.BundleFactory,
230 Filesystem: map[string]string{},
231 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700232apex {
233 name: "com.android.apogee",
234 file_contexts: "file_contexts_file",
235}
236`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000237 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000238 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700239 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700240 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700241 }),
242 }})
243}
244
245func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000246 runApexTestCase(t, Bp2buildTestCase{
247 Description: "apex - file contexts is not specified",
248 ModuleTypeUnderTest: "apex",
249 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000250 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000251 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700252 "system/sepolicy/apex/Android.bp": `
253filegroup {
254 name: "com.android.apogee-file_contexts",
255 srcs: [
256 "com.android.apogee-file_contexts",
257 ],
Wei Li1c66fc72022-05-09 23:59:14 -0700258}
259`,
260 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000261 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700262apex {
263 name: "com.android.apogee",
264}
265`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000266 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000267 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700268 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700269 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700270 }),
271 }})
272}
273
Yu Liu4ae55d12022-01-05 17:17:23 -0800274func TestApexBundleCompileMultilibBoth(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000275 runApexTestCase(t, Bp2buildTestCase{
276 Description: "apex - example with compile_multilib=both",
277 ModuleTypeUnderTest: "apex",
278 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000279 StubbedBuildDefinitions: append(multilibStubNames(), "//system/sepolicy/apex:com.android.apogee-file_contexts"),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000280 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700281 "system/sepolicy/apex/Android.bp": `
282filegroup {
283 name: "com.android.apogee-file_contexts",
284 srcs: [ "apogee-file_contexts", ],
Wei Li1c66fc72022-05-09 23:59:14 -0700285}
286`,
287 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400288 Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000289 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000290 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800291 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400292 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000293 ":native_shared_lib_for_both",
294 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800295 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000296 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
297 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800298 "//conditions:default": [],
299 })`,
300 "native_shared_libs_64": `select({
301 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400302 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000303 ":native_shared_lib_for_both",
304 ":native_shared_lib_for_lib64",
305 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800306 ],
307 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400308 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000309 ":native_shared_lib_for_both",
310 ":native_shared_lib_for_lib64",
311 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800312 ],
313 "//conditions:default": [],
314 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700315 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700316 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800317 }),
318 }})
319}
320
Vinh Tran8f5310f2022-10-07 18:16:47 -0400321func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
322 expectedBazelTargets := []string{
323 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
324 "native_shared_libs_32": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800325 "//build/bazel/platforms/arch:arm": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400326 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000327 ":native_shared_lib_for_both",
328 ":native_shared_lib_for_lib32",
329 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800330 ],
331 "//build/bazel/platforms/arch:x86": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400332 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000333 ":native_shared_lib_for_both",
334 ":native_shared_lib_for_lib32",
335 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800336 ],
337 "//conditions:default": [],
338 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400339 "native_shared_libs_64": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800340 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400341 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000342 ":native_shared_lib_for_both",
343 ":native_shared_lib_for_lib64",
344 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800345 ],
346 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400347 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000348 ":native_shared_lib_for_both",
349 ":native_shared_lib_for_lib64",
350 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800351 ],
352 "//conditions:default": [],
353 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400354 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
355 "manifest": `"apex_manifest.json"`,
356 }),
357 }
358
359 // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
360 // should result to the same bp2build output
361 compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
362 for _, compileMultiLibProp := range compileMultiLibPropValues {
363 descriptionSuffix := compileMultiLibProp
364 if descriptionSuffix == "" {
365 descriptionSuffix = "compile_multilib unset"
366 }
367 runApexTestCase(t, Bp2buildTestCase{
368 Description: "apex - example with " + compileMultiLibProp,
369 ModuleTypeUnderTest: "apex",
370 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000371 StubbedBuildDefinitions: append(multilibStubNames(), "//system/sepolicy/apex:com.android.apogee-file_contexts"),
Vinh Tran8f5310f2022-10-07 18:16:47 -0400372 Filesystem: map[string]string{
373 "system/sepolicy/apex/Android.bp": `
374 filegroup {
375 name: "com.android.apogee-file_contexts",
376 srcs: [ "apogee-file_contexts", ],
Vinh Tran8f5310f2022-10-07 18:16:47 -0400377 }
378 `,
379 },
380 Blueprint: createMultilibBlueprint(compileMultiLibProp),
381 ExpectedBazelTargets: expectedBazelTargets,
382 })
383 }
Yu Liu4ae55d12022-01-05 17:17:23 -0800384}
385
386func TestApexBundleCompileMultilib32(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000387 runApexTestCase(t, Bp2buildTestCase{
388 Description: "apex - example with compile_multilib=32",
389 ModuleTypeUnderTest: "apex",
390 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000391 StubbedBuildDefinitions: append(multilibStubNames(), "//system/sepolicy/apex:com.android.apogee-file_contexts"),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000392 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700393 "system/sepolicy/apex/Android.bp": `
394filegroup {
395 name: "com.android.apogee-file_contexts",
396 srcs: [ "apogee-file_contexts", ],
Wei Li1c66fc72022-05-09 23:59:14 -0700397}
398`,
399 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400400 Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000401 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000402 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800403 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400404 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000405 ":native_shared_lib_for_both",
406 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800407 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000408 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
409 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800410 "//conditions:default": [],
411 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700412 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700413 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800414 }),
415 }})
416}
417
418func TestApexBundleCompileMultilib64(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000419 runApexTestCase(t, Bp2buildTestCase{
420 Description: "apex - example with compile_multilib=64",
421 ModuleTypeUnderTest: "apex",
422 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000423 StubbedBuildDefinitions: append(multilibStubNames(), "//system/sepolicy/apex:com.android.apogee-file_contexts"),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000424 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700425 "system/sepolicy/apex/Android.bp": `
426filegroup {
427 name: "com.android.apogee-file_contexts",
428 srcs: [ "apogee-file_contexts", ],
Wei Li1c66fc72022-05-09 23:59:14 -0700429}
430`,
431 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400432 Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000433 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000434 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800435 "native_shared_libs_64": `select({
436 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400437 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000438 ":native_shared_lib_for_both",
439 ":native_shared_lib_for_lib64",
440 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800441 ],
442 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400443 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000444 ":native_shared_lib_for_both",
445 ":native_shared_lib_for_lib64",
446 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800447 ],
448 "//conditions:default": [],
449 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700450 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700451 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800452 }),
453 }})
454}
455
Chris Parsonscd209032023-09-19 01:12:48 +0000456func multilibStubNames() []string {
457 return []string{"native_shared_lib_for_both", "native_shared_lib_for_first", "native_shared_lib_for_lib32", "native_shared_lib_for_lib64",
458 "native_shared_lib_for_lib64", "unnested_native_shared_lib"}
459}
460
Jingwen Chen34feb142022-10-06 13:02:30 +0000461func createMultilibBlueprint(compile_multilib string) string {
Vinh Tran8f5310f2022-10-07 18:16:47 -0400462 return fmt.Sprintf(`
Jingwen Chen34feb142022-10-06 13:02:30 +0000463cc_library {
464 name: "native_shared_lib_for_both",
Jingwen Chen34feb142022-10-06 13:02:30 +0000465}
466
467cc_library {
468 name: "native_shared_lib_for_first",
Jingwen Chen34feb142022-10-06 13:02:30 +0000469}
470
471cc_library {
472 name: "native_shared_lib_for_lib32",
Jingwen Chen34feb142022-10-06 13:02:30 +0000473}
474
475cc_library {
476 name: "native_shared_lib_for_lib64",
Jingwen Chen34feb142022-10-06 13:02:30 +0000477}
478
Vinh Tran8f5310f2022-10-07 18:16:47 -0400479cc_library {
480 name: "unnested_native_shared_lib",
Vinh Tran8f5310f2022-10-07 18:16:47 -0400481}
482
Jingwen Chen34feb142022-10-06 13:02:30 +0000483apex {
484 name: "com.android.apogee",
Vinh Tran8f5310f2022-10-07 18:16:47 -0400485 %s
486 native_shared_libs: ["unnested_native_shared_lib"],
Jingwen Chen34feb142022-10-06 13:02:30 +0000487 multilib: {
488 both: {
489 native_shared_libs: [
490 "native_shared_lib_for_both",
491 ],
492 },
493 first: {
494 native_shared_libs: [
495 "native_shared_lib_for_first",
496 ],
497 },
498 lib32: {
499 native_shared_libs: [
500 "native_shared_lib_for_lib32",
501 ],
502 },
503 lib64: {
504 native_shared_libs: [
505 "native_shared_lib_for_lib64",
506 ],
507 },
508 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400509}`, compile_multilib)
Jingwen Chen34feb142022-10-06 13:02:30 +0000510}
511
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400512func TestApexBundleDefaultPropertyValues(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000513 runApexTestCase(t, Bp2buildTestCase{
514 Description: "apex - default property values",
515 ModuleTypeUnderTest: "apex",
516 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000517 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000518 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700519 "system/sepolicy/apex/Android.bp": `
520filegroup {
521 name: "com.android.apogee-file_contexts",
522 srcs: [ "apogee-file_contexts", ],
Wei Li1c66fc72022-05-09 23:59:14 -0700523}
524`,
525 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000526 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400527apex {
528 name: "com.android.apogee",
529 manifest: "apogee_manifest.json",
530}
531`,
Alixe06d75b2022-08-31 18:28:19 +0000532 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700533 "manifest": `"apogee_manifest.json"`,
534 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500535 }),
536 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400537}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000538
539func TestApexBundleHasBazelModuleProps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000540 runApexTestCase(t, Bp2buildTestCase{
541 Description: "apex - has bazel module props",
542 ModuleTypeUnderTest: "apex",
543 ModuleTypeUnderTestFactory: apex.BundleFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000544 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000545 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700546 "system/sepolicy/apex/Android.bp": `
547filegroup {
548 name: "apogee-file_contexts",
549 srcs: [ "apogee-file_contexts", ],
Wei Li1c66fc72022-05-09 23:59:14 -0700550}
551`,
552 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000553 Blueprint: `
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000554apex {
555 name: "apogee",
556 manifest: "manifest.json",
557 bazel_module: { bp2build_available: true },
558}
559`,
Alixe06d75b2022-08-31 18:28:19 +0000560 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700561 "manifest": `"manifest.json"`,
562 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500563 }),
564 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000565}
Yu Liu4ae55d12022-01-05 17:17:23 -0800566
Wei Li1c66fc72022-05-09 23:59:14 -0700567func TestBp2BuildOverrideApex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000568 runOverrideApexTestCase(t, Bp2buildTestCase{
569 Description: "override_apex",
570 ModuleTypeUnderTest: "override_apex",
571 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
572 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +0000573 StubbedBuildDefinitions: []string{"com.android.apogee.key", "com.android.apogee.certificate", "native_shared_lib_1",
574 "native_shared_lib_2", "prebuilt_1", "prebuilt_2", "com.android.apogee-file_contexts", "cc_binary_1",
575 "sh_binary_2", "com.android.apogee", "com.google.android.apogee.key", "com.google.android.apogee.certificate"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000576 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700577apex_key {
578 name: "com.android.apogee.key",
579 public_key: "com.android.apogee.avbpubkey",
580 private_key: "com.android.apogee.pem",
Wei Li1c66fc72022-05-09 23:59:14 -0700581}
582
583android_app_certificate {
584 name: "com.android.apogee.certificate",
585 certificate: "com.android.apogee",
Wei Li1c66fc72022-05-09 23:59:14 -0700586}
587
588cc_library {
589 name: "native_shared_lib_1",
Wei Li1c66fc72022-05-09 23:59:14 -0700590}
591
592cc_library {
593 name: "native_shared_lib_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700594}
595
Jingwen Chen81c67d32022-06-08 16:08:25 +0000596prebuilt_etc {
597 name: "prebuilt_1",
Wei Li1c66fc72022-05-09 23:59:14 -0700598}
599
Jingwen Chen81c67d32022-06-08 16:08:25 +0000600prebuilt_etc {
601 name: "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700602}
603
604filegroup {
605 name: "com.android.apogee-file_contexts",
606 srcs: [
607 "com.android.apogee-file_contexts",
608 ],
Wei Li1c66fc72022-05-09 23:59:14 -0700609}
610
Chris Parsonscd209032023-09-19 01:12:48 +0000611cc_binary { name: "cc_binary_1" }
612sh_binary { name: "sh_binary_2" }
Wei Li1c66fc72022-05-09 23:59:14 -0700613
614apex {
615 name: "com.android.apogee",
616 manifest: "apogee_manifest.json",
617 androidManifest: "ApogeeAndroidManifest.xml",
618 file_contexts: ":com.android.apogee-file_contexts",
619 min_sdk_version: "29",
620 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000621 certificate: ":com.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700622 updatable: false,
623 installable: false,
624 compressible: false,
625 native_shared_libs: [
626 "native_shared_lib_1",
627 "native_shared_lib_2",
628 ],
629 binaries: [
630 "cc_binary_1",
631 "sh_binary_2",
632 ],
633 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000634 "prebuilt_1",
635 "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700636 ],
Wei Li1c66fc72022-05-09 23:59:14 -0700637}
638
639apex_key {
640 name: "com.google.android.apogee.key",
641 public_key: "com.google.android.apogee.avbpubkey",
642 private_key: "com.google.android.apogee.pem",
Wei Li1c66fc72022-05-09 23:59:14 -0700643}
644
645android_app_certificate {
646 name: "com.google.android.apogee.certificate",
647 certificate: "com.google.android.apogee",
Wei Li1c66fc72022-05-09 23:59:14 -0700648}
649
650override_apex {
651 name: "com.google.android.apogee",
652 base: ":com.android.apogee",
653 key: "com.google.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000654 certificate: ":com.google.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700655 prebuilts: [],
656 compressible: true,
657}
658`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000659 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000660 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700661 "android_manifest": `"ApogeeAndroidManifest.xml"`,
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000662 "base_apex_name": `"com.android.apogee"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700663 "binaries": `[
664 ":cc_binary_1",
665 ":sh_binary_2",
666 ]`,
667 "certificate": `":com.google.android.apogee.certificate"`,
668 "file_contexts": `":com.android.apogee-file_contexts"`,
669 "installable": "False",
670 "key": `":com.google.android.apogee.key"`,
671 "manifest": `"apogee_manifest.json"`,
672 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400673 "native_shared_libs_32": `select({
674 "//build/bazel/platforms/arch:arm": [
675 ":native_shared_lib_1",
676 ":native_shared_lib_2",
677 ],
678 "//build/bazel/platforms/arch:x86": [
679 ":native_shared_lib_1",
680 ":native_shared_lib_2",
681 ],
682 "//conditions:default": [],
683 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700684 "native_shared_libs_64": `select({
685 "//build/bazel/platforms/arch:arm64": [
686 ":native_shared_lib_1",
687 ":native_shared_lib_2",
688 ],
689 "//build/bazel/platforms/arch:x86_64": [
690 ":native_shared_lib_1",
691 ":native_shared_lib_2",
692 ],
693 "//conditions:default": [],
694 })`,
695 "prebuilts": `[]`,
696 "updatable": "False",
697 "compressible": "True",
698 }),
699 }})
700}
Wei Li40f98732022-05-20 22:08:11 -0700701
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400702func TestOverrideApexTest(t *testing.T) {
703 runOverrideApexTestCase(t, Bp2buildTestCase{
704 Description: "override_apex",
705 ModuleTypeUnderTest: "override_apex",
706 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
707 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +0000708 StubbedBuildDefinitions: []string{"com.android.apogee.certificate", "native_shared_lib_1",
709 "prebuilt_1", "com.android.apogee-file_contexts", "cc_binary_1", "sh_binary_2",
710 "com.android.apogee", "com.google.android.apogee.key", "com.google.android.apogee.certificate", "com.android.apogee.key"},
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400711 Blueprint: `
712apex_key {
713 name: "com.android.apogee.key",
714 public_key: "com.android.apogee.avbpubkey",
715 private_key: "com.android.apogee.pem",
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400716}
717
718android_app_certificate {
719 name: "com.android.apogee.certificate",
720 certificate: "com.android.apogee",
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400721}
722
723cc_library {
724 name: "native_shared_lib_1",
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400725}
726
727prebuilt_etc {
728 name: "prebuilt_1",
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400729}
730
731filegroup {
732 name: "com.android.apogee-file_contexts",
733 srcs: [
734 "com.android.apogee-file_contexts",
735 ],
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400736}
737
Chris Parsonscd209032023-09-19 01:12:48 +0000738cc_binary { name: "cc_binary_1"}
739sh_binary { name: "sh_binary_2"}
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400740
741apex_test {
742 name: "com.android.apogee",
743 manifest: "apogee_manifest.json",
744 androidManifest: "ApogeeAndroidManifest.xml",
745 file_contexts: ":com.android.apogee-file_contexts",
746 min_sdk_version: "29",
747 key: "com.android.apogee.key",
748 certificate: ":com.android.apogee.certificate",
749 updatable: false,
750 installable: false,
751 compressible: false,
752 native_shared_libs: [
753 "native_shared_lib_1",
754 ],
755 binaries: [
756 "cc_binary_1",
757 "sh_binary_2",
758 ],
759 prebuilts: [
760 "prebuilt_1",
761 ],
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400762}
763
764apex_key {
765 name: "com.google.android.apogee.key",
766 public_key: "com.google.android.apogee.avbpubkey",
767 private_key: "com.google.android.apogee.pem",
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400768}
769
770android_app_certificate {
771 name: "com.google.android.apogee.certificate",
772 certificate: "com.google.android.apogee",
Liz Kammer1a1c9df2023-03-28 11:39:50 -0400773}
774
775override_apex {
776 name: "com.google.android.apogee",
777 base: ":com.android.apogee",
778 key: "com.google.android.apogee.key",
779 certificate: ":com.google.android.apogee.certificate",
780 prebuilts: [],
781 compressible: true,
782}
783`,
784 ExpectedBazelTargets: []string{
785 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
786 "android_manifest": `"ApogeeAndroidManifest.xml"`,
787 "base_apex_name": `"com.android.apogee"`,
788 "binaries": `[
789 ":cc_binary_1",
790 ":sh_binary_2",
791 ]`,
792 "certificate": `":com.google.android.apogee.certificate"`,
793 "file_contexts": `":com.android.apogee-file_contexts"`,
794 "installable": "False",
795 "key": `":com.google.android.apogee.key"`,
796 "manifest": `"apogee_manifest.json"`,
797 "min_sdk_version": `"29"`,
798 "native_shared_libs_32": `select({
799 "//build/bazel/platforms/arch:arm": [":native_shared_lib_1"],
800 "//build/bazel/platforms/arch:x86": [":native_shared_lib_1"],
801 "//conditions:default": [],
802 })`,
803 "native_shared_libs_64": `select({
804 "//build/bazel/platforms/arch:arm64": [":native_shared_lib_1"],
805 "//build/bazel/platforms/arch:x86_64": [":native_shared_lib_1"],
806 "//conditions:default": [],
807 })`,
808 "testonly": "True",
809 "prebuilts": `[]`,
810 "updatable": "False",
811 "compressible": "True",
812 }),
813 }})
814}
815
Wei Li40f98732022-05-20 22:08:11 -0700816func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000817 runOverrideApexTestCase(t, Bp2buildTestCase{
818 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
819 ModuleTypeUnderTest: "override_apex",
820 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000821 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000822 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700823 "system/sepolicy/apex/Android.bp": `
824filegroup {
825 name: "com.android.apogee-file_contexts",
826 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700827}`,
828 "a/b/Android.bp": `
829apex {
830 name: "com.android.apogee",
831 bazel_module: { bp2build_available: false },
832}
833`,
834 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000835 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700836override_apex {
837 name: "com.google.android.apogee",
838 base: ":com.android.apogee",
839}
840`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000841 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000842 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000843 "base_apex_name": `"com.android.apogee"`,
844 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
845 "manifest": `"//a/b:apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700846 }),
847 }})
848}
849
850func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000851 runOverrideApexTestCase(t, Bp2buildTestCase{
852 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
853 ModuleTypeUnderTest: "override_apex",
854 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000855 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000856 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700857 "system/sepolicy/apex/Android.bp": `
858filegroup {
859 name: "com.android.apogee-file_contexts",
860 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700861}`,
862 "a/b/Android.bp": `
863apex {
864 name: "com.android.apogee",
865 manifest: "apogee_manifest.json",
866 bazel_module: { bp2build_available: false },
867}
868`,
869 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000870 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700871override_apex {
872 name: "com.google.android.apogee",
873 base: ":com.android.apogee",
874}
875`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000876 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000877 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000878 "base_apex_name": `"com.android.apogee"`,
879 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
880 "manifest": `"//a/b:apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700881 }),
882 }})
883}
884
885func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000886 runOverrideApexTestCase(t, Bp2buildTestCase{
887 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
888 ModuleTypeUnderTest: "override_apex",
889 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000890 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000891 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700892 "system/sepolicy/apex/Android.bp": `
893filegroup {
894 name: "com.android.apogee-file_contexts",
895 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700896}`,
897 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000898 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700899apex {
900 name: "com.android.apogee",
901 bazel_module: { bp2build_available: false },
902}
903
904override_apex {
905 name: "com.google.android.apogee",
906 base: ":com.android.apogee",
907}
908`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000909 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000910 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000911 "base_apex_name": `"com.android.apogee"`,
912 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
913 "manifest": `"apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700914 }),
915 }})
916}
917
918func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000919 runOverrideApexTestCase(t, Bp2buildTestCase{
920 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
921 ModuleTypeUnderTest: "override_apex",
922 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000923 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000924 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700925 "system/sepolicy/apex/Android.bp": `
926filegroup {
927 name: "com.android.apogee-file_contexts",
928 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700929}`,
930 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000931 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700932apex {
933 name: "com.android.apogee",
934 manifest: "apogee_manifest.json",
935 bazel_module: { bp2build_available: false },
936}
937
938override_apex {
939 name: "com.google.android.apogee",
940 base: ":com.android.apogee",
941}
942`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000943 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000944 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000945 "base_apex_name": `"com.android.apogee"`,
946 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
947 "manifest": `"apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700948 }),
949 }})
950}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000951
952func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000953 runOverrideApexTestCase(t, Bp2buildTestCase{
954 Description: "override_apex - override package name",
955 ModuleTypeUnderTest: "override_apex",
956 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000957 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000958 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000959 "system/sepolicy/apex/Android.bp": `
960filegroup {
961 name: "com.android.apogee-file_contexts",
962 srcs: [ "apogee-file_contexts", ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000963}`,
964 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000965 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000966apex {
967 name: "com.android.apogee",
968 bazel_module: { bp2build_available: false },
969}
970
971override_apex {
972 name: "com.google.android.apogee",
973 base: ":com.android.apogee",
974 package_name: "com.google.android.apogee",
975}
976`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000977 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000978 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000979 "base_apex_name": `"com.android.apogee"`,
980 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
981 "manifest": `"apex_manifest.json"`,
982 "package_name": `"com.google.android.apogee"`,
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000983 }),
984 }})
985}
Jingwen Chendf165c92022-06-08 16:00:39 +0000986
987func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000988 runOverrideApexTestCase(t, Bp2buildTestCase{
989 Description: "override_apex - no override",
990 ModuleTypeUnderTest: "override_apex",
991 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000992 StubbedBuildDefinitions: []string{"prebuilt_file", "com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000993 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000994 "system/sepolicy/apex/Android.bp": `
995filegroup {
996 name: "com.android.apogee-file_contexts",
997 srcs: [ "apogee-file_contexts", ],
Jingwen Chendf165c92022-06-08 16:00:39 +0000998}`,
999 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001000 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001001prebuilt_etc {
1002 name: "prebuilt_file",
Jingwen Chendf165c92022-06-08 16:00:39 +00001003}
1004
1005apex {
1006 name: "com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001007 prebuilts: ["prebuilt_file"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001008}
1009
1010override_apex {
1011 name: "com.google.android.apogee",
1012 base: ":com.android.apogee",
1013}
1014`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001015 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001016 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001017 "base_apex_name": `"com.android.apogee"`,
1018 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1019 "manifest": `"apex_manifest.json"`,
1020 "prebuilts": `[":prebuilt_file"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001021 }),
1022 }})
1023}
1024
1025func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001026 runOverrideApexTestCase(t, Bp2buildTestCase{
1027 Description: "override_apex - ooverride",
1028 ModuleTypeUnderTest: "override_apex",
1029 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001030 StubbedBuildDefinitions: []string{"prebuilt_file", "prebuilt_file2", "com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001031 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001032 "system/sepolicy/apex/Android.bp": `
1033filegroup {
1034 name: "com.android.apogee-file_contexts",
1035 srcs: [ "apogee-file_contexts", ],
Jingwen Chendf165c92022-06-08 16:00:39 +00001036}`,
1037 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001038 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001039prebuilt_etc {
1040 name: "prebuilt_file",
Jingwen Chendf165c92022-06-08 16:00:39 +00001041}
1042
1043prebuilt_etc {
1044 name: "prebuilt_file2",
Jingwen Chendf165c92022-06-08 16:00:39 +00001045}
1046
1047apex {
1048 name: "com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001049 prebuilts: ["prebuilt_file"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001050}
1051
1052override_apex {
1053 name: "com.google.android.apogee",
1054 base: ":com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001055 prebuilts: ["prebuilt_file2"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001056}
1057`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001058 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001059 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001060 "base_apex_name": `"com.android.apogee"`,
1061 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1062 "manifest": `"apex_manifest.json"`,
1063 "prebuilts": `[":prebuilt_file2"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001064 }),
1065 }})
1066}
1067
1068func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001069 runOverrideApexTestCase(t, Bp2buildTestCase{
1070 Description: "override_apex - override with empty list",
1071 ModuleTypeUnderTest: "override_apex",
1072 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001073 StubbedBuildDefinitions: []string{"prebuilt_file", "com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001074 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001075 "system/sepolicy/apex/Android.bp": `
1076filegroup {
1077 name: "com.android.apogee-file_contexts",
1078 srcs: [ "apogee-file_contexts", ],
Jingwen Chendf165c92022-06-08 16:00:39 +00001079}`,
1080 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001081 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001082prebuilt_etc {
1083 name: "prebuilt_file",
Jingwen Chendf165c92022-06-08 16:00:39 +00001084}
1085
1086apex {
1087 name: "com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001088 prebuilts: ["prebuilt_file"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001089}
1090
1091override_apex {
1092 name: "com.google.android.apogee",
1093 base: ":com.android.apogee",
1094 prebuilts: [],
1095}
1096`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001097 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001098 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001099 "base_apex_name": `"com.android.apogee"`,
1100 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1101 "manifest": `"apex_manifest.json"`,
1102 "prebuilts": `[]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001103 }),
1104 }})
1105}
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001106
1107func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001108 runOverrideApexTestCase(t, Bp2buildTestCase{
1109 Description: "override_apex - logging_parent - no override",
1110 ModuleTypeUnderTest: "override_apex",
1111 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001112 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001113 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001114 "system/sepolicy/apex/Android.bp": `
1115filegroup {
1116 name: "com.android.apogee-file_contexts",
1117 srcs: [ "apogee-file_contexts", ],
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001118}`,
1119 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001120 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001121apex {
1122 name: "com.android.apogee",
1123 bazel_module: { bp2build_available: false },
1124 logging_parent: "foo.bar.baz",
1125}
1126
1127override_apex {
1128 name: "com.google.android.apogee",
1129 base: ":com.android.apogee",
1130}
1131`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001132 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001133 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001134 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001135 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1136 "manifest": `"apex_manifest.json"`,
1137 "logging_parent": `"foo.bar.baz"`,
1138 }),
1139 }})
1140}
1141
1142func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001143 runOverrideApexTestCase(t, Bp2buildTestCase{
1144 Description: "override_apex - logging_parent - override",
1145 ModuleTypeUnderTest: "override_apex",
1146 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001147 StubbedBuildDefinitions: []string{"//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001148 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001149 "system/sepolicy/apex/Android.bp": `
1150filegroup {
1151 name: "com.android.apogee-file_contexts",
1152 srcs: [ "apogee-file_contexts", ],
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001153}`,
1154 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001155 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001156apex {
1157 name: "com.android.apogee",
1158 bazel_module: { bp2build_available: false },
1159 logging_parent: "foo.bar.baz",
1160}
1161
1162override_apex {
1163 name: "com.google.android.apogee",
1164 base: ":com.android.apogee",
1165 logging_parent: "foo.bar.baz.override",
1166}
1167`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001168 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001169 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001170 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001171 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1172 "manifest": `"apex_manifest.json"`,
1173 "logging_parent": `"foo.bar.baz.override"`,
1174 }),
1175 }})
1176}
Jingwen Chenbea58092022-09-29 16:56:02 +00001177
1178func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1179 runOverrideApexTestCase(t, Bp2buildTestCase{
1180 Description: "override_apex - don't set default certificate",
1181 ModuleTypeUnderTest: "override_apex",
1182 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1183 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001184 StubbedBuildDefinitions: []string{"com.android.apogee.certificate", "com.android.apogee-file_contexts", "com.android.apogee"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001185 Blueprint: `
1186android_app_certificate {
1187 name: "com.android.apogee.certificate",
1188 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001189}
1190
1191filegroup {
1192 name: "com.android.apogee-file_contexts",
1193 srcs: [
1194 "com.android.apogee-file_contexts",
1195 ],
Jingwen Chenbea58092022-09-29 16:56:02 +00001196}
1197
1198apex {
1199 name: "com.android.apogee",
1200 manifest: "apogee_manifest.json",
1201 file_contexts: ":com.android.apogee-file_contexts",
1202 certificate: ":com.android.apogee.certificate",
Jingwen Chenbea58092022-09-29 16:56:02 +00001203}
1204
1205override_apex {
1206 name: "com.google.android.apogee",
1207 base: ":com.android.apogee",
1208 // certificate is deliberately omitted, and not converted to bazel,
1209 // because the overridden apex shouldn't be using the base apex's cert.
1210}
1211`,
1212 ExpectedBazelTargets: []string{
1213 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001214 "base_apex_name": `"com.android.apogee"`,
1215 "file_contexts": `":com.android.apogee-file_contexts"`,
1216 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001217 }),
1218 }})
1219}
1220
1221func TestApexCertificateIsModule(t *testing.T) {
1222 runApexTestCase(t, Bp2buildTestCase{
1223 Description: "apex - certificate is module",
1224 ModuleTypeUnderTest: "apex",
1225 ModuleTypeUnderTestFactory: apex.BundleFactory,
1226 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001227 StubbedBuildDefinitions: []string{"com.android.apogee-file_contexts", "com.android.apogee.certificate"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001228 Blueprint: `
1229android_app_certificate {
1230 name: "com.android.apogee.certificate",
1231 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001232}
1233
1234apex {
1235 name: "com.android.apogee",
1236 manifest: "apogee_manifest.json",
1237 file_contexts: ":com.android.apogee-file_contexts",
1238 certificate: ":com.android.apogee.certificate",
1239}
Chris Parsonscd209032023-09-19 01:12:48 +00001240` + simpleModule("filegroup", "com.android.apogee-file_contexts"),
Jingwen Chenbea58092022-09-29 16:56:02 +00001241 ExpectedBazelTargets: []string{
1242 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1243 "certificate": `":com.android.apogee.certificate"`,
1244 "file_contexts": `":com.android.apogee-file_contexts"`,
1245 "manifest": `"apogee_manifest.json"`,
1246 }),
1247 }})
1248}
1249
Vinh Tran55225e32022-12-20 10:38:48 -05001250func TestApexWithStubLib(t *testing.T) {
1251 runApexTestCase(t, Bp2buildTestCase{
1252 Description: "apex - static variant of stub lib should not have apex_available tag",
1253 ModuleTypeUnderTest: "apex",
1254 ModuleTypeUnderTestFactory: apex.BundleFactory,
1255 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001256 StubbedBuildDefinitions: []string{"myapex-file_contexts"},
Vinh Tran55225e32022-12-20 10:38:48 -05001257 Blueprint: `
1258cc_library{
1259 name: "foo",
1260 stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
1261 apex_available: ["myapex"],
1262}
1263
1264cc_binary{
1265 name: "bar",
1266 static_libs: ["foo"],
1267 apex_available: ["myapex"],
1268}
1269
1270apex {
1271 name: "myapex",
1272 manifest: "myapex_manifest.json",
1273 file_contexts: ":myapex-file_contexts",
1274 binaries: ["bar"],
1275 native_shared_libs: ["foo"],
1276}
Chris Parsonscd209032023-09-19 01:12:48 +00001277` + simpleModule("filegroup", "myapex-file_contexts"),
Vinh Tran55225e32022-12-20 10:38:48 -05001278 ExpectedBazelTargets: []string{
1279 MakeBazelTarget("cc_binary", "bar", AttrNameToString{
1280 "local_includes": `["."]`,
1281 "deps": `[":foo_bp2build_cc_library_static"]`,
1282 "tags": `["apex_available=myapex"]`,
1283 }),
1284 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
1285 "local_includes": `["."]`,
1286 }),
1287 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1288 "local_includes": `["."]`,
1289 "stubs_symbol_file": `"foo.map.txt"`,
1290 "tags": `["apex_available=myapex"]`,
1291 }),
1292 MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001293 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -04001294 "soname": `"foo.so"`,
1295 "source_library_label": `"//:foo"`,
1296 "symbol_file": `"foo.map.txt"`,
Vinh Tran55225e32022-12-20 10:38:48 -05001297 "versions": `[
1298 "28",
1299 "29",
1300 "current",
1301 ]`,
1302 }),
1303 MakeBazelTarget("apex", "myapex", AttrNameToString{
1304 "file_contexts": `":myapex-file_contexts"`,
1305 "manifest": `"myapex_manifest.json"`,
1306 "binaries": `[":bar"]`,
1307 "native_shared_libs_32": `select({
1308 "//build/bazel/platforms/arch:arm": [":foo"],
1309 "//build/bazel/platforms/arch:x86": [":foo"],
1310 "//conditions:default": [],
1311 })`,
1312 "native_shared_libs_64": `select({
1313 "//build/bazel/platforms/arch:arm64": [":foo"],
1314 "//build/bazel/platforms/arch:x86_64": [":foo"],
1315 "//conditions:default": [],
1316 })`,
1317 }),
1318 },
1319 })
1320}
1321
Jingwen Chenbea58092022-09-29 16:56:02 +00001322func TestApexCertificateIsSrc(t *testing.T) {
1323 runApexTestCase(t, Bp2buildTestCase{
1324 Description: "apex - certificate is src",
1325 ModuleTypeUnderTest: "apex",
1326 ModuleTypeUnderTestFactory: apex.BundleFactory,
1327 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001328 StubbedBuildDefinitions: []string{"com.android.apogee-file_contexts"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001329 Blueprint: `
1330apex {
1331 name: "com.android.apogee",
1332 manifest: "apogee_manifest.json",
1333 file_contexts: ":com.android.apogee-file_contexts",
1334 certificate: "com.android.apogee.certificate",
1335}
Chris Parsonscd209032023-09-19 01:12:48 +00001336` + simpleModule("filegroup", "com.android.apogee-file_contexts"),
Jingwen Chenbea58092022-09-29 16:56:02 +00001337 ExpectedBazelTargets: []string{
1338 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1339 "certificate_name": `"com.android.apogee.certificate"`,
1340 "file_contexts": `":com.android.apogee-file_contexts"`,
1341 "manifest": `"apogee_manifest.json"`,
1342 }),
1343 }})
1344}
1345
1346func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1347 runOverrideApexTestCase(t, Bp2buildTestCase{
1348 Description: "override_apex - certificate is module",
1349 ModuleTypeUnderTest: "override_apex",
1350 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1351 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001352 StubbedBuildDefinitions: []string{"com.android.apogee.certificate", "com.android.apogee-file_contexts",
1353 "com.android.apogee", "com.google.android.apogee.certificate"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001354 Blueprint: `
1355android_app_certificate {
1356 name: "com.android.apogee.certificate",
1357 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001358}
1359
1360filegroup {
1361 name: "com.android.apogee-file_contexts",
1362 srcs: [
1363 "com.android.apogee-file_contexts",
1364 ],
Jingwen Chenbea58092022-09-29 16:56:02 +00001365}
1366
1367apex {
1368 name: "com.android.apogee",
1369 manifest: "apogee_manifest.json",
1370 file_contexts: ":com.android.apogee-file_contexts",
1371 certificate: ":com.android.apogee.certificate",
Jingwen Chenbea58092022-09-29 16:56:02 +00001372}
1373
1374android_app_certificate {
1375 name: "com.google.android.apogee.certificate",
1376 certificate: "com.google.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001377}
1378
1379override_apex {
1380 name: "com.google.android.apogee",
1381 base: ":com.android.apogee",
1382 certificate: ":com.google.android.apogee.certificate",
1383}
1384`,
1385 ExpectedBazelTargets: []string{
1386 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001387 "base_apex_name": `"com.android.apogee"`,
1388 "file_contexts": `":com.android.apogee-file_contexts"`,
1389 "certificate": `":com.google.android.apogee.certificate"`,
1390 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001391 }),
1392 }})
1393}
1394
1395func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1396 runOverrideApexTestCase(t, Bp2buildTestCase{
1397 Description: "override_apex - certificate is src",
1398 ModuleTypeUnderTest: "override_apex",
1399 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1400 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001401 StubbedBuildDefinitions: []string{"com.android.apogee.certificate", "com.android.apogee", "com.android.apogee-file_contexts"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001402 Blueprint: `
1403android_app_certificate {
1404 name: "com.android.apogee.certificate",
1405 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001406}
1407
1408filegroup {
1409 name: "com.android.apogee-file_contexts",
1410 srcs: [
1411 "com.android.apogee-file_contexts",
1412 ],
Jingwen Chenbea58092022-09-29 16:56:02 +00001413}
1414
1415apex {
1416 name: "com.android.apogee",
1417 manifest: "apogee_manifest.json",
1418 file_contexts: ":com.android.apogee-file_contexts",
1419 certificate: ":com.android.apogee.certificate",
1420 bazel_module: { bp2build_available: false },
1421}
1422
1423override_apex {
1424 name: "com.google.android.apogee",
1425 base: ":com.android.apogee",
1426 certificate: "com.google.android.apogee.certificate",
1427}
1428`,
1429 ExpectedBazelTargets: []string{
1430 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001431 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001432 "file_contexts": `":com.android.apogee-file_contexts"`,
1433 "certificate_name": `"com.google.android.apogee.certificate"`,
1434 "manifest": `"apogee_manifest.json"`,
1435 }),
1436 }})
1437}
Yu Liu4c212ce2022-10-14 12:20:20 -07001438
1439func TestApexTestBundleSimple(t *testing.T) {
1440 runApexTestCase(t, Bp2buildTestCase{
1441 Description: "apex_test - simple",
1442 ModuleTypeUnderTest: "apex_test",
1443 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
1444 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001445 StubbedBuildDefinitions: []string{"cc_test_1"},
Yu Liu4c212ce2022-10-14 12:20:20 -07001446 Blueprint: `
Chris Parsonscd209032023-09-19 01:12:48 +00001447cc_test { name: "cc_test_1"}
Yu Liu4c212ce2022-10-14 12:20:20 -07001448
1449apex_test {
1450 name: "test_com.android.apogee",
1451 file_contexts: "file_contexts_file",
1452 tests: ["cc_test_1"],
1453}
1454`,
1455 ExpectedBazelTargets: []string{
1456 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
Spandan Dasa43ae132023-05-08 18:33:16 +00001457 "file_contexts": `"file_contexts_file"`,
1458 "base_apex_name": `"com.android.apogee"`,
1459 "manifest": `"apex_manifest.json"`,
1460 "testonly": `True`,
1461 "tests": `[":cc_test_1"]`,
Yu Liu4c212ce2022-10-14 12:20:20 -07001462 }),
1463 }})
1464}
Cole Faust912bc882023-03-08 12:29:50 -08001465
1466func TestApexBundle_overridePlusProductVars(t *testing.T) {
1467 // Reproduction of b/271424349
1468 // Tests that overriding an apex that uses product variables correctly copies the product var
1469 // selects over to the override.
1470 runOverrideApexTestCase(t, Bp2buildTestCase{
1471 Description: "apex - overriding a module that uses product vars",
1472 ModuleTypeUnderTest: "override_apex",
1473 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001474 StubbedBuildDefinitions: []string{"foo-file_contexts"},
Cole Faust912bc882023-03-08 12:29:50 -08001475 Blueprint: `
1476soong_config_string_variable {
1477 name: "library_linking_strategy",
1478 values: [
1479 "prefer_static",
1480 ],
1481}
1482
1483soong_config_module_type {
1484 name: "library_linking_strategy_apex_defaults",
1485 module_type: "apex_defaults",
1486 config_namespace: "ANDROID",
1487 variables: ["library_linking_strategy"],
1488 properties: [
1489 "manifest",
1490 "min_sdk_version",
1491 ],
1492}
1493
1494library_linking_strategy_apex_defaults {
1495 name: "higher_min_sdk_when_prefer_static",
1496 soong_config_variables: {
1497 library_linking_strategy: {
1498 // Use the R min_sdk_version
1499 prefer_static: {},
1500 // Override the R min_sdk_version to min_sdk_version that supports dcla
1501 conditions_default: {
1502 min_sdk_version: "31",
1503 },
1504 },
1505 },
1506}
1507
1508filegroup {
1509 name: "foo-file_contexts",
1510 srcs: [
1511 "com.android.apogee-file_contexts",
1512 ],
Cole Faust912bc882023-03-08 12:29:50 -08001513}
1514
1515apex {
1516 name: "foo",
1517 defaults: ["higher_min_sdk_when_prefer_static"],
1518 min_sdk_version: "30",
1519 package_name: "pkg_name",
1520 file_contexts: ":foo-file_contexts",
1521}
1522override_apex {
1523 name: "override_foo",
1524 base: ":foo",
1525 package_name: "override_pkg_name",
1526}
1527`,
1528 ExpectedBazelTargets: []string{
1529 MakeBazelTarget("apex", "foo", AttrNameToString{
1530 "file_contexts": `":foo-file_contexts"`,
1531 "manifest": `"apex_manifest.json"`,
1532 "min_sdk_version": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001533 "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30",
Cole Faust912bc882023-03-08 12:29:50 -08001534 "//conditions:default": "31",
1535 })`,
1536 "package_name": `"pkg_name"`,
1537 }), MakeBazelTarget("apex", "override_foo", AttrNameToString{
1538 "base_apex_name": `"foo"`,
1539 "file_contexts": `":foo-file_contexts"`,
1540 "manifest": `"apex_manifest.json"`,
1541 "min_sdk_version": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001542 "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30",
Cole Faust912bc882023-03-08 12:29:50 -08001543 "//conditions:default": "31",
1544 })`,
1545 "package_name": `"override_pkg_name"`,
1546 }),
1547 }})
1548}
Jingwen Chena8623da2023-03-28 13:05:02 +00001549
1550func TestApexBundleSimple_customCannedFsConfig(t *testing.T) {
1551 runApexTestCase(t, Bp2buildTestCase{
1552 Description: "apex - custom canned_fs_config",
1553 ModuleTypeUnderTest: "apex",
1554 ModuleTypeUnderTestFactory: apex.BundleFactory,
1555 Filesystem: map[string]string{},
1556 Blueprint: `
1557apex {
1558 name: "com.android.apogee",
1559 canned_fs_config: "custom.canned_fs_config",
1560 file_contexts: "file_contexts_file",
1561}
1562`,
1563 ExpectedBazelTargets: []string{
1564 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1565 "canned_fs_config": `"custom.canned_fs_config"`,
1566 "file_contexts": `"file_contexts_file"`,
1567 "manifest": `"apex_manifest.json"`,
1568 }),
1569 }})
1570}