blob: 60de28cc511efbd4a2c4fbf5f697527701d933f1 [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 Parsons4c81ce02023-09-21 15:30:27 +0000821 StubbedBuildDefinitions: []string{"//a/b:com.android.apogee", "//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",
Wei Li40f98732022-05-20 22:08:11 -0700831}
832`,
833 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000834 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700835override_apex {
836 name: "com.google.android.apogee",
837 base: ":com.android.apogee",
838}
839`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000840 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000841 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000842 "base_apex_name": `"com.android.apogee"`,
843 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
844 "manifest": `"//a/b:apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700845 }),
846 }})
847}
848
849func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000850 runOverrideApexTestCase(t, Bp2buildTestCase{
851 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
852 ModuleTypeUnderTest: "override_apex",
853 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsons4c81ce02023-09-21 15:30:27 +0000854 StubbedBuildDefinitions: []string{"//a/b:com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000855 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700856 "system/sepolicy/apex/Android.bp": `
857filegroup {
858 name: "com.android.apogee-file_contexts",
859 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700860}`,
861 "a/b/Android.bp": `
862apex {
863 name: "com.android.apogee",
864 manifest: "apogee_manifest.json",
Wei Li40f98732022-05-20 22:08:11 -0700865}
866`,
867 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000868 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700869override_apex {
870 name: "com.google.android.apogee",
871 base: ":com.android.apogee",
872}
873`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000874 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000875 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000876 "base_apex_name": `"com.android.apogee"`,
877 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
878 "manifest": `"//a/b:apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700879 }),
880 }})
881}
882
883func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000884 runOverrideApexTestCase(t, Bp2buildTestCase{
885 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
886 ModuleTypeUnderTest: "override_apex",
887 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsons4c81ce02023-09-21 15:30:27 +0000888 StubbedBuildDefinitions: []string{"com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000889 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700890 "system/sepolicy/apex/Android.bp": `
891filegroup {
892 name: "com.android.apogee-file_contexts",
893 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700894}`,
895 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000896 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700897apex {
898 name: "com.android.apogee",
Wei Li40f98732022-05-20 22:08:11 -0700899}
900
901override_apex {
902 name: "com.google.android.apogee",
903 base: ":com.android.apogee",
904}
905`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000906 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000907 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000908 "base_apex_name": `"com.android.apogee"`,
909 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
910 "manifest": `"apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700911 }),
912 }})
913}
914
915func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000916 runOverrideApexTestCase(t, Bp2buildTestCase{
917 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
918 ModuleTypeUnderTest: "override_apex",
919 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsons4c81ce02023-09-21 15:30:27 +0000920 StubbedBuildDefinitions: []string{"com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000921 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700922 "system/sepolicy/apex/Android.bp": `
923filegroup {
924 name: "com.android.apogee-file_contexts",
925 srcs: [ "apogee-file_contexts", ],
Wei Li40f98732022-05-20 22:08:11 -0700926}`,
927 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000928 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700929apex {
930 name: "com.android.apogee",
931 manifest: "apogee_manifest.json",
Wei Li40f98732022-05-20 22:08:11 -0700932}
933
934override_apex {
935 name: "com.google.android.apogee",
936 base: ":com.android.apogee",
937}
938`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000939 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000940 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000941 "base_apex_name": `"com.android.apogee"`,
942 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
943 "manifest": `"apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700944 }),
945 }})
946}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000947
948func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000949 runOverrideApexTestCase(t, Bp2buildTestCase{
950 Description: "override_apex - override package name",
951 ModuleTypeUnderTest: "override_apex",
952 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsons4c81ce02023-09-21 15:30:27 +0000953 StubbedBuildDefinitions: []string{"com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000954 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000955 "system/sepolicy/apex/Android.bp": `
956filegroup {
957 name: "com.android.apogee-file_contexts",
958 srcs: [ "apogee-file_contexts", ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000959}`,
960 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000961 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000962apex {
963 name: "com.android.apogee",
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000964}
965
966override_apex {
967 name: "com.google.android.apogee",
968 base: ":com.android.apogee",
969 package_name: "com.google.android.apogee",
970}
971`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000972 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000973 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000974 "base_apex_name": `"com.android.apogee"`,
975 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
976 "manifest": `"apex_manifest.json"`,
977 "package_name": `"com.google.android.apogee"`,
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000978 }),
979 }})
980}
Jingwen Chendf165c92022-06-08 16:00:39 +0000981
982func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000983 runOverrideApexTestCase(t, Bp2buildTestCase{
984 Description: "override_apex - no override",
985 ModuleTypeUnderTest: "override_apex",
986 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +0000987 StubbedBuildDefinitions: []string{"prebuilt_file", "com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000988 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000989 "system/sepolicy/apex/Android.bp": `
990filegroup {
991 name: "com.android.apogee-file_contexts",
992 srcs: [ "apogee-file_contexts", ],
Jingwen Chendf165c92022-06-08 16:00:39 +0000993}`,
994 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000995 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000996prebuilt_etc {
997 name: "prebuilt_file",
Jingwen Chendf165c92022-06-08 16:00:39 +0000998}
999
1000apex {
1001 name: "com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001002 prebuilts: ["prebuilt_file"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001003}
1004
1005override_apex {
1006 name: "com.google.android.apogee",
1007 base: ":com.android.apogee",
1008}
1009`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001010 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001011 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001012 "base_apex_name": `"com.android.apogee"`,
1013 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1014 "manifest": `"apex_manifest.json"`,
1015 "prebuilts": `[":prebuilt_file"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001016 }),
1017 }})
1018}
1019
1020func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001021 runOverrideApexTestCase(t, Bp2buildTestCase{
1022 Description: "override_apex - ooverride",
1023 ModuleTypeUnderTest: "override_apex",
1024 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001025 StubbedBuildDefinitions: []string{"prebuilt_file", "prebuilt_file2", "com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001026 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001027 "system/sepolicy/apex/Android.bp": `
1028filegroup {
1029 name: "com.android.apogee-file_contexts",
1030 srcs: [ "apogee-file_contexts", ],
Jingwen Chendf165c92022-06-08 16:00:39 +00001031}`,
1032 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001033 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001034prebuilt_etc {
1035 name: "prebuilt_file",
Jingwen Chendf165c92022-06-08 16:00:39 +00001036}
1037
1038prebuilt_etc {
1039 name: "prebuilt_file2",
Jingwen Chendf165c92022-06-08 16:00:39 +00001040}
1041
1042apex {
1043 name: "com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001044 prebuilts: ["prebuilt_file"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001045}
1046
1047override_apex {
1048 name: "com.google.android.apogee",
1049 base: ":com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001050 prebuilts: ["prebuilt_file2"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001051}
1052`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001053 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001054 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001055 "base_apex_name": `"com.android.apogee"`,
1056 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1057 "manifest": `"apex_manifest.json"`,
1058 "prebuilts": `[":prebuilt_file2"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001059 }),
1060 }})
1061}
1062
1063func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001064 runOverrideApexTestCase(t, Bp2buildTestCase{
1065 Description: "override_apex - override with empty list",
1066 ModuleTypeUnderTest: "override_apex",
1067 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001068 StubbedBuildDefinitions: []string{"prebuilt_file", "com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001069 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +00001070 "system/sepolicy/apex/Android.bp": `
1071filegroup {
1072 name: "com.android.apogee-file_contexts",
1073 srcs: [ "apogee-file_contexts", ],
Jingwen Chendf165c92022-06-08 16:00:39 +00001074}`,
1075 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001076 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +00001077prebuilt_etc {
1078 name: "prebuilt_file",
Jingwen Chendf165c92022-06-08 16:00:39 +00001079}
1080
1081apex {
1082 name: "com.android.apogee",
Chris Parsonscd209032023-09-19 01:12:48 +00001083 prebuilts: ["prebuilt_file"]
Jingwen Chendf165c92022-06-08 16:00:39 +00001084}
1085
1086override_apex {
1087 name: "com.google.android.apogee",
1088 base: ":com.android.apogee",
1089 prebuilts: [],
1090}
1091`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001092 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001093 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001094 "base_apex_name": `"com.android.apogee"`,
1095 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1096 "manifest": `"apex_manifest.json"`,
1097 "prebuilts": `[]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001098 }),
1099 }})
1100}
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001101
1102func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001103 runOverrideApexTestCase(t, Bp2buildTestCase{
1104 Description: "override_apex - logging_parent - no override",
1105 ModuleTypeUnderTest: "override_apex",
1106 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsons4c81ce02023-09-21 15:30:27 +00001107 StubbedBuildDefinitions: []string{"com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001108 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001109 "system/sepolicy/apex/Android.bp": `
1110filegroup {
1111 name: "com.android.apogee-file_contexts",
1112 srcs: [ "apogee-file_contexts", ],
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001113}`,
1114 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001115 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001116apex {
1117 name: "com.android.apogee",
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001118 logging_parent: "foo.bar.baz",
1119}
1120
1121override_apex {
1122 name: "com.google.android.apogee",
1123 base: ":com.android.apogee",
1124}
1125`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001126 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001127 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001128 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001129 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1130 "manifest": `"apex_manifest.json"`,
1131 "logging_parent": `"foo.bar.baz"`,
1132 }),
1133 }})
1134}
1135
1136func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001137 runOverrideApexTestCase(t, Bp2buildTestCase{
1138 Description: "override_apex - logging_parent - override",
1139 ModuleTypeUnderTest: "override_apex",
1140 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsons4c81ce02023-09-21 15:30:27 +00001141 StubbedBuildDefinitions: []string{"com.android.apogee", "//system/sepolicy/apex:com.android.apogee-file_contexts"},
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001142 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001143 "system/sepolicy/apex/Android.bp": `
1144filegroup {
1145 name: "com.android.apogee-file_contexts",
1146 srcs: [ "apogee-file_contexts", ],
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001147}`,
1148 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001149 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001150apex {
1151 name: "com.android.apogee",
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001152 logging_parent: "foo.bar.baz",
1153}
1154
1155override_apex {
1156 name: "com.google.android.apogee",
1157 base: ":com.android.apogee",
1158 logging_parent: "foo.bar.baz.override",
1159}
1160`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001161 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001162 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001163 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001164 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1165 "manifest": `"apex_manifest.json"`,
1166 "logging_parent": `"foo.bar.baz.override"`,
1167 }),
1168 }})
1169}
Jingwen Chenbea58092022-09-29 16:56:02 +00001170
1171func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1172 runOverrideApexTestCase(t, Bp2buildTestCase{
1173 Description: "override_apex - don't set default certificate",
1174 ModuleTypeUnderTest: "override_apex",
1175 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1176 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001177 StubbedBuildDefinitions: []string{"com.android.apogee.certificate", "com.android.apogee-file_contexts", "com.android.apogee"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001178 Blueprint: `
1179android_app_certificate {
1180 name: "com.android.apogee.certificate",
1181 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001182}
1183
1184filegroup {
1185 name: "com.android.apogee-file_contexts",
1186 srcs: [
1187 "com.android.apogee-file_contexts",
1188 ],
Jingwen Chenbea58092022-09-29 16:56:02 +00001189}
1190
1191apex {
1192 name: "com.android.apogee",
1193 manifest: "apogee_manifest.json",
1194 file_contexts: ":com.android.apogee-file_contexts",
1195 certificate: ":com.android.apogee.certificate",
Jingwen Chenbea58092022-09-29 16:56:02 +00001196}
1197
1198override_apex {
1199 name: "com.google.android.apogee",
1200 base: ":com.android.apogee",
1201 // certificate is deliberately omitted, and not converted to bazel,
1202 // because the overridden apex shouldn't be using the base apex's cert.
1203}
1204`,
1205 ExpectedBazelTargets: []string{
1206 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001207 "base_apex_name": `"com.android.apogee"`,
1208 "file_contexts": `":com.android.apogee-file_contexts"`,
1209 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001210 }),
1211 }})
1212}
1213
1214func TestApexCertificateIsModule(t *testing.T) {
1215 runApexTestCase(t, Bp2buildTestCase{
1216 Description: "apex - certificate is module",
1217 ModuleTypeUnderTest: "apex",
1218 ModuleTypeUnderTestFactory: apex.BundleFactory,
1219 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001220 StubbedBuildDefinitions: []string{"com.android.apogee-file_contexts", "com.android.apogee.certificate"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001221 Blueprint: `
1222android_app_certificate {
1223 name: "com.android.apogee.certificate",
1224 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001225}
1226
1227apex {
1228 name: "com.android.apogee",
1229 manifest: "apogee_manifest.json",
1230 file_contexts: ":com.android.apogee-file_contexts",
1231 certificate: ":com.android.apogee.certificate",
1232}
Chris Parsonscd209032023-09-19 01:12:48 +00001233` + simpleModule("filegroup", "com.android.apogee-file_contexts"),
Jingwen Chenbea58092022-09-29 16:56:02 +00001234 ExpectedBazelTargets: []string{
1235 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1236 "certificate": `":com.android.apogee.certificate"`,
1237 "file_contexts": `":com.android.apogee-file_contexts"`,
1238 "manifest": `"apogee_manifest.json"`,
1239 }),
1240 }})
1241}
1242
Vinh Tran55225e32022-12-20 10:38:48 -05001243func TestApexWithStubLib(t *testing.T) {
1244 runApexTestCase(t, Bp2buildTestCase{
1245 Description: "apex - static variant of stub lib should not have apex_available tag",
1246 ModuleTypeUnderTest: "apex",
1247 ModuleTypeUnderTestFactory: apex.BundleFactory,
1248 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001249 StubbedBuildDefinitions: []string{"myapex-file_contexts"},
Vinh Tran55225e32022-12-20 10:38:48 -05001250 Blueprint: `
1251cc_library{
1252 name: "foo",
1253 stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] },
1254 apex_available: ["myapex"],
1255}
1256
1257cc_binary{
1258 name: "bar",
1259 static_libs: ["foo"],
1260 apex_available: ["myapex"],
1261}
1262
1263apex {
1264 name: "myapex",
1265 manifest: "myapex_manifest.json",
1266 file_contexts: ":myapex-file_contexts",
1267 binaries: ["bar"],
1268 native_shared_libs: ["foo"],
1269}
Chris Parsonscd209032023-09-19 01:12:48 +00001270` + simpleModule("filegroup", "myapex-file_contexts"),
Vinh Tran55225e32022-12-20 10:38:48 -05001271 ExpectedBazelTargets: []string{
1272 MakeBazelTarget("cc_binary", "bar", AttrNameToString{
1273 "local_includes": `["."]`,
1274 "deps": `[":foo_bp2build_cc_library_static"]`,
1275 "tags": `["apex_available=myapex"]`,
1276 }),
1277 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
1278 "local_includes": `["."]`,
1279 }),
1280 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
1281 "local_includes": `["."]`,
1282 "stubs_symbol_file": `"foo.map.txt"`,
1283 "tags": `["apex_available=myapex"]`,
1284 }),
1285 MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{
Spandan Das04f9f4c2023-09-13 23:59:05 +00001286 "api_surface": `"module-libapi"`,
Sam Delmerico5f906492023-03-15 18:06:18 -04001287 "soname": `"foo.so"`,
1288 "source_library_label": `"//:foo"`,
1289 "symbol_file": `"foo.map.txt"`,
Vinh Tran55225e32022-12-20 10:38:48 -05001290 "versions": `[
1291 "28",
1292 "29",
1293 "current",
1294 ]`,
1295 }),
1296 MakeBazelTarget("apex", "myapex", AttrNameToString{
1297 "file_contexts": `":myapex-file_contexts"`,
1298 "manifest": `"myapex_manifest.json"`,
1299 "binaries": `[":bar"]`,
1300 "native_shared_libs_32": `select({
1301 "//build/bazel/platforms/arch:arm": [":foo"],
1302 "//build/bazel/platforms/arch:x86": [":foo"],
1303 "//conditions:default": [],
1304 })`,
1305 "native_shared_libs_64": `select({
1306 "//build/bazel/platforms/arch:arm64": [":foo"],
1307 "//build/bazel/platforms/arch:x86_64": [":foo"],
1308 "//conditions:default": [],
1309 })`,
1310 }),
1311 },
1312 })
1313}
1314
Jingwen Chenbea58092022-09-29 16:56:02 +00001315func TestApexCertificateIsSrc(t *testing.T) {
1316 runApexTestCase(t, Bp2buildTestCase{
1317 Description: "apex - certificate is src",
1318 ModuleTypeUnderTest: "apex",
1319 ModuleTypeUnderTestFactory: apex.BundleFactory,
1320 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001321 StubbedBuildDefinitions: []string{"com.android.apogee-file_contexts"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001322 Blueprint: `
1323apex {
1324 name: "com.android.apogee",
1325 manifest: "apogee_manifest.json",
1326 file_contexts: ":com.android.apogee-file_contexts",
1327 certificate: "com.android.apogee.certificate",
1328}
Chris Parsonscd209032023-09-19 01:12:48 +00001329` + simpleModule("filegroup", "com.android.apogee-file_contexts"),
Jingwen Chenbea58092022-09-29 16:56:02 +00001330 ExpectedBazelTargets: []string{
1331 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1332 "certificate_name": `"com.android.apogee.certificate"`,
1333 "file_contexts": `":com.android.apogee-file_contexts"`,
1334 "manifest": `"apogee_manifest.json"`,
1335 }),
1336 }})
1337}
1338
1339func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1340 runOverrideApexTestCase(t, Bp2buildTestCase{
1341 Description: "override_apex - certificate is module",
1342 ModuleTypeUnderTest: "override_apex",
1343 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1344 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001345 StubbedBuildDefinitions: []string{"com.android.apogee.certificate", "com.android.apogee-file_contexts",
1346 "com.android.apogee", "com.google.android.apogee.certificate"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001347 Blueprint: `
1348android_app_certificate {
1349 name: "com.android.apogee.certificate",
1350 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001351}
1352
1353filegroup {
1354 name: "com.android.apogee-file_contexts",
1355 srcs: [
1356 "com.android.apogee-file_contexts",
1357 ],
Jingwen Chenbea58092022-09-29 16:56:02 +00001358}
1359
1360apex {
1361 name: "com.android.apogee",
1362 manifest: "apogee_manifest.json",
1363 file_contexts: ":com.android.apogee-file_contexts",
1364 certificate: ":com.android.apogee.certificate",
Jingwen Chenbea58092022-09-29 16:56:02 +00001365}
1366
1367android_app_certificate {
1368 name: "com.google.android.apogee.certificate",
1369 certificate: "com.google.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001370}
1371
1372override_apex {
1373 name: "com.google.android.apogee",
1374 base: ":com.android.apogee",
1375 certificate: ":com.google.android.apogee.certificate",
1376}
1377`,
1378 ExpectedBazelTargets: []string{
1379 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001380 "base_apex_name": `"com.android.apogee"`,
1381 "file_contexts": `":com.android.apogee-file_contexts"`,
1382 "certificate": `":com.google.android.apogee.certificate"`,
1383 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001384 }),
1385 }})
1386}
1387
1388func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1389 runOverrideApexTestCase(t, Bp2buildTestCase{
1390 Description: "override_apex - certificate is src",
1391 ModuleTypeUnderTest: "override_apex",
1392 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1393 Filesystem: map[string]string{},
Chris Parsons4c81ce02023-09-21 15:30:27 +00001394 StubbedBuildDefinitions: []string{"com.android.apogee", "com.android.apogee.certificate", "com.android.apogee", "com.android.apogee-file_contexts"},
Jingwen Chenbea58092022-09-29 16:56:02 +00001395 Blueprint: `
1396android_app_certificate {
1397 name: "com.android.apogee.certificate",
1398 certificate: "com.android.apogee",
Jingwen Chenbea58092022-09-29 16:56:02 +00001399}
1400
1401filegroup {
1402 name: "com.android.apogee-file_contexts",
1403 srcs: [
1404 "com.android.apogee-file_contexts",
1405 ],
Jingwen Chenbea58092022-09-29 16:56:02 +00001406}
1407
1408apex {
1409 name: "com.android.apogee",
1410 manifest: "apogee_manifest.json",
1411 file_contexts: ":com.android.apogee-file_contexts",
1412 certificate: ":com.android.apogee.certificate",
Jingwen Chenbea58092022-09-29 16:56:02 +00001413}
1414
1415override_apex {
1416 name: "com.google.android.apogee",
1417 base: ":com.android.apogee",
1418 certificate: "com.google.android.apogee.certificate",
1419}
1420`,
1421 ExpectedBazelTargets: []string{
1422 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001423 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001424 "file_contexts": `":com.android.apogee-file_contexts"`,
1425 "certificate_name": `"com.google.android.apogee.certificate"`,
1426 "manifest": `"apogee_manifest.json"`,
1427 }),
1428 }})
1429}
Yu Liu4c212ce2022-10-14 12:20:20 -07001430
1431func TestApexTestBundleSimple(t *testing.T) {
1432 runApexTestCase(t, Bp2buildTestCase{
1433 Description: "apex_test - simple",
1434 ModuleTypeUnderTest: "apex_test",
1435 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
1436 Filesystem: map[string]string{},
Chris Parsonscd209032023-09-19 01:12:48 +00001437 StubbedBuildDefinitions: []string{"cc_test_1"},
Yu Liu4c212ce2022-10-14 12:20:20 -07001438 Blueprint: `
Chris Parsonscd209032023-09-19 01:12:48 +00001439cc_test { name: "cc_test_1"}
Yu Liu4c212ce2022-10-14 12:20:20 -07001440
1441apex_test {
1442 name: "test_com.android.apogee",
1443 file_contexts: "file_contexts_file",
1444 tests: ["cc_test_1"],
1445}
1446`,
1447 ExpectedBazelTargets: []string{
1448 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
Spandan Dasa43ae132023-05-08 18:33:16 +00001449 "file_contexts": `"file_contexts_file"`,
1450 "base_apex_name": `"com.android.apogee"`,
1451 "manifest": `"apex_manifest.json"`,
1452 "testonly": `True`,
1453 "tests": `[":cc_test_1"]`,
Yu Liu4c212ce2022-10-14 12:20:20 -07001454 }),
1455 }})
1456}
Cole Faust912bc882023-03-08 12:29:50 -08001457
1458func TestApexBundle_overridePlusProductVars(t *testing.T) {
1459 // Reproduction of b/271424349
1460 // Tests that overriding an apex that uses product variables correctly copies the product var
1461 // selects over to the override.
1462 runOverrideApexTestCase(t, Bp2buildTestCase{
1463 Description: "apex - overriding a module that uses product vars",
1464 ModuleTypeUnderTest: "override_apex",
1465 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
Chris Parsonscd209032023-09-19 01:12:48 +00001466 StubbedBuildDefinitions: []string{"foo-file_contexts"},
Cole Faust912bc882023-03-08 12:29:50 -08001467 Blueprint: `
1468soong_config_string_variable {
1469 name: "library_linking_strategy",
1470 values: [
1471 "prefer_static",
1472 ],
1473}
1474
1475soong_config_module_type {
1476 name: "library_linking_strategy_apex_defaults",
1477 module_type: "apex_defaults",
1478 config_namespace: "ANDROID",
1479 variables: ["library_linking_strategy"],
1480 properties: [
1481 "manifest",
1482 "min_sdk_version",
1483 ],
1484}
1485
1486library_linking_strategy_apex_defaults {
1487 name: "higher_min_sdk_when_prefer_static",
1488 soong_config_variables: {
1489 library_linking_strategy: {
1490 // Use the R min_sdk_version
1491 prefer_static: {},
1492 // Override the R min_sdk_version to min_sdk_version that supports dcla
1493 conditions_default: {
1494 min_sdk_version: "31",
1495 },
1496 },
1497 },
1498}
1499
1500filegroup {
1501 name: "foo-file_contexts",
1502 srcs: [
1503 "com.android.apogee-file_contexts",
1504 ],
Cole Faust912bc882023-03-08 12:29:50 -08001505}
1506
1507apex {
1508 name: "foo",
1509 defaults: ["higher_min_sdk_when_prefer_static"],
1510 min_sdk_version: "30",
1511 package_name: "pkg_name",
1512 file_contexts: ":foo-file_contexts",
1513}
1514override_apex {
1515 name: "override_foo",
1516 base: ":foo",
1517 package_name: "override_pkg_name",
1518}
1519`,
1520 ExpectedBazelTargets: []string{
1521 MakeBazelTarget("apex", "foo", AttrNameToString{
1522 "file_contexts": `":foo-file_contexts"`,
1523 "manifest": `"apex_manifest.json"`,
1524 "min_sdk_version": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001525 "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30",
Cole Faust912bc882023-03-08 12:29:50 -08001526 "//conditions:default": "31",
1527 })`,
1528 "package_name": `"pkg_name"`,
1529 }), MakeBazelTarget("apex", "override_foo", AttrNameToString{
1530 "base_apex_name": `"foo"`,
1531 "file_contexts": `":foo-file_contexts"`,
1532 "manifest": `"apex_manifest.json"`,
1533 "min_sdk_version": `select({
Cole Faust87c0c332023-07-31 12:10:12 -07001534 "//build/bazel/product_config/config_settings:android__library_linking_strategy__prefer_static": "30",
Cole Faust912bc882023-03-08 12:29:50 -08001535 "//conditions:default": "31",
1536 })`,
1537 "package_name": `"override_pkg_name"`,
1538 }),
1539 }})
1540}
Jingwen Chena8623da2023-03-28 13:05:02 +00001541
1542func TestApexBundleSimple_customCannedFsConfig(t *testing.T) {
1543 runApexTestCase(t, Bp2buildTestCase{
1544 Description: "apex - custom canned_fs_config",
1545 ModuleTypeUnderTest: "apex",
1546 ModuleTypeUnderTestFactory: apex.BundleFactory,
1547 Filesystem: map[string]string{},
1548 Blueprint: `
1549apex {
1550 name: "com.android.apogee",
1551 canned_fs_config: "custom.canned_fs_config",
1552 file_contexts: "file_contexts_file",
1553}
1554`,
1555 ExpectedBazelTargets: []string{
1556 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1557 "canned_fs_config": `"custom.canned_fs_config"`,
1558 "file_contexts": `"file_contexts_file"`,
1559 "manifest": `"apex_manifest.json"`,
1560 }),
1561 }})
1562}