blob: a666e4994d4ecebc99d3e8f6c57339cecab4fff5 [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)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040045}
46
Sam Delmerico3177a6e2022-06-21 19:28:33 +000047func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) {
Wei Li1c66fc72022-05-09 23:59:14 -070048 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000049 RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc)
Wei Li1c66fc72022-05-09 23:59:14 -070050}
51
52func registerOverrideApexModuleTypes(ctx android.RegistrationContext) {
53 // CC module types needed as they can be APEX dependencies
54 cc.RegisterCCBuildComponents(ctx)
55
56 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
57 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
58 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
59 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
60 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
61 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
62 ctx.RegisterModuleType("apex", apex.BundleFactory)
Jingwen Chendf165c92022-06-08 16:00:39 +000063 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070064}
65
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040066func TestApexBundleSimple(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000067 runApexTestCase(t, Bp2buildTestCase{
68 Description: "apex - example with all props, file_context is a module in same Android.bp",
69 ModuleTypeUnderTest: "apex",
70 ModuleTypeUnderTestFactory: apex.BundleFactory,
71 Filesystem: map[string]string{},
72 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040073apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000074 name: "com.android.apogee.key",
75 public_key: "com.android.apogee.avbpubkey",
76 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040077 bazel_module: { bp2build_available: false },
78}
79
80android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000081 name: "com.android.apogee.certificate",
82 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040083 bazel_module: { bp2build_available: false },
84}
85
86cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000087 name: "native_shared_lib_1",
88 bazel_module: { bp2build_available: false },
89}
90
91cc_library {
92 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040093 bazel_module: { bp2build_available: false },
94}
95
Jingwen Chen81c67d32022-06-08 16:08:25 +000096prebuilt_etc {
97 name: "prebuilt_1",
Jingwen Chenb07c9012021-12-08 10:05:45 +000098 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040099}
100
Jingwen Chen81c67d32022-06-08 16:08:25 +0000101prebuilt_etc {
102 name: "prebuilt_2",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000103 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400104}
105
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400106filegroup {
107 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000108 srcs: [
Wei Li1c66fc72022-05-09 23:59:14 -0700109 "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000110 ],
111 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400112}
113
Jingwen Chenb07c9012021-12-08 10:05:45 +0000114cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
115sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
116
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400117apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400118 name: "com.android.apogee",
119 manifest: "apogee_manifest.json",
120 androidManifest: "ApogeeAndroidManifest.xml",
Wei Li1c66fc72022-05-09 23:59:14 -0700121 file_contexts: ":com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400122 min_sdk_version: "29",
123 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000124 certificate: ":com.android.apogee.certificate",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400125 updatable: false,
126 installable: false,
Wei Lif034cb42022-01-19 15:54:31 -0800127 compressible: false,
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400128 native_shared_libs: [
129 "native_shared_lib_1",
130 "native_shared_lib_2",
131 ],
132 binaries: [
Jingwen Chenb07c9012021-12-08 10:05:45 +0000133 "cc_binary_1",
134 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400135 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400136 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000137 "prebuilt_1",
138 "prebuilt_2",
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400139 ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000140 package_name: "com.android.apogee.test.package",
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000141 logging_parent: "logging.parent",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400142}
143`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000144 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000145 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500146 "android_manifest": `"ApogeeAndroidManifest.xml"`,
147 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000148 ":cc_binary_1",
149 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500150 ]`,
151 "certificate": `":com.android.apogee.certificate"`,
152 "file_contexts": `":com.android.apogee-file_contexts"`,
153 "installable": "False",
154 "key": `":com.android.apogee.key"`,
155 "manifest": `"apogee_manifest.json"`,
156 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400157 "native_shared_libs_32": `select({
158 "//build/bazel/platforms/arch:arm": [
159 ":native_shared_lib_1",
160 ":native_shared_lib_2",
161 ],
162 "//build/bazel/platforms/arch:x86": [
163 ":native_shared_lib_1",
164 ":native_shared_lib_2",
165 ],
166 "//conditions:default": [],
167 })`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800168 "native_shared_libs_64": `select({
169 "//build/bazel/platforms/arch:arm64": [
170 ":native_shared_lib_1",
171 ":native_shared_lib_2",
172 ],
173 "//build/bazel/platforms/arch:x86_64": [
174 ":native_shared_lib_1",
175 ":native_shared_lib_2",
176 ],
177 "//conditions:default": [],
178 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500179 "prebuilts": `[
Jingwen Chen81c67d32022-06-08 16:08:25 +0000180 ":prebuilt_1",
181 ":prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500182 ]`,
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000183 "updatable": "False",
184 "compressible": "False",
185 "package_name": `"com.android.apogee.test.package"`,
186 "logging_parent": `"logging.parent"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500187 }),
188 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400189}
190
Wei Li1c66fc72022-05-09 23:59:14 -0700191func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000192 runApexTestCase(t, Bp2buildTestCase{
193 Description: "apex - file contexts is a module in another Android.bp",
194 ModuleTypeUnderTest: "apex",
195 ModuleTypeUnderTestFactory: apex.BundleFactory,
196 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700197 "a/b/Android.bp": `
198filegroup {
199 name: "com.android.apogee-file_contexts",
200 srcs: [
201 "com.android.apogee-file_contexts",
202 ],
203 bazel_module: { bp2build_available: false },
204}
205`,
206 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000207 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700208apex {
209 name: "com.android.apogee",
210 file_contexts: ":com.android.apogee-file_contexts",
211}
212`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000213 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000214 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700215 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700216 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700217 }),
218 }})
219}
220
221func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000222 runApexTestCase(t, Bp2buildTestCase{
223 Description: "apex - file contexts is a file",
224 ModuleTypeUnderTest: "apex",
225 ModuleTypeUnderTestFactory: apex.BundleFactory,
226 Filesystem: map[string]string{},
227 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700228apex {
229 name: "com.android.apogee",
230 file_contexts: "file_contexts_file",
231}
232`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000233 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000234 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700235 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700236 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700237 }),
238 }})
239}
240
241func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000242 runApexTestCase(t, Bp2buildTestCase{
243 Description: "apex - file contexts is not specified",
244 ModuleTypeUnderTest: "apex",
245 ModuleTypeUnderTestFactory: apex.BundleFactory,
246 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700247 "system/sepolicy/apex/Android.bp": `
248filegroup {
249 name: "com.android.apogee-file_contexts",
250 srcs: [
251 "com.android.apogee-file_contexts",
252 ],
253 bazel_module: { bp2build_available: false },
254}
255`,
256 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000257 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700258apex {
259 name: "com.android.apogee",
260}
261`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000262 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000263 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700264 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700265 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700266 }),
267 }})
268}
269
Yu Liu4ae55d12022-01-05 17:17:23 -0800270func TestApexBundleCompileMultilibBoth(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000271 runApexTestCase(t, Bp2buildTestCase{
272 Description: "apex - example with compile_multilib=both",
273 ModuleTypeUnderTest: "apex",
274 ModuleTypeUnderTestFactory: apex.BundleFactory,
275 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700276 "system/sepolicy/apex/Android.bp": `
277filegroup {
278 name: "com.android.apogee-file_contexts",
279 srcs: [ "apogee-file_contexts", ],
280 bazel_module: { bp2build_available: false },
281}
282`,
283 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400284 Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000285 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000286 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800287 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400288 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000289 ":native_shared_lib_for_both",
290 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800291 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000292 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
293 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800294 "//conditions:default": [],
295 })`,
296 "native_shared_libs_64": `select({
297 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400298 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000299 ":native_shared_lib_for_both",
300 ":native_shared_lib_for_lib64",
301 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800302 ],
303 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400304 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000305 ":native_shared_lib_for_both",
306 ":native_shared_lib_for_lib64",
307 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800308 ],
309 "//conditions:default": [],
310 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700311 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700312 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800313 }),
314 }})
315}
316
Vinh Tran8f5310f2022-10-07 18:16:47 -0400317func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
318 expectedBazelTargets := []string{
319 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
320 "native_shared_libs_32": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800321 "//build/bazel/platforms/arch:arm": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400322 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000323 ":native_shared_lib_for_both",
324 ":native_shared_lib_for_lib32",
325 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800326 ],
327 "//build/bazel/platforms/arch:x86": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400328 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000329 ":native_shared_lib_for_both",
330 ":native_shared_lib_for_lib32",
331 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800332 ],
333 "//conditions:default": [],
334 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400335 "native_shared_libs_64": `select({
Yu Liu4ae55d12022-01-05 17:17:23 -0800336 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400337 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000338 ":native_shared_lib_for_both",
339 ":native_shared_lib_for_lib64",
340 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800341 ],
342 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400343 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000344 ":native_shared_lib_for_both",
345 ":native_shared_lib_for_lib64",
346 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800347 ],
348 "//conditions:default": [],
349 })`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400350 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
351 "manifest": `"apex_manifest.json"`,
352 }),
353 }
354
355 // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
356 // should result to the same bp2build output
357 compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
358 for _, compileMultiLibProp := range compileMultiLibPropValues {
359 descriptionSuffix := compileMultiLibProp
360 if descriptionSuffix == "" {
361 descriptionSuffix = "compile_multilib unset"
362 }
363 runApexTestCase(t, Bp2buildTestCase{
364 Description: "apex - example with " + compileMultiLibProp,
365 ModuleTypeUnderTest: "apex",
366 ModuleTypeUnderTestFactory: apex.BundleFactory,
367 Filesystem: map[string]string{
368 "system/sepolicy/apex/Android.bp": `
369 filegroup {
370 name: "com.android.apogee-file_contexts",
371 srcs: [ "apogee-file_contexts", ],
372 bazel_module: { bp2build_available: false },
373 }
374 `,
375 },
376 Blueprint: createMultilibBlueprint(compileMultiLibProp),
377 ExpectedBazelTargets: expectedBazelTargets,
378 })
379 }
Yu Liu4ae55d12022-01-05 17:17:23 -0800380}
381
382func TestApexBundleCompileMultilib32(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000383 runApexTestCase(t, Bp2buildTestCase{
384 Description: "apex - example with compile_multilib=32",
385 ModuleTypeUnderTest: "apex",
386 ModuleTypeUnderTestFactory: apex.BundleFactory,
387 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700388 "system/sepolicy/apex/Android.bp": `
389filegroup {
390 name: "com.android.apogee-file_contexts",
391 srcs: [ "apogee-file_contexts", ],
392 bazel_module: { bp2build_available: false },
393}
394`,
395 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400396 Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000397 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000398 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800399 "native_shared_libs_32": `[
Vinh Tran8f5310f2022-10-07 18:16:47 -0400400 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000401 ":native_shared_lib_for_both",
402 ":native_shared_lib_for_lib32",
Yu Liu4ae55d12022-01-05 17:17:23 -0800403 ] + select({
Jingwen Chen34feb142022-10-06 13:02:30 +0000404 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"],
405 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"],
Yu Liu4ae55d12022-01-05 17:17:23 -0800406 "//conditions:default": [],
407 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700408 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700409 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800410 }),
411 }})
412}
413
414func TestApexBundleCompileMultilib64(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000415 runApexTestCase(t, Bp2buildTestCase{
416 Description: "apex - example with compile_multilib=64",
417 ModuleTypeUnderTest: "apex",
418 ModuleTypeUnderTestFactory: apex.BundleFactory,
419 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700420 "system/sepolicy/apex/Android.bp": `
421filegroup {
422 name: "com.android.apogee-file_contexts",
423 srcs: [ "apogee-file_contexts", ],
424 bazel_module: { bp2build_available: false },
425}
426`,
427 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400428 Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000429 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000430 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Yu Liu4ae55d12022-01-05 17:17:23 -0800431 "native_shared_libs_64": `select({
432 "//build/bazel/platforms/arch:arm64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400433 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000434 ":native_shared_lib_for_both",
435 ":native_shared_lib_for_lib64",
436 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800437 ],
438 "//build/bazel/platforms/arch:x86_64": [
Vinh Tran8f5310f2022-10-07 18:16:47 -0400439 ":unnested_native_shared_lib",
Jingwen Chen34feb142022-10-06 13:02:30 +0000440 ":native_shared_lib_for_both",
441 ":native_shared_lib_for_lib64",
442 ":native_shared_lib_for_first",
Yu Liu4ae55d12022-01-05 17:17:23 -0800443 ],
444 "//conditions:default": [],
445 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700446 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700447 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800448 }),
449 }})
450}
451
Jingwen Chen34feb142022-10-06 13:02:30 +0000452func createMultilibBlueprint(compile_multilib string) string {
Vinh Tran8f5310f2022-10-07 18:16:47 -0400453 return fmt.Sprintf(`
Jingwen Chen34feb142022-10-06 13:02:30 +0000454cc_library {
455 name: "native_shared_lib_for_both",
456 bazel_module: { bp2build_available: false },
457}
458
459cc_library {
460 name: "native_shared_lib_for_first",
461 bazel_module: { bp2build_available: false },
462}
463
464cc_library {
465 name: "native_shared_lib_for_lib32",
466 bazel_module: { bp2build_available: false },
467}
468
469cc_library {
470 name: "native_shared_lib_for_lib64",
471 bazel_module: { bp2build_available: false },
472}
473
Vinh Tran8f5310f2022-10-07 18:16:47 -0400474cc_library {
475 name: "unnested_native_shared_lib",
476 bazel_module: { bp2build_available: false },
477}
478
Jingwen Chen34feb142022-10-06 13:02:30 +0000479apex {
480 name: "com.android.apogee",
Vinh Tran8f5310f2022-10-07 18:16:47 -0400481 %s
482 native_shared_libs: ["unnested_native_shared_lib"],
Jingwen Chen34feb142022-10-06 13:02:30 +0000483 multilib: {
484 both: {
485 native_shared_libs: [
486 "native_shared_lib_for_both",
487 ],
488 },
489 first: {
490 native_shared_libs: [
491 "native_shared_lib_for_first",
492 ],
493 },
494 lib32: {
495 native_shared_libs: [
496 "native_shared_lib_for_lib32",
497 ],
498 },
499 lib64: {
500 native_shared_libs: [
501 "native_shared_lib_for_lib64",
502 ],
503 },
504 },
Vinh Tran8f5310f2022-10-07 18:16:47 -0400505}`, compile_multilib)
Jingwen Chen34feb142022-10-06 13:02:30 +0000506}
507
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400508func TestApexBundleDefaultPropertyValues(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000509 runApexTestCase(t, Bp2buildTestCase{
510 Description: "apex - default property values",
511 ModuleTypeUnderTest: "apex",
512 ModuleTypeUnderTestFactory: apex.BundleFactory,
513 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700514 "system/sepolicy/apex/Android.bp": `
515filegroup {
516 name: "com.android.apogee-file_contexts",
517 srcs: [ "apogee-file_contexts", ],
518 bazel_module: { bp2build_available: false },
519}
520`,
521 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000522 Blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400523apex {
524 name: "com.android.apogee",
525 manifest: "apogee_manifest.json",
526}
527`,
Alixe06d75b2022-08-31 18:28:19 +0000528 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700529 "manifest": `"apogee_manifest.json"`,
530 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500531 }),
532 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400533}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000534
535func TestApexBundleHasBazelModuleProps(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000536 runApexTestCase(t, Bp2buildTestCase{
537 Description: "apex - has bazel module props",
538 ModuleTypeUnderTest: "apex",
539 ModuleTypeUnderTestFactory: apex.BundleFactory,
540 Filesystem: map[string]string{
Wei Li1c66fc72022-05-09 23:59:14 -0700541 "system/sepolicy/apex/Android.bp": `
542filegroup {
543 name: "apogee-file_contexts",
544 srcs: [ "apogee-file_contexts", ],
545 bazel_module: { bp2build_available: false },
546}
547`,
548 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000549 Blueprint: `
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000550apex {
551 name: "apogee",
552 manifest: "manifest.json",
553 bazel_module: { bp2build_available: true },
554}
555`,
Alixe06d75b2022-08-31 18:28:19 +0000556 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700557 "manifest": `"manifest.json"`,
558 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500559 }),
560 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000561}
Yu Liu4ae55d12022-01-05 17:17:23 -0800562
Wei Li1c66fc72022-05-09 23:59:14 -0700563func TestBp2BuildOverrideApex(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000564 runOverrideApexTestCase(t, Bp2buildTestCase{
565 Description: "override_apex",
566 ModuleTypeUnderTest: "override_apex",
567 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
568 Filesystem: map[string]string{},
569 Blueprint: `
Wei Li1c66fc72022-05-09 23:59:14 -0700570apex_key {
571 name: "com.android.apogee.key",
572 public_key: "com.android.apogee.avbpubkey",
573 private_key: "com.android.apogee.pem",
574 bazel_module: { bp2build_available: false },
575}
576
577android_app_certificate {
578 name: "com.android.apogee.certificate",
579 certificate: "com.android.apogee",
580 bazel_module: { bp2build_available: false },
581}
582
583cc_library {
584 name: "native_shared_lib_1",
585 bazel_module: { bp2build_available: false },
586}
587
588cc_library {
589 name: "native_shared_lib_2",
590 bazel_module: { bp2build_available: false },
591}
592
Jingwen Chen81c67d32022-06-08 16:08:25 +0000593prebuilt_etc {
594 name: "prebuilt_1",
Wei Li1c66fc72022-05-09 23:59:14 -0700595 bazel_module: { bp2build_available: false },
596}
597
Jingwen Chen81c67d32022-06-08 16:08:25 +0000598prebuilt_etc {
599 name: "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700600 bazel_module: { bp2build_available: false },
601}
602
603filegroup {
604 name: "com.android.apogee-file_contexts",
605 srcs: [
606 "com.android.apogee-file_contexts",
607 ],
608 bazel_module: { bp2build_available: false },
609}
610
611cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
612sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
613
614apex {
615 name: "com.android.apogee",
616 manifest: "apogee_manifest.json",
617 androidManifest: "ApogeeAndroidManifest.xml",
618 file_contexts: ":com.android.apogee-file_contexts",
619 min_sdk_version: "29",
620 key: "com.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000621 certificate: ":com.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700622 updatable: false,
623 installable: false,
624 compressible: false,
625 native_shared_libs: [
626 "native_shared_lib_1",
627 "native_shared_lib_2",
628 ],
629 binaries: [
630 "cc_binary_1",
631 "sh_binary_2",
632 ],
633 prebuilts: [
Jingwen Chen81c67d32022-06-08 16:08:25 +0000634 "prebuilt_1",
635 "prebuilt_2",
Wei Li1c66fc72022-05-09 23:59:14 -0700636 ],
637 bazel_module: { bp2build_available: false },
638}
639
640apex_key {
641 name: "com.google.android.apogee.key",
642 public_key: "com.google.android.apogee.avbpubkey",
643 private_key: "com.google.android.apogee.pem",
644 bazel_module: { bp2build_available: false },
645}
646
647android_app_certificate {
648 name: "com.google.android.apogee.certificate",
649 certificate: "com.google.android.apogee",
650 bazel_module: { bp2build_available: false },
651}
652
653override_apex {
654 name: "com.google.android.apogee",
655 base: ":com.android.apogee",
656 key: "com.google.android.apogee.key",
Jingwen Chenbea58092022-09-29 16:56:02 +0000657 certificate: ":com.google.android.apogee.certificate",
Wei Li1c66fc72022-05-09 23:59:14 -0700658 prebuilts: [],
659 compressible: true,
660}
661`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000662 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000663 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700664 "android_manifest": `"ApogeeAndroidManifest.xml"`,
665 "binaries": `[
666 ":cc_binary_1",
667 ":sh_binary_2",
668 ]`,
669 "certificate": `":com.google.android.apogee.certificate"`,
670 "file_contexts": `":com.android.apogee-file_contexts"`,
671 "installable": "False",
672 "key": `":com.google.android.apogee.key"`,
673 "manifest": `"apogee_manifest.json"`,
674 "min_sdk_version": `"29"`,
Vinh Tran8f5310f2022-10-07 18:16:47 -0400675 "native_shared_libs_32": `select({
676 "//build/bazel/platforms/arch:arm": [
677 ":native_shared_lib_1",
678 ":native_shared_lib_2",
679 ],
680 "//build/bazel/platforms/arch:x86": [
681 ":native_shared_lib_1",
682 ":native_shared_lib_2",
683 ],
684 "//conditions:default": [],
685 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700686 "native_shared_libs_64": `select({
687 "//build/bazel/platforms/arch:arm64": [
688 ":native_shared_lib_1",
689 ":native_shared_lib_2",
690 ],
691 "//build/bazel/platforms/arch:x86_64": [
692 ":native_shared_lib_1",
693 ":native_shared_lib_2",
694 ],
695 "//conditions:default": [],
696 })`,
697 "prebuilts": `[]`,
698 "updatable": "False",
699 "compressible": "True",
700 }),
701 }})
702}
Wei Li40f98732022-05-20 22:08:11 -0700703
704func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000705 runOverrideApexTestCase(t, Bp2buildTestCase{
706 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
707 ModuleTypeUnderTest: "override_apex",
708 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
709 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700710 "system/sepolicy/apex/Android.bp": `
711filegroup {
712 name: "com.android.apogee-file_contexts",
713 srcs: [ "apogee-file_contexts", ],
714 bazel_module: { bp2build_available: false },
715}`,
716 "a/b/Android.bp": `
717apex {
718 name: "com.android.apogee",
719 bazel_module: { bp2build_available: false },
720}
721`,
722 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000723 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700724override_apex {
725 name: "com.google.android.apogee",
726 base: ":com.android.apogee",
727}
728`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000729 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000730 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700731 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
732 "manifest": `"//a/b:apex_manifest.json"`,
733 }),
734 }})
735}
736
737func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000738 runOverrideApexTestCase(t, Bp2buildTestCase{
739 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
740 ModuleTypeUnderTest: "override_apex",
741 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
742 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700743 "system/sepolicy/apex/Android.bp": `
744filegroup {
745 name: "com.android.apogee-file_contexts",
746 srcs: [ "apogee-file_contexts", ],
747 bazel_module: { bp2build_available: false },
748}`,
749 "a/b/Android.bp": `
750apex {
751 name: "com.android.apogee",
752 manifest: "apogee_manifest.json",
753 bazel_module: { bp2build_available: false },
754}
755`,
756 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000757 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700758override_apex {
759 name: "com.google.android.apogee",
760 base: ":com.android.apogee",
761}
762`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000763 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000764 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700765 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
766 "manifest": `"//a/b:apogee_manifest.json"`,
767 }),
768 }})
769}
770
771func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000772 runOverrideApexTestCase(t, Bp2buildTestCase{
773 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
774 ModuleTypeUnderTest: "override_apex",
775 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
776 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700777 "system/sepolicy/apex/Android.bp": `
778filegroup {
779 name: "com.android.apogee-file_contexts",
780 srcs: [ "apogee-file_contexts", ],
781 bazel_module: { bp2build_available: false },
782}`,
783 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000784 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700785apex {
786 name: "com.android.apogee",
787 bazel_module: { bp2build_available: false },
788}
789
790override_apex {
791 name: "com.google.android.apogee",
792 base: ":com.android.apogee",
793}
794`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000795 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000796 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700797 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
798 "manifest": `"apex_manifest.json"`,
799 }),
800 }})
801}
802
803func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000804 runOverrideApexTestCase(t, Bp2buildTestCase{
805 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
806 ModuleTypeUnderTest: "override_apex",
807 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
808 Filesystem: map[string]string{
Wei Li40f98732022-05-20 22:08:11 -0700809 "system/sepolicy/apex/Android.bp": `
810filegroup {
811 name: "com.android.apogee-file_contexts",
812 srcs: [ "apogee-file_contexts", ],
813 bazel_module: { bp2build_available: false },
814}`,
815 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000816 Blueprint: `
Wei Li40f98732022-05-20 22:08:11 -0700817apex {
818 name: "com.android.apogee",
819 manifest: "apogee_manifest.json",
820 bazel_module: { bp2build_available: false },
821}
822
823override_apex {
824 name: "com.google.android.apogee",
825 base: ":com.android.apogee",
826}
827`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000828 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000829 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Wei Li40f98732022-05-20 22:08:11 -0700830 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
831 "manifest": `"apogee_manifest.json"`,
832 }),
833 }})
834}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000835
836func TestApexBundleSimple_packageNameOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000837 runOverrideApexTestCase(t, Bp2buildTestCase{
838 Description: "override_apex - override package name",
839 ModuleTypeUnderTest: "override_apex",
840 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
841 Filesystem: map[string]string{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000842 "system/sepolicy/apex/Android.bp": `
843filegroup {
844 name: "com.android.apogee-file_contexts",
845 srcs: [ "apogee-file_contexts", ],
846 bazel_module: { bp2build_available: false },
847}`,
848 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000849 Blueprint: `
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000850apex {
851 name: "com.android.apogee",
852 bazel_module: { bp2build_available: false },
853}
854
855override_apex {
856 name: "com.google.android.apogee",
857 base: ":com.android.apogee",
858 package_name: "com.google.android.apogee",
859}
860`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000861 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000862 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000863 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
864 "manifest": `"apex_manifest.json"`,
865 "package_name": `"com.google.android.apogee"`,
866 }),
867 }})
868}
Jingwen Chendf165c92022-06-08 16:00:39 +0000869
870func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000871 runOverrideApexTestCase(t, Bp2buildTestCase{
872 Description: "override_apex - no override",
873 ModuleTypeUnderTest: "override_apex",
874 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
875 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000876 "system/sepolicy/apex/Android.bp": `
877filegroup {
878 name: "com.android.apogee-file_contexts",
879 srcs: [ "apogee-file_contexts", ],
880 bazel_module: { bp2build_available: false },
881}`,
882 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000883 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000884prebuilt_etc {
885 name: "prebuilt_file",
886 bazel_module: { bp2build_available: false },
887}
888
889apex {
890 name: "com.android.apogee",
891 bazel_module: { bp2build_available: false },
892 prebuilts: ["prebuilt_file"]
893}
894
895override_apex {
896 name: "com.google.android.apogee",
897 base: ":com.android.apogee",
898}
899`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000900 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000901 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chendf165c92022-06-08 16:00:39 +0000902 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
903 "manifest": `"apex_manifest.json"`,
904 "prebuilts": `[":prebuilt_file"]`,
905 }),
906 }})
907}
908
909func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000910 runOverrideApexTestCase(t, Bp2buildTestCase{
911 Description: "override_apex - ooverride",
912 ModuleTypeUnderTest: "override_apex",
913 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
914 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000915 "system/sepolicy/apex/Android.bp": `
916filegroup {
917 name: "com.android.apogee-file_contexts",
918 srcs: [ "apogee-file_contexts", ],
919 bazel_module: { bp2build_available: false },
920}`,
921 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000922 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000923prebuilt_etc {
924 name: "prebuilt_file",
925 bazel_module: { bp2build_available: false },
926}
927
928prebuilt_etc {
929 name: "prebuilt_file2",
930 bazel_module: { bp2build_available: false },
931}
932
933apex {
934 name: "com.android.apogee",
935 bazel_module: { bp2build_available: false },
936 prebuilts: ["prebuilt_file"]
937}
938
939override_apex {
940 name: "com.google.android.apogee",
941 base: ":com.android.apogee",
942 prebuilts: ["prebuilt_file2"]
943}
944`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000945 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000946 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chendf165c92022-06-08 16:00:39 +0000947 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
948 "manifest": `"apex_manifest.json"`,
949 "prebuilts": `[":prebuilt_file2"]`,
950 }),
951 }})
952}
953
954func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000955 runOverrideApexTestCase(t, Bp2buildTestCase{
956 Description: "override_apex - override with empty list",
957 ModuleTypeUnderTest: "override_apex",
958 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
959 Filesystem: map[string]string{
Jingwen Chendf165c92022-06-08 16:00:39 +0000960 "system/sepolicy/apex/Android.bp": `
961filegroup {
962 name: "com.android.apogee-file_contexts",
963 srcs: [ "apogee-file_contexts", ],
964 bazel_module: { bp2build_available: false },
965}`,
966 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000967 Blueprint: `
Jingwen Chendf165c92022-06-08 16:00:39 +0000968prebuilt_etc {
969 name: "prebuilt_file",
970 bazel_module: { bp2build_available: false },
971}
972
973apex {
974 name: "com.android.apogee",
975 bazel_module: { bp2build_available: false },
976 prebuilts: ["prebuilt_file"]
977}
978
979override_apex {
980 name: "com.google.android.apogee",
981 base: ":com.android.apogee",
982 prebuilts: [],
983}
984`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000985 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +0000986 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chendf165c92022-06-08 16:00:39 +0000987 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
988 "manifest": `"apex_manifest.json"`,
989 "prebuilts": `[]`,
990 }),
991 }})
992}
Jingwen Chenb732d7c2022-06-10 08:14:19 +0000993
994func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +0000995 runOverrideApexTestCase(t, Bp2buildTestCase{
996 Description: "override_apex - logging_parent - no override",
997 ModuleTypeUnderTest: "override_apex",
998 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
999 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001000 "system/sepolicy/apex/Android.bp": `
1001filegroup {
1002 name: "com.android.apogee-file_contexts",
1003 srcs: [ "apogee-file_contexts", ],
1004 bazel_module: { bp2build_available: false },
1005}`,
1006 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001007 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001008apex {
1009 name: "com.android.apogee",
1010 bazel_module: { bp2build_available: false },
1011 logging_parent: "foo.bar.baz",
1012}
1013
1014override_apex {
1015 name: "com.google.android.apogee",
1016 base: ":com.android.apogee",
1017}
1018`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001019 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001020 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001021 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1022 "manifest": `"apex_manifest.json"`,
1023 "logging_parent": `"foo.bar.baz"`,
1024 }),
1025 }})
1026}
1027
1028func TestApexBundleSimple_LoggingParentOverride(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001029 runOverrideApexTestCase(t, Bp2buildTestCase{
1030 Description: "override_apex - logging_parent - override",
1031 ModuleTypeUnderTest: "override_apex",
1032 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1033 Filesystem: map[string]string{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001034 "system/sepolicy/apex/Android.bp": `
1035filegroup {
1036 name: "com.android.apogee-file_contexts",
1037 srcs: [ "apogee-file_contexts", ],
1038 bazel_module: { bp2build_available: false },
1039}`,
1040 },
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001041 Blueprint: `
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001042apex {
1043 name: "com.android.apogee",
1044 bazel_module: { bp2build_available: false },
1045 logging_parent: "foo.bar.baz",
1046}
1047
1048override_apex {
1049 name: "com.google.android.apogee",
1050 base: ":com.android.apogee",
1051 logging_parent: "foo.bar.baz.override",
1052}
1053`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +00001054 ExpectedBazelTargets: []string{
Alixe06d75b2022-08-31 18:28:19 +00001055 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
Jingwen Chenb732d7c2022-06-10 08:14:19 +00001056 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
1057 "manifest": `"apex_manifest.json"`,
1058 "logging_parent": `"foo.bar.baz.override"`,
1059 }),
1060 }})
1061}
Jingwen Chenbea58092022-09-29 16:56:02 +00001062
1063func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) {
1064 runOverrideApexTestCase(t, Bp2buildTestCase{
1065 Description: "override_apex - don't set default certificate",
1066 ModuleTypeUnderTest: "override_apex",
1067 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1068 Filesystem: map[string]string{},
1069 Blueprint: `
1070android_app_certificate {
1071 name: "com.android.apogee.certificate",
1072 certificate: "com.android.apogee",
1073 bazel_module: { bp2build_available: false },
1074}
1075
1076filegroup {
1077 name: "com.android.apogee-file_contexts",
1078 srcs: [
1079 "com.android.apogee-file_contexts",
1080 ],
1081 bazel_module: { bp2build_available: false },
1082}
1083
1084apex {
1085 name: "com.android.apogee",
1086 manifest: "apogee_manifest.json",
1087 file_contexts: ":com.android.apogee-file_contexts",
1088 certificate: ":com.android.apogee.certificate",
1089 bazel_module: { bp2build_available: false },
1090}
1091
1092override_apex {
1093 name: "com.google.android.apogee",
1094 base: ":com.android.apogee",
1095 // certificate is deliberately omitted, and not converted to bazel,
1096 // because the overridden apex shouldn't be using the base apex's cert.
1097}
1098`,
1099 ExpectedBazelTargets: []string{
1100 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
1101 "file_contexts": `":com.android.apogee-file_contexts"`,
1102 "manifest": `"apogee_manifest.json"`,
1103 }),
1104 }})
1105}
1106
1107func TestApexCertificateIsModule(t *testing.T) {
1108 runApexTestCase(t, Bp2buildTestCase{
1109 Description: "apex - certificate is module",
1110 ModuleTypeUnderTest: "apex",
1111 ModuleTypeUnderTestFactory: apex.BundleFactory,
1112 Filesystem: map[string]string{},
1113 Blueprint: `
1114android_app_certificate {
1115 name: "com.android.apogee.certificate",
1116 certificate: "com.android.apogee",
1117 bazel_module: { bp2build_available: false },
1118}
1119
1120apex {
1121 name: "com.android.apogee",
1122 manifest: "apogee_manifest.json",
1123 file_contexts: ":com.android.apogee-file_contexts",
1124 certificate: ":com.android.apogee.certificate",
1125}
1126` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1127 ExpectedBazelTargets: []string{
1128 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1129 "certificate": `":com.android.apogee.certificate"`,
1130 "file_contexts": `":com.android.apogee-file_contexts"`,
1131 "manifest": `"apogee_manifest.json"`,
1132 }),
1133 }})
1134}
1135
1136func TestApexCertificateIsSrc(t *testing.T) {
1137 runApexTestCase(t, Bp2buildTestCase{
1138 Description: "apex - certificate is src",
1139 ModuleTypeUnderTest: "apex",
1140 ModuleTypeUnderTestFactory: apex.BundleFactory,
1141 Filesystem: map[string]string{},
1142 Blueprint: `
1143apex {
1144 name: "com.android.apogee",
1145 manifest: "apogee_manifest.json",
1146 file_contexts: ":com.android.apogee-file_contexts",
1147 certificate: "com.android.apogee.certificate",
1148}
1149` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"),
1150 ExpectedBazelTargets: []string{
1151 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
1152 "certificate_name": `"com.android.apogee.certificate"`,
1153 "file_contexts": `":com.android.apogee-file_contexts"`,
1154 "manifest": `"apogee_manifest.json"`,
1155 }),
1156 }})
1157}
1158
1159func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) {
1160 runOverrideApexTestCase(t, Bp2buildTestCase{
1161 Description: "override_apex - certificate is module",
1162 ModuleTypeUnderTest: "override_apex",
1163 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1164 Filesystem: map[string]string{},
1165 Blueprint: `
1166android_app_certificate {
1167 name: "com.android.apogee.certificate",
1168 certificate: "com.android.apogee",
1169 bazel_module: { bp2build_available: false },
1170}
1171
1172filegroup {
1173 name: "com.android.apogee-file_contexts",
1174 srcs: [
1175 "com.android.apogee-file_contexts",
1176 ],
1177 bazel_module: { bp2build_available: false },
1178}
1179
1180apex {
1181 name: "com.android.apogee",
1182 manifest: "apogee_manifest.json",
1183 file_contexts: ":com.android.apogee-file_contexts",
1184 certificate: ":com.android.apogee.certificate",
1185 bazel_module: { bp2build_available: false },
1186}
1187
1188android_app_certificate {
1189 name: "com.google.android.apogee.certificate",
1190 certificate: "com.google.android.apogee",
1191 bazel_module: { bp2build_available: false },
1192}
1193
1194override_apex {
1195 name: "com.google.android.apogee",
1196 base: ":com.android.apogee",
1197 certificate: ":com.google.android.apogee.certificate",
1198}
1199`,
1200 ExpectedBazelTargets: []string{
1201 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
1202 "file_contexts": `":com.android.apogee-file_contexts"`,
1203 "certificate": `":com.google.android.apogee.certificate"`,
1204 "manifest": `"apogee_manifest.json"`,
1205 }),
1206 }})
1207}
1208
1209func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) {
1210 runOverrideApexTestCase(t, Bp2buildTestCase{
1211 Description: "override_apex - certificate is src",
1212 ModuleTypeUnderTest: "override_apex",
1213 ModuleTypeUnderTestFactory: apex.OverrideApexFactory,
1214 Filesystem: map[string]string{},
1215 Blueprint: `
1216android_app_certificate {
1217 name: "com.android.apogee.certificate",
1218 certificate: "com.android.apogee",
1219 bazel_module: { bp2build_available: false },
1220}
1221
1222filegroup {
1223 name: "com.android.apogee-file_contexts",
1224 srcs: [
1225 "com.android.apogee-file_contexts",
1226 ],
1227 bazel_module: { bp2build_available: false },
1228}
1229
1230apex {
1231 name: "com.android.apogee",
1232 manifest: "apogee_manifest.json",
1233 file_contexts: ":com.android.apogee-file_contexts",
1234 certificate: ":com.android.apogee.certificate",
1235 bazel_module: { bp2build_available: false },
1236}
1237
1238override_apex {
1239 name: "com.google.android.apogee",
1240 base: ":com.android.apogee",
1241 certificate: "com.google.android.apogee.certificate",
1242}
1243`,
1244 ExpectedBazelTargets: []string{
1245 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
1246 "file_contexts": `":com.android.apogee-file_contexts"`,
1247 "certificate_name": `"com.google.android.apogee.certificate"`,
1248 "manifest": `"apogee_manifest.json"`,
1249 }),
1250 }})
1251}