blob: b6061e46ea877dacc6c8997567499b7ca2e11896 [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"`,
666 "binaries": `[
667 ":cc_binary_1",
668 ":sh_binary_2",
669 ]`,
670 "certificate": `":com.google.android.apogee.certificate"`,
671 "file_contexts": `":com.android.apogee-file_contexts"`,
672 "installable": "False",
673 "key": `":com.google.android.apogee.key"`,
674 "manifest": `"apogee_manifest.json"`,
675 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400676 "native_shared_libs_32": `select({
677 "//build/bazel/platforms/arch:arm": [
678 ":native_shared_lib_1",
679 ":native_shared_lib_2",
680 ],
681 "//build/bazel/platforms/arch:x86": [
682 ":native_shared_lib_1",
683 ":native_shared_lib_2",
684 ],
685 "//conditions:default": [],
686 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700687 "native_shared_libs_64": `select({
688 "//build/bazel/platforms/arch:arm64": [
689 ":native_shared_lib_1",
690 ":native_shared_lib_2",
691 ],
692 "//build/bazel/platforms/arch:x86_64": [
693 ":native_shared_lib_1",
694 ":native_shared_lib_2",
695 ],
696 "//conditions:default": [],
697 })`,
698 "prebuilts": `[]`,
699 "updatable": "False",
700 "compressible": "True",
701 }),
702 }})
703}
Wei Li40f98732022-05-20 22:08:11 -0700704
705func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000706 runOverrideApexTestCase(t, Bp2buildTestCase{
707 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
708 ModuleTypeUnderTest: "override_apex",
709 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
710 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700711 "system/sepolicy/apex/Android.bp": `
712filegroup {
713 name: "com.android.apogee-file_contexts",
714 srcs: [ "apogee-file_contexts", ],
715 bazel_module: { bp2build_available: false },
716}`,
717 "a/b/Android.bp": `
718apex {
719 name: "com.android.apogee",
720 bazel_module: { bp2build_available: false },
721}
722`,
723 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000724 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700725override_apex {
726 name: "com.google.android.apogee",
727 base: ":com.android.apogee",
728}
729`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000730 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000731 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700732 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
733 "manifest": `"//a/b:apex_manifest.json"`,
734 }),
735 }})
736}
737
738func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000739 runOverrideApexTestCase(t, Bp2buildTestCase{
740 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
741 ModuleTypeUnderTest: "override_apex",
742 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
743 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700744 "system/sepolicy/apex/Android.bp": `
745filegroup {
746 name: "com.android.apogee-file_contexts",
747 srcs: [ "apogee-file_contexts", ],
748 bazel_module: { bp2build_available: false },
749}`,
750 "a/b/Android.bp": `
751apex {
752 name: "com.android.apogee",
753 manifest: "apogee_manifest.json",
754 bazel_module: { bp2build_available: false },
755}
756`,
757 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000758 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700759override_apex {
760 name: "com.google.android.apogee",
761 base: ":com.android.apogee",
762}
763`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000764 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000765 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700766 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
767 "manifest": `"//a/b:apogee_manifest.json"`,
768 }),
769 }})
770}
771
772func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000773 runOverrideApexTestCase(t, Bp2buildTestCase{
774 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
775 ModuleTypeUnderTest: "override_apex",
776 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
777 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700778 "system/sepolicy/apex/Android.bp": `
779filegroup {
780 name: "com.android.apogee-file_contexts",
781 srcs: [ "apogee-file_contexts", ],
782 bazel_module: { bp2build_available: false },
783}`,
784 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000785 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700786apex {
787 name: "com.android.apogee",
788 bazel_module: { bp2build_available: false },
789}
790
791override_apex {
792 name: "com.google.android.apogee",
793 base: ":com.android.apogee",
794}
795`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000796 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000797 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700798 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
799 "manifest": `"apex_manifest.json"`,
800 }),
801 }})
802}
803
804func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000805 runOverrideApexTestCase(t, Bp2buildTestCase{
806 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
807 ModuleTypeUnderTest: "override_apex",
808 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
809 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700810 "system/sepolicy/apex/Android.bp": `
811filegroup {
812 name: "com.android.apogee-file_contexts",
813 srcs: [ "apogee-file_contexts", ],
814 bazel_module: { bp2build_available: false },
815}`,
816 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000817 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700818apex {
819 name: "com.android.apogee",
820 manifest: "apogee_manifest.json",
821 bazel_module: { bp2build_available: false },
822}
823
824override_apex {
825 name: "com.google.android.apogee",
826 base: ":com.android.apogee",
827}
828`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000829 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000830 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700831 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
832 "manifest": `"apogee_manifest.json"`,
833 }),
834 }})
835}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000836
837func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000838 runOverrideApexTestCase(t, Bp2buildTestCase{
839 Description: "override_apex - override package name",
840 ModuleTypeUnderTest: "override_apex",
841 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
842 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000843 "system/sepolicy/apex/Android.bp": `
844filegroup {
845 name: "com.android.apogee-file_contexts",
846 srcs: [ "apogee-file_contexts", ],
847 bazel_module: { bp2build_available: false },
848}`,
849 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000850 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000851apex {
852 name: "com.android.apogee",
853 bazel_module: { bp2build_available: false },
854}
855
856override_apex {
857 name: "com.google.android.apogee",
858 base: ":com.android.apogee",
859 package_name: "com.google.android.apogee",
860}
861`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000862 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000863 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000864 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
865 "manifest": `"apex_manifest.json"`,
866 "package_name": `"com.google.android.apogee"`,
867 }),
868 }})
869}
Jingwen Chendf165c92022-06-08 16:00:39 +0000870
871func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000872 runOverrideApexTestCase(t, Bp2buildTestCase{
873 Description: "override_apex - no override",
874 ModuleTypeUnderTest: "override_apex",
875 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
876 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000877 "system/sepolicy/apex/Android.bp": `
878filegroup {
879 name: "com.android.apogee-file_contexts",
880 srcs: [ "apogee-file_contexts", ],
881 bazel_module: { bp2build_available: false },
882}`,
883 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000884 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000885prebuilt_etc {
886 name: "prebuilt_file",
887 bazel_module: { bp2build_available: false },
888}
889
890apex {
891 name: "com.android.apogee",
892 bazel_module: { bp2build_available: false },
893 prebuilts: ["prebuilt_file"]
894}
895
896override_apex {
897 name: "com.google.android.apogee",
898 base: ":com.android.apogee",
899}
900`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000901 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000902 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chendf165c92022-06-08 16:00:39 +0000903 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
904 "manifest": `"apex_manifest.json"`,
905 "prebuilts": `[":prebuilt_file"]`,
906 }),
907 }})
908}
909
910func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000911 runOverrideApexTestCase(t, Bp2buildTestCase{
912 Description: "override_apex - ooverride",
913 ModuleTypeUnderTest: "override_apex",
914 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
915 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000916 "system/sepolicy/apex/Android.bp": `
917filegroup {
918 name: "com.android.apogee-file_contexts",
919 srcs: [ "apogee-file_contexts", ],
920 bazel_module: { bp2build_available: false },
921}`,
922 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000923 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000924prebuilt_etc {
925 name: "prebuilt_file",
926 bazel_module: { bp2build_available: false },
927}
928
929prebuilt_etc {
930 name: "prebuilt_file2",
931 bazel_module: { bp2build_available: false },
932}
933
934apex {
935 name: "com.android.apogee",
936 bazel_module: { bp2build_available: false },
937 prebuilts: ["prebuilt_file"]
938}
939
940override_apex {
941 name: "com.google.android.apogee",
942 base: ":com.android.apogee",
943 prebuilts: ["prebuilt_file2"]
944}
945`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000946 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000947 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chendf165c92022-06-08 16:00:39 +0000948 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
949 "manifest": `"apex_manifest.json"`,
950 "prebuilts": `[":prebuilt_file2"]`,
951 }),
952 }})
953}
954
955func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000956 runOverrideApexTestCase(t, Bp2buildTestCase{
957 Description: "override_apex - override with empty list",
958 ModuleTypeUnderTest: "override_apex",
959 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
960 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000961 "system/sepolicy/apex/Android.bp": `
962filegroup {
963 name: "com.android.apogee-file_contexts",
964 srcs: [ "apogee-file_contexts", ],
965 bazel_module: { bp2build_available: false },
966}`,
967 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000968 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000969prebuilt_etc {
970 name: "prebuilt_file",
971 bazel_module: { bp2build_available: false },
972}
973
974apex {
975 name: "com.android.apogee",
976 bazel_module: { bp2build_available: false },
977 prebuilts: ["prebuilt_file"]
978}
979
980override_apex {
981 name: "com.google.android.apogee",
982 base: ":com.android.apogee",
983 prebuilts: [],
984}
985`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000986 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000987 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chendf165c92022-06-08 16:00:39 +0000988 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
989 "manifest": `"apex_manifest.json"`,
990 "prebuilts": `[]`,
991 }),
992 }})
993}
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000994
995func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000996 runOverrideApexTestCase(t, Bp2buildTestCase{
997 Description: "override_apex - logging_parent - no override",
998 ModuleTypeUnderTest: "override_apex",
999 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1000 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001001 "system/sepolicy/apex/Android.bp": `
1002filegroup {
1003 name: "com.android.apogee-file_contexts",
1004 srcs: [ "apogee-file_contexts", ],
1005 bazel_module: { bp2build_available: false },
1006}`,
1007 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001008 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001009apex {
1010 name: "com.android.apogee",
1011 bazel_module: { bp2build_available: false },
1012 logging_parent: "foo.bar.baz",
1013}
1014
1015override_apex {
1016 name: "com.google.android.apogee",
1017 base: ":com.android.apogee",
1018}
1019`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001020 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001021 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001022 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1023 "manifest": `"apex_manifest.json"`,
1024 "logging_parent": `"foo.bar.baz"`,
1025 }),
1026 }})
1027}
1028
1029func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001030 runOverrideApexTestCase(t, Bp2buildTestCase{
1031 Description: "override_apex - logging_parent - override",
1032 ModuleTypeUnderTest: "override_apex",
1033 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1034 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001035 "system/sepolicy/apex/Android.bp": `
1036filegroup {
1037 name: "com.android.apogee-file_contexts",
1038 srcs: [ "apogee-file_contexts", ],
1039 bazel_module: { bp2build_available: false },
1040}`,
1041 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001042 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001043apex {
1044 name: "com.android.apogee",
1045 bazel_module: { bp2build_available: false },
1046 logging_parent: "foo.bar.baz",
1047}
1048
1049override_apex {
1050 name: "com.google.android.apogee",
1051 base: ":com.android.apogee",
1052 logging_parent: "foo.bar.baz.override",
1053}
1054`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001055 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001056 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001057 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1058 "manifest": `"apex_manifest.json"`,
1059 "logging_parent": `"foo.bar.baz.override"`,
1060 }),
1061 }})
1062}
Jingwen Chenbea58092022-09-29 16:56:02 +00001063
1064func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1065 runOverrideApexTestCase(t, Bp2buildTestCase{
1066 Description: "override_apex - don't set default certificate",
1067 ModuleTypeUnderTest: "override_apex",
1068 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1069 Filesystem: map[string]string{},
1070 Blueprint: `
1071android_app_certificate {
1072 name: "com.android.apogee.certificate",
1073 certificate: "com.android.apogee",
1074 bazel_module: { bp2build_available: false },
1075}
1076
1077filegroup {
1078 name: "com.android.apogee-file_contexts",
1079 srcs: [
1080 "com.android.apogee-file_contexts",
1081 ],
1082 bazel_module: { bp2build_available: false },
1083}
1084
1085apex {
1086 name: "com.android.apogee",
1087 manifest: "apogee_manifest.json",
1088 file_contexts: ":com.android.apogee-file_contexts",
1089 certificate: ":com.android.apogee.certificate",
1090 bazel_module: { bp2build_available: false },
1091}
1092
1093override_apex {
1094 name: "com.google.android.apogee",
1095 base: ":com.android.apogee",
1096 // certificate is deliberately omitted, and not converted to bazel,
1097 // because the overridden apex shouldn't be using the base apex's cert.
1098}
1099`,
1100 ExpectedBazelTargets: []string{
1101 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
1102 "file_contexts": `":com.android.apogee-file_contexts"`,
1103 "manifest": `"apogee_manifest.json"`,
1104 }),
1105 }})
1106}
1107
1108func TestApexCertificateIsModule(t *testing.T) {
1109 runApexTestCase(t, Bp2buildTestCase{
1110 Description: "apex - certificate is module",
1111 ModuleTypeUnderTest: "apex",
1112 ModuleTypeUnderTestFactory: apex.BundleFactory,
1113 Filesystem: map[string]string{},
1114 Blueprint: `
1115android_app_certificate {
1116 name: "com.android.apogee.certificate",
1117 certificate: "com.android.apogee",
1118 bazel_module: { bp2build_available: false },
1119}
1120
1121apex {
1122 name: "com.android.apogee",
1123 manifest: "apogee_manifest.json",
1124 file_contexts: ":com.android.apogee-file_contexts",
1125 certificate: ":com.android.apogee.certificate",
1126}
1127` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1128 ExpectedBazelTargets: []string{
1129 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1130 "certificate": `":com.android.apogee.certificate"`,
1131 "file_contexts": `":com.android.apogee-file_contexts"`,
1132 "manifest": `"apogee_manifest.json"`,
1133 }),
1134 }})
1135}
1136
1137func TestApexCertificateIsSrc(t *testing.T) {
1138 runApexTestCase(t, Bp2buildTestCase{
1139 Description: "apex - certificate is src",
1140 ModuleTypeUnderTest: "apex",
1141 ModuleTypeUnderTestFactory: apex.BundleFactory,
1142 Filesystem: map[string]string{},
1143 Blueprint: `
1144apex {
1145 name: "com.android.apogee",
1146 manifest: "apogee_manifest.json",
1147 file_contexts: ":com.android.apogee-file_contexts",
1148 certificate: "com.android.apogee.certificate",
1149}
1150` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1151 ExpectedBazelTargets: []string{
1152 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1153 "certificate_name": `"com.android.apogee.certificate"`,
1154 "file_contexts": `":com.android.apogee-file_contexts"`,
1155 "manifest": `"apogee_manifest.json"`,
1156 }),
1157 }})
1158}
1159
1160func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1161 runOverrideApexTestCase(t, Bp2buildTestCase{
1162 Description: "override_apex - certificate is module",
1163 ModuleTypeUnderTest: "override_apex",
1164 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1165 Filesystem: map[string]string{},
1166 Blueprint: `
1167android_app_certificate {
1168 name: "com.android.apogee.certificate",
1169 certificate: "com.android.apogee",
1170 bazel_module: { bp2build_available: false },
1171}
1172
1173filegroup {
1174 name: "com.android.apogee-file_contexts",
1175 srcs: [
1176 "com.android.apogee-file_contexts",
1177 ],
1178 bazel_module: { bp2build_available: false },
1179}
1180
1181apex {
1182 name: "com.android.apogee",
1183 manifest: "apogee_manifest.json",
1184 file_contexts: ":com.android.apogee-file_contexts",
1185 certificate: ":com.android.apogee.certificate",
1186 bazel_module: { bp2build_available: false },
1187}
1188
1189android_app_certificate {
1190 name: "com.google.android.apogee.certificate",
1191 certificate: "com.google.android.apogee",
1192 bazel_module: { bp2build_available: false },
1193}
1194
1195override_apex {
1196 name: "com.google.android.apogee",
1197 base: ":com.android.apogee",
1198 certificate: ":com.google.android.apogee.certificate",
1199}
1200`,
1201 ExpectedBazelTargets: []string{
1202 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
1203 "file_contexts": `":com.android.apogee-file_contexts"`,
1204 "certificate": `":com.google.android.apogee.certificate"`,
1205 "manifest": `"apogee_manifest.json"`,
1206 }),
1207 }})
1208}
1209
1210func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1211 runOverrideApexTestCase(t, Bp2buildTestCase{
1212 Description: "override_apex - certificate is src",
1213 ModuleTypeUnderTest: "override_apex",
1214 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1215 Filesystem: map[string]string{},
1216 Blueprint: `
1217android_app_certificate {
1218 name: "com.android.apogee.certificate",
1219 certificate: "com.android.apogee",
1220 bazel_module: { bp2build_available: false },
1221}
1222
1223filegroup {
1224 name: "com.android.apogee-file_contexts",
1225 srcs: [
1226 "com.android.apogee-file_contexts",
1227 ],
1228 bazel_module: { bp2build_available: false },
1229}
1230
1231apex {
1232 name: "com.android.apogee",
1233 manifest: "apogee_manifest.json",
1234 file_contexts: ":com.android.apogee-file_contexts",
1235 certificate: ":com.android.apogee.certificate",
1236 bazel_module: { bp2build_available: false },
1237}
1238
1239override_apex {
1240 name: "com.google.android.apogee",
1241 base: ":com.android.apogee",
1242 certificate: "com.google.android.apogee.certificate",
1243}
1244`,
1245 ExpectedBazelTargets: []string{
1246 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
1247 "file_contexts": `":com.android.apogee-file_contexts"`,
1248 "certificate_name": `"com.google.android.apogee.certificate"`,
1249 "manifest": `"apogee_manifest.json"`,
1250 }),
1251 }})
1252}
Yu Liu4c212ce2022-10-14 12:20:20 -07001253
1254func TestApexTestBundleSimple(t *testing.T) {
1255 runApexTestCase(t, Bp2buildTestCase{
1256 Description: "apex_test - simple",
1257 ModuleTypeUnderTest: "apex_test",
1258 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
1259 Filesystem: map[string]string{},
1260 Blueprint: `
1261cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } }
1262
1263apex_test {
1264 name: "test_com.android.apogee",
1265 file_contexts: "file_contexts_file",
1266 tests: ["cc_test_1"],
1267}
1268`,
1269 ExpectedBazelTargets: []string{
1270 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
1271 "file_contexts": `"file_contexts_file"`,
1272 "manifest": `"apex_manifest.json"`,
1273 "testonly": `True`,
1274 "tests": `[":cc_test_1"]`,
1275 }),
1276 }})
1277}