blob: 714b8488a0ad57bc3849e3466b3a2c889100e17f [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)
61 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
62 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
63 ctx.RegisterModuleType("apex", apex.BundleFactory)
Jingwen Chendf165c92022-06-08 16:00:39 +000064 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070065}
66
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040067func TestApexBundleSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000068 runApexTestCase(t, Bp2buildTestCase{
69 Description: "apex - example with all props, file_context is a module in same Android.bp",
70 ModuleTypeUnderTest: "apex",
71 ModuleTypeUnderTestFactory: apex.BundleFactory,
72 Filesystem: map[string]string{},
73 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040074apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000075 name: "com.android.apogee.key",
76 public_key: "com.android.apogee.avbpubkey",
77 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040078 bazel_module: { bp2build_available: false },
79}
80
81android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000082 name: "com.android.apogee.certificate",
83 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040084 bazel_module: { bp2build_available: false },
85}
86
87cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000088 name: "native_shared_lib_1",
89 bazel_module: { bp2build_available: false },
90}
91
92cc_library {
93 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040094 bazel_module: { bp2build_available: false },
95}
96
Jingwen Chen81c67d32022-06-08 16:08:25 +000097prebuilt_etc {
98 name: "prebuilt_1",
Jingwen Chenb07c9012021-12-08 10:05:45 +000099 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400100}
101
Jingwen Chen81c67d32022-06-08 16:08:25 +0000102prebuilt_etc {
103 name: "prebuilt_2",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000104 bazel_module: { bp2build_available: false },
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 ],
112 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400113}
114
Jingwen Chenb07c9012021-12-08 10:05:45 +0000115cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
116sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
117
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400118apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400119 name: "com.android.apogee",
120 manifest: "apogee_manifest.json",
121 androidManifest: "ApogeeAndroidManifest.xml",
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",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400143}
144`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000145 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000146 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500147 "android_manifest": `"ApogeeAndroidManifest.xml"`,
148 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000149 ":cc_binary_1",
150 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500151 ]`,
152 "certificate": `":com.android.apogee.certificate"`,
153 "file_contexts": `":com.android.apogee-file_contexts"`,
154 "installable": "False",
155 "key": `":com.android.apogee.key"`,
156 "manifest": `"apogee_manifest.json"`,
157 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400158 "native_shared_libs_32": `select({
159 "//build/bazel/platforms/arch:arm": [
160 ":native_shared_lib_1",
161 ":native_shared_lib_2",
162 ],
163 "//build/bazel/platforms/arch:x86": [
164 ":native_shared_lib_1",
165 ":native_shared_lib_2",
166 ],
167 "//conditions:default": [],
168 })`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800169 "native_shared_libs_64": `select({
170 "//build/bazel/platforms/arch:arm64": [
171 ":native_shared_lib_1",
172 ":native_shared_lib_2",
173 ],
174 "//build/bazel/platforms/arch:x86_64": [
175 ":native_shared_lib_1",
176 ":native_shared_lib_2",
177 ],
178 "//conditions:default": [],
179 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500180 "prebuilts": `[
Jingwen Chen81c67d32022-06-08 16:08:25 +0000181 ":prebuilt_1",
182 ":prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500183 ]`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000184 "updatable": "False",
185 "compressible": "False",
186 "package_name": `"com.android.apogee.test.package"`,
187 "logging_parent": `"logging.parent"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500188 }),
189 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400190}
191
Wei Li1c66fc72022-05-09 23:59:14 -0700192func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000193 runApexTestCase(t, Bp2buildTestCase{
194 Description: "apex - file contexts is a module in another Android.bp",
195 ModuleTypeUnderTest: "apex",
196 ModuleTypeUnderTestFactory: apex.BundleFactory,
197 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700198 "a/b/Android.bp": `
199filegroup {
200 name: "com.android.apogee-file_contexts",
201 srcs: [
202 "com.android.apogee-file_contexts",
203 ],
204 bazel_module: { bp2build_available: false },
205}
206`,
207 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000208 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700209apex {
210 name: "com.android.apogee",
211 file_contexts: ":com.android.apogee-file_contexts",
212}
213`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000214 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000215 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700216 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700217 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700218 }),
219 }})
220}
221
222func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000223 runApexTestCase(t, Bp2buildTestCase{
224 Description: "apex - file contexts is a file",
225 ModuleTypeUnderTest: "apex",
226 ModuleTypeUnderTestFactory: apex.BundleFactory,
227 Filesystem: map[string]string{},
228 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700229apex {
230 name: "com.android.apogee",
231 file_contexts: "file_contexts_file",
232}
233`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000234 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000235 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700236 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700237 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700238 }),
239 }})
240}
241
242func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000243 runApexTestCase(t, Bp2buildTestCase{
244 Description: "apex - file contexts is not specified",
245 ModuleTypeUnderTest: "apex",
246 ModuleTypeUnderTestFactory: apex.BundleFactory,
247 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700248 "system/sepolicy/apex/Android.bp": `
249filegroup {
250 name: "com.android.apogee-file_contexts",
251 srcs: [
252 "com.android.apogee-file_contexts",
253 ],
254 bazel_module: { bp2build_available: false },
255}
256`,
257 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000258 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700259apex {
260 name: "com.android.apogee",
261}
262`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000263 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000264 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700265 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700266 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700267 }),
268 }})
269}
270
Yu Liu4ae55d12022-01-05 17:17:23 -0800271func TestApexBundleCompileMultilibBoth(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000272 runApexTestCase(t, Bp2buildTestCase{
273 Description: "apex - example with compile_multilib=both",
274 ModuleTypeUnderTest: "apex",
275 ModuleTypeUnderTestFactory: apex.BundleFactory,
276 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700277 "system/sepolicy/apex/Android.bp": `
278filegroup {
279 name: "com.android.apogee-file_contexts",
280 srcs: [ "apogee-file_contexts", ],
281 bazel_module: { bp2build_available: false },
282}
283`,
284 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400285 Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000286 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000287 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800288 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400289 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000290 ":native_shared_lib_for_both",
291 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800292 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000293 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
294 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800295 "//conditions:default": [],
296 })`,
297 "native_shared_libs_64": `select({
298 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400299 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000300 ":native_shared_lib_for_both",
301 ":native_shared_lib_for_lib64",
302 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800303 ],
304 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400305 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000306 ":native_shared_lib_for_both",
307 ":native_shared_lib_for_lib64",
308 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800309 ],
310 "//conditions:default": [],
311 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700312 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700313 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800314 }),
315 }})
316}
317
Vinh Tran8f5310f2022-10-07 18:16:47 -0400318func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
319 expectedBazelTargets := []string{
320 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
321 "native_shared_libs_32": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800322 "//build/bazel/platforms/arch:arm": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400323 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000324 ":native_shared_lib_for_both",
325 ":native_shared_lib_for_lib32",
326 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800327 ],
328 "//build/bazel/platforms/arch:x86": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400329 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000330 ":native_shared_lib_for_both",
331 ":native_shared_lib_for_lib32",
332 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800333 ],
334 "//conditions:default": [],
335 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400336 "native_shared_libs_64": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800337 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400338 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000339 ":native_shared_lib_for_both",
340 ":native_shared_lib_for_lib64",
341 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800342 ],
343 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400344 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000345 ":native_shared_lib_for_both",
346 ":native_shared_lib_for_lib64",
347 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800348 ],
349 "//conditions:default": [],
350 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400351 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
352 "manifest": `"apex_manifest.json"`,
353 }),
354 }
355
356 // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
357 // should result to the same bp2build output
358 compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
359 for _, compileMultiLibProp := range compileMultiLibPropValues {
360 descriptionSuffix := compileMultiLibProp
361 if descriptionSuffix == "" {
362 descriptionSuffix = "compile_multilib unset"
363 }
364 runApexTestCase(t, Bp2buildTestCase{
365 Description: "apex - example with " + compileMultiLibProp,
366 ModuleTypeUnderTest: "apex",
367 ModuleTypeUnderTestFactory: apex.BundleFactory,
368 Filesystem: map[string]string{
369 "system/sepolicy/apex/Android.bp": `
370 filegroup {
371 name: "com.android.apogee-file_contexts",
372 srcs: [ "apogee-file_contexts", ],
373 bazel_module: { bp2build_available: false },
374 }
375 `,
376 },
377 Blueprint: createMultilibBlueprint(compileMultiLibProp),
378 ExpectedBazelTargets: expectedBazelTargets,
379 })
380 }
Yu Liu4ae55d12022-01-05 17:17:23 -0800381}
382
383func TestApexBundleCompileMultilib32(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000384 runApexTestCase(t, Bp2buildTestCase{
385 Description: "apex - example with compile_multilib=32",
386 ModuleTypeUnderTest: "apex",
387 ModuleTypeUnderTestFactory: apex.BundleFactory,
388 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700389 "system/sepolicy/apex/Android.bp": `
390filegroup {
391 name: "com.android.apogee-file_contexts",
392 srcs: [ "apogee-file_contexts", ],
393 bazel_module: { bp2build_available: false },
394}
395`,
396 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400397 Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000398 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000399 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800400 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400401 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000402 ":native_shared_lib_for_both",
403 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800404 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000405 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
406 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800407 "//conditions:default": [],
408 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700409 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700410 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800411 }),
412 }})
413}
414
415func TestApexBundleCompileMultilib64(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000416 runApexTestCase(t, Bp2buildTestCase{
417 Description: "apex - example with compile_multilib=64",
418 ModuleTypeUnderTest: "apex",
419 ModuleTypeUnderTestFactory: apex.BundleFactory,
420 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700421 "system/sepolicy/apex/Android.bp": `
422filegroup {
423 name: "com.android.apogee-file_contexts",
424 srcs: [ "apogee-file_contexts", ],
425 bazel_module: { bp2build_available: false },
426}
427`,
428 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400429 Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000430 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000431 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800432 "native_shared_libs_64": `select({
433 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400434 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000435 ":native_shared_lib_for_both",
436 ":native_shared_lib_for_lib64",
437 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800438 ],
439 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400440 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000441 ":native_shared_lib_for_both",
442 ":native_shared_lib_for_lib64",
443 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800444 ],
445 "//conditions:default": [],
446 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700447 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700448 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800449 }),
450 }})
451}
452
Jingwen Chen34feb142022-10-06 13:02:30 +0000453func createMultilibBlueprint(compile_multilib string) string {
Vinh Tran8f5310f2022-10-07 18:16:47 -0400454 return fmt.Sprintf(`
Jingwen Chen34feb142022-10-06 13:02:30 +0000455cc_library {
456 name: "native_shared_lib_for_both",
457 bazel_module: { bp2build_available: false },
458}
459
460cc_library {
461 name: "native_shared_lib_for_first",
462 bazel_module: { bp2build_available: false },
463}
464
465cc_library {
466 name: "native_shared_lib_for_lib32",
467 bazel_module: { bp2build_available: false },
468}
469
470cc_library {
471 name: "native_shared_lib_for_lib64",
472 bazel_module: { bp2build_available: false },
473}
474
Vinh Tran8f5310f2022-10-07 18:16:47 -0400475cc_library {
476 name: "unnested_native_shared_lib",
477 bazel_module: { bp2build_available: false },
478}
479
Jingwen Chen34feb142022-10-06 13:02:30 +0000480apex {
481 name: "com.android.apogee",
Vinh Tran8f5310f2022-10-07 18:16:47 -0400482 %s
483 native_shared_libs: ["unnested_native_shared_lib"],
Jingwen Chen34feb142022-10-06 13:02:30 +0000484 multilib: {
485 both: {
486 native_shared_libs: [
487 "native_shared_lib_for_both",
488 ],
489 },
490 first: {
491 native_shared_libs: [
492 "native_shared_lib_for_first",
493 ],
494 },
495 lib32: {
496 native_shared_libs: [
497 "native_shared_lib_for_lib32",
498 ],
499 },
500 lib64: {
501 native_shared_libs: [
502 "native_shared_lib_for_lib64",
503 ],
504 },
505 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400506}`, compile_multilib)
Jingwen Chen34feb142022-10-06 13:02:30 +0000507}
508
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400509func TestApexBundleDefaultPropertyValues(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000510 runApexTestCase(t, Bp2buildTestCase{
511 Description: "apex - default property values",
512 ModuleTypeUnderTest: "apex",
513 ModuleTypeUnderTestFactory: apex.BundleFactory,
514 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700515 "system/sepolicy/apex/Android.bp": `
516filegroup {
517 name: "com.android.apogee-file_contexts",
518 srcs: [ "apogee-file_contexts", ],
519 bazel_module: { bp2build_available: false },
520}
521`,
522 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000523 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400524apex {
525 name: "com.android.apogee",
526 manifest: "apogee_manifest.json",
527}
528`,
Alixe06d75b2022-08-31 18:28:19 +0000529 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700530 "manifest": `"apogee_manifest.json"`,
531 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500532 }),
533 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400534}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000535
536func TestApexBundleHasBazelModuleProps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000537 runApexTestCase(t, Bp2buildTestCase{
538 Description: "apex - has bazel module props",
539 ModuleTypeUnderTest: "apex",
540 ModuleTypeUnderTestFactory: apex.BundleFactory,
541 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700542 "system/sepolicy/apex/Android.bp": `
543filegroup {
544 name: "apogee-file_contexts",
545 srcs: [ "apogee-file_contexts", ],
546 bazel_module: { bp2build_available: false },
547}
548`,
549 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000550 Blueprint: `
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000551apex {
552 name: "apogee",
553 manifest: "manifest.json",
554 bazel_module: { bp2build_available: true },
555}
556`,
Alixe06d75b2022-08-31 18:28:19 +0000557 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700558 "manifest": `"manifest.json"`,
559 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500560 }),
561 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000562}
Yu Liu4ae55d12022-01-05 17:17:23 -0800563
Wei Li1c66fc72022-05-09 23:59:14 -0700564func TestBp2BuildOverrideApex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000565 runOverrideApexTestCase(t, Bp2buildTestCase{
566 Description: "override_apex",
567 ModuleTypeUnderTest: "override_apex",
568 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
569 Filesystem: map[string]string{},
570 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700571apex_key {
572 name: "com.android.apogee.key",
573 public_key: "com.android.apogee.avbpubkey",
574 private_key: "com.android.apogee.pem",
575 bazel_module: { bp2build_available: false },
576}
577
578android_app_certificate {
579 name: "com.android.apogee.certificate",
580 certificate: "com.android.apogee",
581 bazel_module: { bp2build_available: false },
582}
583
584cc_library {
585 name: "native_shared_lib_1",
586 bazel_module: { bp2build_available: false },
587}
588
589cc_library {
590 name: "native_shared_lib_2",
591 bazel_module: { bp2build_available: false },
592}
593
Jingwen Chen81c67d32022-06-08 16:08:25 +0000594prebuilt_etc {
595 name: "prebuilt_1",
Wei Li1c66fc72022-05-09 23:59:14 -0700596 bazel_module: { bp2build_available: false },
597}
598
Jingwen Chen81c67d32022-06-08 16:08:25 +0000599prebuilt_etc {
600 name: "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700601 bazel_module: { bp2build_available: false },
602}
603
604filegroup {
605 name: "com.android.apogee-file_contexts",
606 srcs: [
607 "com.android.apogee-file_contexts",
608 ],
609 bazel_module: { bp2build_available: false },
610}
611
612cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
613sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
614
615apex {
616 name: "com.android.apogee",
617 manifest: "apogee_manifest.json",
618 androidManifest: "ApogeeAndroidManifest.xml",
619 file_contexts: ":com.android.apogee-file_contexts",
620 min_sdk_version: "29",
621 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000622 certificate: ":com.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700623 updatable: false,
624 installable: false,
625 compressible: false,
626 native_shared_libs: [
627 "native_shared_lib_1",
628 "native_shared_lib_2",
629 ],
630 binaries: [
631 "cc_binary_1",
632 "sh_binary_2",
633 ],
634 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000635 "prebuilt_1",
636 "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700637 ],
638 bazel_module: { bp2build_available: false },
639}
640
641apex_key {
642 name: "com.google.android.apogee.key",
643 public_key: "com.google.android.apogee.avbpubkey",
644 private_key: "com.google.android.apogee.pem",
645 bazel_module: { bp2build_available: false },
646}
647
648android_app_certificate {
649 name: "com.google.android.apogee.certificate",
650 certificate: "com.google.android.apogee",
651 bazel_module: { bp2build_available: false },
652}
653
654override_apex {
655 name: "com.google.android.apogee",
656 base: ":com.android.apogee",
657 key: "com.google.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000658 certificate: ":com.google.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700659 prebuilts: [],
660 compressible: true,
661}
662`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000663 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000664 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700665 "android_manifest": `"ApogeeAndroidManifest.xml"`,
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000666 "base_apex_name": `"com.android.apogee"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700667 "binaries": `[
668 ":cc_binary_1",
669 ":sh_binary_2",
670 ]`,
671 "certificate": `":com.google.android.apogee.certificate"`,
672 "file_contexts": `":com.android.apogee-file_contexts"`,
673 "installable": "False",
674 "key": `":com.google.android.apogee.key"`,
675 "manifest": `"apogee_manifest.json"`,
676 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400677 "native_shared_libs_32": `select({
678 "//build/bazel/platforms/arch:arm": [
679 ":native_shared_lib_1",
680 ":native_shared_lib_2",
681 ],
682 "//build/bazel/platforms/arch:x86": [
683 ":native_shared_lib_1",
684 ":native_shared_lib_2",
685 ],
686 "//conditions:default": [],
687 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700688 "native_shared_libs_64": `select({
689 "//build/bazel/platforms/arch:arm64": [
690 ":native_shared_lib_1",
691 ":native_shared_lib_2",
692 ],
693 "//build/bazel/platforms/arch:x86_64": [
694 ":native_shared_lib_1",
695 ":native_shared_lib_2",
696 ],
697 "//conditions:default": [],
698 })`,
699 "prebuilts": `[]`,
700 "updatable": "False",
701 "compressible": "True",
702 }),
703 }})
704}
Wei Li40f98732022-05-20 22:08:11 -0700705
706func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000707 runOverrideApexTestCase(t, Bp2buildTestCase{
708 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
709 ModuleTypeUnderTest: "override_apex",
710 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
711 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700712 "system/sepolicy/apex/Android.bp": `
713filegroup {
714 name: "com.android.apogee-file_contexts",
715 srcs: [ "apogee-file_contexts", ],
716 bazel_module: { bp2build_available: false },
717}`,
718 "a/b/Android.bp": `
719apex {
720 name: "com.android.apogee",
721 bazel_module: { bp2build_available: false },
722}
723`,
724 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000725 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700726override_apex {
727 name: "com.google.android.apogee",
728 base: ":com.android.apogee",
729}
730`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000731 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000732 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000733 "base_apex_name": `"com.android.apogee"`,
734 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
735 "manifest": `"//a/b:apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700736 }),
737 }})
738}
739
740func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000741 runOverrideApexTestCase(t, Bp2buildTestCase{
742 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
743 ModuleTypeUnderTest: "override_apex",
744 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
745 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700746 "system/sepolicy/apex/Android.bp": `
747filegroup {
748 name: "com.android.apogee-file_contexts",
749 srcs: [ "apogee-file_contexts", ],
750 bazel_module: { bp2build_available: false },
751}`,
752 "a/b/Android.bp": `
753apex {
754 name: "com.android.apogee",
755 manifest: "apogee_manifest.json",
756 bazel_module: { bp2build_available: false },
757}
758`,
759 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000760 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700761override_apex {
762 name: "com.google.android.apogee",
763 base: ":com.android.apogee",
764}
765`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000766 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000767 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000768 "base_apex_name": `"com.android.apogee"`,
769 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
770 "manifest": `"//a/b:apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700771 }),
772 }})
773}
774
775func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000776 runOverrideApexTestCase(t, Bp2buildTestCase{
777 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
778 ModuleTypeUnderTest: "override_apex",
779 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
780 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700781 "system/sepolicy/apex/Android.bp": `
782filegroup {
783 name: "com.android.apogee-file_contexts",
784 srcs: [ "apogee-file_contexts", ],
785 bazel_module: { bp2build_available: false },
786}`,
787 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000788 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700789apex {
790 name: "com.android.apogee",
791 bazel_module: { bp2build_available: false },
792}
793
794override_apex {
795 name: "com.google.android.apogee",
796 base: ":com.android.apogee",
797}
798`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000799 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000800 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000801 "base_apex_name": `"com.android.apogee"`,
802 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
803 "manifest": `"apex_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700804 }),
805 }})
806}
807
808func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000809 runOverrideApexTestCase(t, Bp2buildTestCase{
810 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
811 ModuleTypeUnderTest: "override_apex",
812 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
813 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700814 "system/sepolicy/apex/Android.bp": `
815filegroup {
816 name: "com.android.apogee-file_contexts",
817 srcs: [ "apogee-file_contexts", ],
818 bazel_module: { bp2build_available: false },
819}`,
820 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000821 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700822apex {
823 name: "com.android.apogee",
824 manifest: "apogee_manifest.json",
825 bazel_module: { bp2build_available: false },
826}
827
828override_apex {
829 name: "com.google.android.apogee",
830 base: ":com.android.apogee",
831}
832`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000833 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000834 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000835 "base_apex_name": `"com.android.apogee"`,
836 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
837 "manifest": `"apogee_manifest.json"`,
Wei Li40f98732022-05-20 22:08:11 -0700838 }),
839 }})
840}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000841
842func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000843 runOverrideApexTestCase(t, Bp2buildTestCase{
844 Description: "override_apex - override package name",
845 ModuleTypeUnderTest: "override_apex",
846 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
847 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000848 "system/sepolicy/apex/Android.bp": `
849filegroup {
850 name: "com.android.apogee-file_contexts",
851 srcs: [ "apogee-file_contexts", ],
852 bazel_module: { bp2build_available: false },
853}`,
854 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000855 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000856apex {
857 name: "com.android.apogee",
858 bazel_module: { bp2build_available: false },
859}
860
861override_apex {
862 name: "com.google.android.apogee",
863 base: ":com.android.apogee",
864 package_name: "com.google.android.apogee",
865}
866`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000867 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000868 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000869 "base_apex_name": `"com.android.apogee"`,
870 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
871 "manifest": `"apex_manifest.json"`,
872 "package_name": `"com.google.android.apogee"`,
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000873 }),
874 }})
875}
Jingwen Chendf165c92022-06-08 16:00:39 +0000876
877func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000878 runOverrideApexTestCase(t, Bp2buildTestCase{
879 Description: "override_apex - no override",
880 ModuleTypeUnderTest: "override_apex",
881 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
882 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000883 "system/sepolicy/apex/Android.bp": `
884filegroup {
885 name: "com.android.apogee-file_contexts",
886 srcs: [ "apogee-file_contexts", ],
887 bazel_module: { bp2build_available: false },
888}`,
889 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000890 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000891prebuilt_etc {
892 name: "prebuilt_file",
893 bazel_module: { bp2build_available: false },
894}
895
896apex {
897 name: "com.android.apogee",
898 bazel_module: { bp2build_available: false },
899 prebuilts: ["prebuilt_file"]
900}
901
902override_apex {
903 name: "com.google.android.apogee",
904 base: ":com.android.apogee",
905}
906`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000907 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000908 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000909 "base_apex_name": `"com.android.apogee"`,
910 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
911 "manifest": `"apex_manifest.json"`,
912 "prebuilts": `[":prebuilt_file"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +0000913 }),
914 }})
915}
916
917func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000918 runOverrideApexTestCase(t, Bp2buildTestCase{
919 Description: "override_apex - ooverride",
920 ModuleTypeUnderTest: "override_apex",
921 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
922 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000923 "system/sepolicy/apex/Android.bp": `
924filegroup {
925 name: "com.android.apogee-file_contexts",
926 srcs: [ "apogee-file_contexts", ],
927 bazel_module: { bp2build_available: false },
928}`,
929 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000930 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000931prebuilt_etc {
932 name: "prebuilt_file",
933 bazel_module: { bp2build_available: false },
934}
935
936prebuilt_etc {
937 name: "prebuilt_file2",
938 bazel_module: { bp2build_available: false },
939}
940
941apex {
942 name: "com.android.apogee",
943 bazel_module: { bp2build_available: false },
944 prebuilts: ["prebuilt_file"]
945}
946
947override_apex {
948 name: "com.google.android.apogee",
949 base: ":com.android.apogee",
950 prebuilts: ["prebuilt_file2"]
951}
952`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000953 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000954 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000955 "base_apex_name": `"com.android.apogee"`,
956 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
957 "manifest": `"apex_manifest.json"`,
958 "prebuilts": `[":prebuilt_file2"]`,
Jingwen Chendf165c92022-06-08 16:00:39 +0000959 }),
960 }})
961}
962
963func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000964 runOverrideApexTestCase(t, Bp2buildTestCase{
965 Description: "override_apex - override with empty list",
966 ModuleTypeUnderTest: "override_apex",
967 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
968 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000969 "system/sepolicy/apex/Android.bp": `
970filegroup {
971 name: "com.android.apogee-file_contexts",
972 srcs: [ "apogee-file_contexts", ],
973 bazel_module: { bp2build_available: false },
974}`,
975 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000976 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000977prebuilt_etc {
978 name: "prebuilt_file",
979 bazel_module: { bp2build_available: false },
980}
981
982apex {
983 name: "com.android.apogee",
984 bazel_module: { bp2build_available: false },
985 prebuilts: ["prebuilt_file"]
986}
987
988override_apex {
989 name: "com.google.android.apogee",
990 base: ":com.android.apogee",
991 prebuilts: [],
992}
993`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000994 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000995 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000996 "base_apex_name": `"com.android.apogee"`,
997 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
998 "manifest": `"apex_manifest.json"`,
999 "prebuilts": `[]`,
Jingwen Chendf165c92022-06-08 16:00:39 +00001000 }),
1001 }})
1002}
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001003
1004func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001005 runOverrideApexTestCase(t, Bp2buildTestCase{
1006 Description: "override_apex - logging_parent - no override",
1007 ModuleTypeUnderTest: "override_apex",
1008 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1009 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001010 "system/sepolicy/apex/Android.bp": `
1011filegroup {
1012 name: "com.android.apogee-file_contexts",
1013 srcs: [ "apogee-file_contexts", ],
1014 bazel_module: { bp2build_available: false },
1015}`,
1016 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001017 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001018apex {
1019 name: "com.android.apogee",
1020 bazel_module: { bp2build_available: false },
1021 logging_parent: "foo.bar.baz",
1022}
1023
1024override_apex {
1025 name: "com.google.android.apogee",
1026 base: ":com.android.apogee",
1027}
1028`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001029 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001030 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001031 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001032 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1033 "manifest": `"apex_manifest.json"`,
1034 "logging_parent": `"foo.bar.baz"`,
1035 }),
1036 }})
1037}
1038
1039func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001040 runOverrideApexTestCase(t, Bp2buildTestCase{
1041 Description: "override_apex - logging_parent - override",
1042 ModuleTypeUnderTest: "override_apex",
1043 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1044 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001045 "system/sepolicy/apex/Android.bp": `
1046filegroup {
1047 name: "com.android.apogee-file_contexts",
1048 srcs: [ "apogee-file_contexts", ],
1049 bazel_module: { bp2build_available: false },
1050}`,
1051 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001052 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001053apex {
1054 name: "com.android.apogee",
1055 bazel_module: { bp2build_available: false },
1056 logging_parent: "foo.bar.baz",
1057}
1058
1059override_apex {
1060 name: "com.google.android.apogee",
1061 base: ":com.android.apogee",
1062 logging_parent: "foo.bar.baz.override",
1063}
1064`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001065 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001066 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001067 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001068 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1069 "manifest": `"apex_manifest.json"`,
1070 "logging_parent": `"foo.bar.baz.override"`,
1071 }),
1072 }})
1073}
Jingwen Chenbea58092022-09-29 16:56:02 +00001074
1075func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1076 runOverrideApexTestCase(t, Bp2buildTestCase{
1077 Description: "override_apex - don't set default certificate",
1078 ModuleTypeUnderTest: "override_apex",
1079 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1080 Filesystem: map[string]string{},
1081 Blueprint: `
1082android_app_certificate {
1083 name: "com.android.apogee.certificate",
1084 certificate: "com.android.apogee",
1085 bazel_module: { bp2build_available: false },
1086}
1087
1088filegroup {
1089 name: "com.android.apogee-file_contexts",
1090 srcs: [
1091 "com.android.apogee-file_contexts",
1092 ],
1093 bazel_module: { bp2build_available: false },
1094}
1095
1096apex {
1097 name: "com.android.apogee",
1098 manifest: "apogee_manifest.json",
1099 file_contexts: ":com.android.apogee-file_contexts",
1100 certificate: ":com.android.apogee.certificate",
1101 bazel_module: { bp2build_available: false },
1102}
1103
1104override_apex {
1105 name: "com.google.android.apogee",
1106 base: ":com.android.apogee",
1107 // certificate is deliberately omitted, and not converted to bazel,
1108 // because the overridden apex shouldn't be using the base apex's cert.
1109}
1110`,
1111 ExpectedBazelTargets: []string{
1112 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001113 "base_apex_name": `"com.android.apogee"`,
1114 "file_contexts": `":com.android.apogee-file_contexts"`,
1115 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001116 }),
1117 }})
1118}
1119
1120func TestApexCertificateIsModule(t *testing.T) {
1121 runApexTestCase(t, Bp2buildTestCase{
1122 Description: "apex - certificate is module",
1123 ModuleTypeUnderTest: "apex",
1124 ModuleTypeUnderTestFactory: apex.BundleFactory,
1125 Filesystem: map[string]string{},
1126 Blueprint: `
1127android_app_certificate {
1128 name: "com.android.apogee.certificate",
1129 certificate: "com.android.apogee",
1130 bazel_module: { bp2build_available: false },
1131}
1132
1133apex {
1134 name: "com.android.apogee",
1135 manifest: "apogee_manifest.json",
1136 file_contexts: ":com.android.apogee-file_contexts",
1137 certificate: ":com.android.apogee.certificate",
1138}
1139` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1140 ExpectedBazelTargets: []string{
1141 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1142 "certificate": `":com.android.apogee.certificate"`,
1143 "file_contexts": `":com.android.apogee-file_contexts"`,
1144 "manifest": `"apogee_manifest.json"`,
1145 }),
1146 }})
1147}
1148
1149func TestApexCertificateIsSrc(t *testing.T) {
1150 runApexTestCase(t, Bp2buildTestCase{
1151 Description: "apex - certificate is src",
1152 ModuleTypeUnderTest: "apex",
1153 ModuleTypeUnderTestFactory: apex.BundleFactory,
1154 Filesystem: map[string]string{},
1155 Blueprint: `
1156apex {
1157 name: "com.android.apogee",
1158 manifest: "apogee_manifest.json",
1159 file_contexts: ":com.android.apogee-file_contexts",
1160 certificate: "com.android.apogee.certificate",
1161}
1162` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1163 ExpectedBazelTargets: []string{
1164 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1165 "certificate_name": `"com.android.apogee.certificate"`,
1166 "file_contexts": `":com.android.apogee-file_contexts"`,
1167 "manifest": `"apogee_manifest.json"`,
1168 }),
1169 }})
1170}
1171
1172func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1173 runOverrideApexTestCase(t, Bp2buildTestCase{
1174 Description: "override_apex - certificate is module",
1175 ModuleTypeUnderTest: "override_apex",
1176 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1177 Filesystem: map[string]string{},
1178 Blueprint: `
1179android_app_certificate {
1180 name: "com.android.apogee.certificate",
1181 certificate: "com.android.apogee",
1182 bazel_module: { bp2build_available: false },
1183}
1184
1185filegroup {
1186 name: "com.android.apogee-file_contexts",
1187 srcs: [
1188 "com.android.apogee-file_contexts",
1189 ],
1190 bazel_module: { bp2build_available: false },
1191}
1192
1193apex {
1194 name: "com.android.apogee",
1195 manifest: "apogee_manifest.json",
1196 file_contexts: ":com.android.apogee-file_contexts",
1197 certificate: ":com.android.apogee.certificate",
1198 bazel_module: { bp2build_available: false },
1199}
1200
1201android_app_certificate {
1202 name: "com.google.android.apogee.certificate",
1203 certificate: "com.google.android.apogee",
1204 bazel_module: { bp2build_available: false },
1205}
1206
1207override_apex {
1208 name: "com.google.android.apogee",
1209 base: ":com.android.apogee",
1210 certificate: ":com.google.android.apogee.certificate",
1211}
1212`,
1213 ExpectedBazelTargets: []string{
1214 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001215 "base_apex_name": `"com.android.apogee"`,
1216 "file_contexts": `":com.android.apogee-file_contexts"`,
1217 "certificate": `":com.google.android.apogee.certificate"`,
1218 "manifest": `"apogee_manifest.json"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001219 }),
1220 }})
1221}
1222
1223func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1224 runOverrideApexTestCase(t, Bp2buildTestCase{
1225 Description: "override_apex - certificate is src",
1226 ModuleTypeUnderTest: "override_apex",
1227 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1228 Filesystem: map[string]string{},
1229 Blueprint: `
1230android_app_certificate {
1231 name: "com.android.apogee.certificate",
1232 certificate: "com.android.apogee",
1233 bazel_module: { bp2build_available: false },
1234}
1235
1236filegroup {
1237 name: "com.android.apogee-file_contexts",
1238 srcs: [
1239 "com.android.apogee-file_contexts",
1240 ],
1241 bazel_module: { bp2build_available: false },
1242}
1243
1244apex {
1245 name: "com.android.apogee",
1246 manifest: "apogee_manifest.json",
1247 file_contexts: ":com.android.apogee-file_contexts",
1248 certificate: ":com.android.apogee.certificate",
1249 bazel_module: { bp2build_available: false },
1250}
1251
1252override_apex {
1253 name: "com.google.android.apogee",
1254 base: ":com.android.apogee",
1255 certificate: "com.google.android.apogee.certificate",
1256}
1257`,
1258 ExpectedBazelTargets: []string{
1259 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenc4c34e12022-11-29 12:07:45 +00001260 "base_apex_name": `"com.android.apogee"`,
Jingwen Chenbea58092022-09-29 16:56:02 +00001261 "file_contexts": `":com.android.apogee-file_contexts"`,
1262 "certificate_name": `"com.google.android.apogee.certificate"`,
1263 "manifest": `"apogee_manifest.json"`,
1264 }),
1265 }})
1266}
Yu Liu4c212ce2022-10-14 12:20:20 -07001267
1268func TestApexTestBundleSimple(t *testing.T) {
1269 runApexTestCase(t, Bp2buildTestCase{
1270 Description: "apex_test - simple",
1271 ModuleTypeUnderTest: "apex_test",
1272 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
1273 Filesystem: map[string]string{},
1274 Blueprint: `
1275cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } }
1276
1277apex_test {
1278 name: "test_com.android.apogee",
1279 file_contexts: "file_contexts_file",
1280 tests: ["cc_test_1"],
1281}
1282`,
1283 ExpectedBazelTargets: []string{
1284 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
1285 "file_contexts": `"file_contexts_file"`,
1286 "manifest": `"apex_manifest.json"`,
1287 "testonly": `True`,
1288 "tests": `[":cc_test_1"]`,
1289 }),
1290 }})
1291}