blob: 00443f69f0056c0903915f0abefe709fe7fe8dd7 [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
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040025 "testing"
26)
27
28func runApexTestCase(t *testing.T, tc bp2buildTestCase) {
29 t.Helper()
30 runBp2BuildTestCase(t, registerApexModuleTypes, tc)
31}
32
33func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040034 // CC module types needed as they can be APEX dependencies
35 cc.RegisterCCBuildComponents(ctx)
36
Jingwen Chenb07c9012021-12-08 10:05:45 +000037 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
38 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040039 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
40 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
41 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
42 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040043}
44
Wei Li1c66fc72022-05-09 23:59:14 -070045func runOverrideApexTestCase(t *testing.T, tc bp2buildTestCase) {
46 t.Helper()
47 runBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc)
48}
49
50func registerOverrideApexModuleTypes(ctx android.RegistrationContext) {
51 // CC module types needed as they can be APEX dependencies
52 cc.RegisterCCBuildComponents(ctx)
53
54 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
55 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
56 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
57 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
58 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
59 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
60 ctx.RegisterModuleType("apex", apex.BundleFactory)
Jingwen Chendf165c92022-06-08 16:00:39 +000061 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
Wei Li1c66fc72022-05-09 23:59:14 -070062}
63
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040064func TestApexBundleSimple(t *testing.T) {
65 runApexTestCase(t, bp2buildTestCase{
Wei Li1c66fc72022-05-09 23:59:14 -070066 description: "apex - example with all props, file_context is a module in same Android.bp",
Liz Kammerbe46fcc2021-11-01 15:32:43 -040067 moduleTypeUnderTest: "apex",
68 moduleTypeUnderTestFactory: apex.BundleFactory,
69 filesystem: map[string]string{},
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040070 blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040071apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000072 name: "com.android.apogee.key",
73 public_key: "com.android.apogee.avbpubkey",
74 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040075 bazel_module: { bp2build_available: false },
76}
77
78android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000079 name: "com.android.apogee.certificate",
80 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040081 bazel_module: { bp2build_available: false },
82}
83
84cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000085 name: "native_shared_lib_1",
86 bazel_module: { bp2build_available: false },
87}
88
89cc_library {
90 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040091 bazel_module: { bp2build_available: false },
92}
93
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040094cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000095 name: "pretend_prebuilt_1",
96 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040097}
98
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040099cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +0000100 name: "pretend_prebuilt_2",
101 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400102}
103
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400104filegroup {
105 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000106 srcs: [
Wei Li1c66fc72022-05-09 23:59:14 -0700107 "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000108 ],
109 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400110}
111
Jingwen Chenb07c9012021-12-08 10:05:45 +0000112cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
113sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
114
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400115apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400116 name: "com.android.apogee",
117 manifest: "apogee_manifest.json",
118 androidManifest: "ApogeeAndroidManifest.xml",
Wei Li1c66fc72022-05-09 23:59:14 -0700119 file_contexts: ":com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400120 min_sdk_version: "29",
121 key: "com.android.apogee.key",
122 certificate: "com.android.apogee.certificate",
123 updatable: false,
124 installable: false,
Wei Lif034cb42022-01-19 15:54:31 -0800125 compressible: false,
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400126 native_shared_libs: [
127 "native_shared_lib_1",
128 "native_shared_lib_2",
129 ],
130 binaries: [
Jingwen Chenb07c9012021-12-08 10:05:45 +0000131 "cc_binary_1",
132 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400133 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400134 prebuilts: [
135 "pretend_prebuilt_1",
136 "pretend_prebuilt_2",
137 ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000138 package_name: "com.android.apogee.test.package",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400139}
140`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500141 expectedBazelTargets: []string{
142 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
143 "android_manifest": `"ApogeeAndroidManifest.xml"`,
144 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000145 ":cc_binary_1",
146 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500147 ]`,
148 "certificate": `":com.android.apogee.certificate"`,
149 "file_contexts": `":com.android.apogee-file_contexts"`,
150 "installable": "False",
151 "key": `":com.android.apogee.key"`,
152 "manifest": `"apogee_manifest.json"`,
153 "min_sdk_version": `"29"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800154 "native_shared_libs_32": `[
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400155 ":native_shared_lib_1",
156 ":native_shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500157 ]`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800158 "native_shared_libs_64": `select({
159 "//build/bazel/platforms/arch:arm64": [
160 ":native_shared_lib_1",
161 ":native_shared_lib_2",
162 ],
163 "//build/bazel/platforms/arch:x86_64": [
164 ":native_shared_lib_1",
165 ":native_shared_lib_2",
166 ],
167 "//conditions:default": [],
168 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500169 "prebuilts": `[
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400170 ":pretend_prebuilt_1",
171 ":pretend_prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500172 ]`,
Wei Lif034cb42022-01-19 15:54:31 -0800173 "updatable": "False",
174 "compressible": "False",
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000175 "package_name": `"com.android.apogee.test.package"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500176 }),
177 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400178}
179
Wei Li1c66fc72022-05-09 23:59:14 -0700180func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
181 runApexTestCase(t, bp2buildTestCase{
182 description: "apex - file contexts is a module in another Android.bp",
183 moduleTypeUnderTest: "apex",
184 moduleTypeUnderTestFactory: apex.BundleFactory,
185 filesystem: map[string]string{
186 "a/b/Android.bp": `
187filegroup {
188 name: "com.android.apogee-file_contexts",
189 srcs: [
190 "com.android.apogee-file_contexts",
191 ],
192 bazel_module: { bp2build_available: false },
193}
194`,
195 },
196 blueprint: `
197apex {
198 name: "com.android.apogee",
199 file_contexts: ":com.android.apogee-file_contexts",
200}
201`,
202 expectedBazelTargets: []string{
203 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
204 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700205 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700206 }),
207 }})
208}
209
210func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
211 runApexTestCase(t, bp2buildTestCase{
212 description: "apex - file contexts is a file",
213 moduleTypeUnderTest: "apex",
214 moduleTypeUnderTestFactory: apex.BundleFactory,
215 filesystem: map[string]string{},
216 blueprint: `
217apex {
218 name: "com.android.apogee",
219 file_contexts: "file_contexts_file",
220}
221`,
222 expectedBazelTargets: []string{
223 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
224 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700225 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700226 }),
227 }})
228}
229
230func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
231 runApexTestCase(t, bp2buildTestCase{
232 description: "apex - file contexts is not specified",
233 moduleTypeUnderTest: "apex",
234 moduleTypeUnderTestFactory: apex.BundleFactory,
235 filesystem: map[string]string{
236 "system/sepolicy/apex/Android.bp": `
237filegroup {
238 name: "com.android.apogee-file_contexts",
239 srcs: [
240 "com.android.apogee-file_contexts",
241 ],
242 bazel_module: { bp2build_available: false },
243}
244`,
245 },
246 blueprint: `
247apex {
248 name: "com.android.apogee",
249}
250`,
251 expectedBazelTargets: []string{
252 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
253 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700254 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700255 }),
256 }})
257}
258
Yu Liu4ae55d12022-01-05 17:17:23 -0800259func TestApexBundleCompileMultilibBoth(t *testing.T) {
260 runApexTestCase(t, bp2buildTestCase{
261 description: "apex - example with compile_multilib=both",
262 moduleTypeUnderTest: "apex",
263 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700264 filesystem: map[string]string{
265 "system/sepolicy/apex/Android.bp": `
266filegroup {
267 name: "com.android.apogee-file_contexts",
268 srcs: [ "apogee-file_contexts", ],
269 bazel_module: { bp2build_available: false },
270}
271`,
272 },
273 blueprint: createMultilibBlueprint("both"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800274 expectedBazelTargets: []string{
275 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
276 "native_shared_libs_32": `[
277 ":native_shared_lib_1",
278 ":native_shared_lib_3",
279 ] + select({
280 "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
281 "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
282 "//conditions:default": [],
283 })`,
284 "native_shared_libs_64": `select({
285 "//build/bazel/platforms/arch:arm64": [
286 ":native_shared_lib_1",
287 ":native_shared_lib_4",
288 ":native_shared_lib_2",
289 ],
290 "//build/bazel/platforms/arch:x86_64": [
291 ":native_shared_lib_1",
292 ":native_shared_lib_4",
293 ":native_shared_lib_2",
294 ],
295 "//conditions:default": [],
296 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700297 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700298 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800299 }),
300 }})
301}
302
303func TestApexBundleCompileMultilibFirst(t *testing.T) {
304 runApexTestCase(t, bp2buildTestCase{
305 description: "apex - example with compile_multilib=first",
306 moduleTypeUnderTest: "apex",
307 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700308 filesystem: map[string]string{
309 "system/sepolicy/apex/Android.bp": `
310filegroup {
311 name: "com.android.apogee-file_contexts",
312 srcs: [ "apogee-file_contexts", ],
313 bazel_module: { bp2build_available: false },
314}
315`,
316 },
317 blueprint: createMultilibBlueprint("first"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800318 expectedBazelTargets: []string{
319 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
320 "native_shared_libs_32": `select({
321 "//build/bazel/platforms/arch:arm": [
322 ":native_shared_lib_1",
323 ":native_shared_lib_3",
324 ":native_shared_lib_2",
325 ],
326 "//build/bazel/platforms/arch:x86": [
327 ":native_shared_lib_1",
328 ":native_shared_lib_3",
329 ":native_shared_lib_2",
330 ],
331 "//conditions:default": [],
332 })`,
333 "native_shared_libs_64": `select({
334 "//build/bazel/platforms/arch:arm64": [
335 ":native_shared_lib_1",
336 ":native_shared_lib_4",
337 ":native_shared_lib_2",
338 ],
339 "//build/bazel/platforms/arch:x86_64": [
340 ":native_shared_lib_1",
341 ":native_shared_lib_4",
342 ":native_shared_lib_2",
343 ],
344 "//conditions:default": [],
345 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700346 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700347 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800348 }),
349 }})
350}
351
352func TestApexBundleCompileMultilib32(t *testing.T) {
353 runApexTestCase(t, bp2buildTestCase{
354 description: "apex - example with compile_multilib=32",
355 moduleTypeUnderTest: "apex",
356 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700357 filesystem: map[string]string{
358 "system/sepolicy/apex/Android.bp": `
359filegroup {
360 name: "com.android.apogee-file_contexts",
361 srcs: [ "apogee-file_contexts", ],
362 bazel_module: { bp2build_available: false },
363}
364`,
365 },
366 blueprint: createMultilibBlueprint("32"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800367 expectedBazelTargets: []string{
368 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
369 "native_shared_libs_32": `[
370 ":native_shared_lib_1",
371 ":native_shared_lib_3",
372 ] + select({
373 "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
374 "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
375 "//conditions:default": [],
376 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700377 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700378 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800379 }),
380 }})
381}
382
383func TestApexBundleCompileMultilib64(t *testing.T) {
384 runApexTestCase(t, bp2buildTestCase{
385 description: "apex - example with compile_multilib=64",
386 moduleTypeUnderTest: "apex",
387 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700388 filesystem: map[string]string{
389 "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 },
397 blueprint: createMultilibBlueprint("64"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800398 expectedBazelTargets: []string{
399 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
400 "native_shared_libs_64": `select({
401 "//build/bazel/platforms/arch:arm64": [
402 ":native_shared_lib_1",
403 ":native_shared_lib_4",
404 ":native_shared_lib_2",
405 ],
406 "//build/bazel/platforms/arch:x86_64": [
407 ":native_shared_lib_1",
408 ":native_shared_lib_4",
409 ":native_shared_lib_2",
410 ],
411 "//conditions:default": [],
412 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700413 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700414 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800415 }),
416 }})
417}
418
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400419func TestApexBundleDefaultPropertyValues(t *testing.T) {
420 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400421 description: "apex - default property values",
422 moduleTypeUnderTest: "apex",
423 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700424 filesystem: map[string]string{
425 "system/sepolicy/apex/Android.bp": `
426filegroup {
427 name: "com.android.apogee-file_contexts",
428 srcs: [ "apogee-file_contexts", ],
429 bazel_module: { bp2build_available: false },
430}
431`,
432 },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400433 blueprint: `
434apex {
435 name: "com.android.apogee",
436 manifest: "apogee_manifest.json",
437}
438`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500439 expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700440 "manifest": `"apogee_manifest.json"`,
441 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500442 }),
443 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400444}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000445
446func TestApexBundleHasBazelModuleProps(t *testing.T) {
447 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400448 description: "apex - has bazel module props",
449 moduleTypeUnderTest: "apex",
450 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700451 filesystem: map[string]string{
452 "system/sepolicy/apex/Android.bp": `
453filegroup {
454 name: "apogee-file_contexts",
455 srcs: [ "apogee-file_contexts", ],
456 bazel_module: { bp2build_available: false },
457}
458`,
459 },
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000460 blueprint: `
461apex {
462 name: "apogee",
463 manifest: "manifest.json",
464 bazel_module: { bp2build_available: true },
465}
466`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500467 expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700468 "manifest": `"manifest.json"`,
469 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500470 }),
471 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000472}
Yu Liu4ae55d12022-01-05 17:17:23 -0800473
474func createMultilibBlueprint(compile_multilib string) string {
475 return `
476cc_library {
477 name: "native_shared_lib_1",
478 bazel_module: { bp2build_available: false },
479}
480
481cc_library {
482 name: "native_shared_lib_2",
483 bazel_module: { bp2build_available: false },
484}
485
486cc_library {
487 name: "native_shared_lib_3",
488 bazel_module: { bp2build_available: false },
489}
490
491cc_library {
492 name: "native_shared_lib_4",
493 bazel_module: { bp2build_available: false },
494}
495
496apex {
497 name: "com.android.apogee",
498 compile_multilib: "` + compile_multilib + `",
499 multilib: {
500 both: {
501 native_shared_libs: [
502 "native_shared_lib_1",
503 ],
504 },
505 first: {
506 native_shared_libs: [
507 "native_shared_lib_2",
508 ],
509 },
510 lib32: {
511 native_shared_libs: [
512 "native_shared_lib_3",
513 ],
514 },
515 lib64: {
516 native_shared_libs: [
517 "native_shared_lib_4",
518 ],
519 },
520 },
521}`
522}
Wei Li1c66fc72022-05-09 23:59:14 -0700523
524func TestBp2BuildOverrideApex(t *testing.T) {
525 runOverrideApexTestCase(t, bp2buildTestCase{
526 description: "override_apex",
527 moduleTypeUnderTest: "override_apex",
528 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
529 filesystem: map[string]string{},
530 blueprint: `
531apex_key {
532 name: "com.android.apogee.key",
533 public_key: "com.android.apogee.avbpubkey",
534 private_key: "com.android.apogee.pem",
535 bazel_module: { bp2build_available: false },
536}
537
538android_app_certificate {
539 name: "com.android.apogee.certificate",
540 certificate: "com.android.apogee",
541 bazel_module: { bp2build_available: false },
542}
543
544cc_library {
545 name: "native_shared_lib_1",
546 bazel_module: { bp2build_available: false },
547}
548
549cc_library {
550 name: "native_shared_lib_2",
551 bazel_module: { bp2build_available: false },
552}
553
554cc_library {
555 name: "pretend_prebuilt_1",
556 bazel_module: { bp2build_available: false },
557}
558
559cc_library {
560 name: "pretend_prebuilt_2",
561 bazel_module: { bp2build_available: false },
562}
563
564filegroup {
565 name: "com.android.apogee-file_contexts",
566 srcs: [
567 "com.android.apogee-file_contexts",
568 ],
569 bazel_module: { bp2build_available: false },
570}
571
572cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
573sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
574
575apex {
576 name: "com.android.apogee",
577 manifest: "apogee_manifest.json",
578 androidManifest: "ApogeeAndroidManifest.xml",
579 file_contexts: ":com.android.apogee-file_contexts",
580 min_sdk_version: "29",
581 key: "com.android.apogee.key",
582 certificate: "com.android.apogee.certificate",
583 updatable: false,
584 installable: false,
585 compressible: false,
586 native_shared_libs: [
587 "native_shared_lib_1",
588 "native_shared_lib_2",
589 ],
590 binaries: [
591 "cc_binary_1",
592 "sh_binary_2",
593 ],
594 prebuilts: [
595 "pretend_prebuilt_1",
596 "pretend_prebuilt_2",
597 ],
598 bazel_module: { bp2build_available: false },
599}
600
601apex_key {
602 name: "com.google.android.apogee.key",
603 public_key: "com.google.android.apogee.avbpubkey",
604 private_key: "com.google.android.apogee.pem",
605 bazel_module: { bp2build_available: false },
606}
607
608android_app_certificate {
609 name: "com.google.android.apogee.certificate",
610 certificate: "com.google.android.apogee",
611 bazel_module: { bp2build_available: false },
612}
613
614override_apex {
615 name: "com.google.android.apogee",
616 base: ":com.android.apogee",
617 key: "com.google.android.apogee.key",
618 certificate: "com.google.android.apogee.certificate",
619 prebuilts: [],
620 compressible: true,
621}
622`,
623 expectedBazelTargets: []string{
624 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
625 "android_manifest": `"ApogeeAndroidManifest.xml"`,
626 "binaries": `[
627 ":cc_binary_1",
628 ":sh_binary_2",
629 ]`,
630 "certificate": `":com.google.android.apogee.certificate"`,
631 "file_contexts": `":com.android.apogee-file_contexts"`,
632 "installable": "False",
633 "key": `":com.google.android.apogee.key"`,
634 "manifest": `"apogee_manifest.json"`,
635 "min_sdk_version": `"29"`,
636 "native_shared_libs_32": `[
637 ":native_shared_lib_1",
638 ":native_shared_lib_2",
639 ]`,
640 "native_shared_libs_64": `select({
641 "//build/bazel/platforms/arch:arm64": [
642 ":native_shared_lib_1",
643 ":native_shared_lib_2",
644 ],
645 "//build/bazel/platforms/arch:x86_64": [
646 ":native_shared_lib_1",
647 ":native_shared_lib_2",
648 ],
649 "//conditions:default": [],
650 })`,
651 "prebuilts": `[]`,
652 "updatable": "False",
653 "compressible": "True",
654 }),
655 }})
656}
Wei Li40f98732022-05-20 22:08:11 -0700657
658func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
659 runOverrideApexTestCase(t, bp2buildTestCase{
660 description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
661 moduleTypeUnderTest: "override_apex",
662 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
663 filesystem: map[string]string{
664 "system/sepolicy/apex/Android.bp": `
665filegroup {
666 name: "com.android.apogee-file_contexts",
667 srcs: [ "apogee-file_contexts", ],
668 bazel_module: { bp2build_available: false },
669}`,
670 "a/b/Android.bp": `
671apex {
672 name: "com.android.apogee",
673 bazel_module: { bp2build_available: false },
674}
675`,
676 },
677 blueprint: `
678override_apex {
679 name: "com.google.android.apogee",
680 base: ":com.android.apogee",
681}
682`,
683 expectedBazelTargets: []string{
684 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
685 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
686 "manifest": `"//a/b:apex_manifest.json"`,
687 }),
688 }})
689}
690
691func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
692 runOverrideApexTestCase(t, bp2buildTestCase{
693 description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
694 moduleTypeUnderTest: "override_apex",
695 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
696 filesystem: map[string]string{
697 "system/sepolicy/apex/Android.bp": `
698filegroup {
699 name: "com.android.apogee-file_contexts",
700 srcs: [ "apogee-file_contexts", ],
701 bazel_module: { bp2build_available: false },
702}`,
703 "a/b/Android.bp": `
704apex {
705 name: "com.android.apogee",
706 manifest: "apogee_manifest.json",
707 bazel_module: { bp2build_available: false },
708}
709`,
710 },
711 blueprint: `
712override_apex {
713 name: "com.google.android.apogee",
714 base: ":com.android.apogee",
715}
716`,
717 expectedBazelTargets: []string{
718 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
719 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
720 "manifest": `"//a/b:apogee_manifest.json"`,
721 }),
722 }})
723}
724
725func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
726 runOverrideApexTestCase(t, bp2buildTestCase{
727 description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
728 moduleTypeUnderTest: "override_apex",
729 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
730 filesystem: map[string]string{
731 "system/sepolicy/apex/Android.bp": `
732filegroup {
733 name: "com.android.apogee-file_contexts",
734 srcs: [ "apogee-file_contexts", ],
735 bazel_module: { bp2build_available: false },
736}`,
737 },
738 blueprint: `
739apex {
740 name: "com.android.apogee",
741 bazel_module: { bp2build_available: false },
742}
743
744override_apex {
745 name: "com.google.android.apogee",
746 base: ":com.android.apogee",
747}
748`,
749 expectedBazelTargets: []string{
750 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
751 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
752 "manifest": `"apex_manifest.json"`,
753 }),
754 }})
755}
756
757func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
758 runOverrideApexTestCase(t, bp2buildTestCase{
759 description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
760 moduleTypeUnderTest: "override_apex",
761 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
762 filesystem: map[string]string{
763 "system/sepolicy/apex/Android.bp": `
764filegroup {
765 name: "com.android.apogee-file_contexts",
766 srcs: [ "apogee-file_contexts", ],
767 bazel_module: { bp2build_available: false },
768}`,
769 },
770 blueprint: `
771apex {
772 name: "com.android.apogee",
773 manifest: "apogee_manifest.json",
774 bazel_module: { bp2build_available: false },
775}
776
777override_apex {
778 name: "com.google.android.apogee",
779 base: ":com.android.apogee",
780}
781`,
782 expectedBazelTargets: []string{
783 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
784 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
785 "manifest": `"apogee_manifest.json"`,
786 }),
787 }})
788}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000789
790func TestApexBundleSimple_packageNameOverride(t *testing.T) {
791 runOverrideApexTestCase(t, bp2buildTestCase{
792 description: "override_apex - override package name",
793 moduleTypeUnderTest: "override_apex",
794 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
795 filesystem: map[string]string{
796 "system/sepolicy/apex/Android.bp": `
797filegroup {
798 name: "com.android.apogee-file_contexts",
799 srcs: [ "apogee-file_contexts", ],
800 bazel_module: { bp2build_available: false },
801}`,
802 },
803 blueprint: `
804apex {
805 name: "com.android.apogee",
806 bazel_module: { bp2build_available: false },
807}
808
809override_apex {
810 name: "com.google.android.apogee",
811 base: ":com.android.apogee",
812 package_name: "com.google.android.apogee",
813}
814`,
815 expectedBazelTargets: []string{
816 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
817 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
818 "manifest": `"apex_manifest.json"`,
819 "package_name": `"com.google.android.apogee"`,
820 }),
821 }})
822}
Jingwen Chendf165c92022-06-08 16:00:39 +0000823
824func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) {
825 runOverrideApexTestCase(t, bp2buildTestCase{
826 description: "override_apex - no override",
827 moduleTypeUnderTest: "override_apex",
828 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
829 filesystem: map[string]string{
830 "system/sepolicy/apex/Android.bp": `
831filegroup {
832 name: "com.android.apogee-file_contexts",
833 srcs: [ "apogee-file_contexts", ],
834 bazel_module: { bp2build_available: false },
835}`,
836 },
837 blueprint: `
838prebuilt_etc {
839 name: "prebuilt_file",
840 bazel_module: { bp2build_available: false },
841}
842
843apex {
844 name: "com.android.apogee",
845 bazel_module: { bp2build_available: false },
846 prebuilts: ["prebuilt_file"]
847}
848
849override_apex {
850 name: "com.google.android.apogee",
851 base: ":com.android.apogee",
852}
853`,
854 expectedBazelTargets: []string{
855 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
856 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
857 "manifest": `"apex_manifest.json"`,
858 "prebuilts": `[":prebuilt_file"]`,
859 }),
860 }})
861}
862
863func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) {
864 runOverrideApexTestCase(t, bp2buildTestCase{
865 description: "override_apex - ooverride",
866 moduleTypeUnderTest: "override_apex",
867 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
868 filesystem: map[string]string{
869 "system/sepolicy/apex/Android.bp": `
870filegroup {
871 name: "com.android.apogee-file_contexts",
872 srcs: [ "apogee-file_contexts", ],
873 bazel_module: { bp2build_available: false },
874}`,
875 },
876 blueprint: `
877prebuilt_etc {
878 name: "prebuilt_file",
879 bazel_module: { bp2build_available: false },
880}
881
882prebuilt_etc {
883 name: "prebuilt_file2",
884 bazel_module: { bp2build_available: false },
885}
886
887apex {
888 name: "com.android.apogee",
889 bazel_module: { bp2build_available: false },
890 prebuilts: ["prebuilt_file"]
891}
892
893override_apex {
894 name: "com.google.android.apogee",
895 base: ":com.android.apogee",
896 prebuilts: ["prebuilt_file2"]
897}
898`,
899 expectedBazelTargets: []string{
900 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
901 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
902 "manifest": `"apex_manifest.json"`,
903 "prebuilts": `[":prebuilt_file2"]`,
904 }),
905 }})
906}
907
908func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) {
909 runOverrideApexTestCase(t, bp2buildTestCase{
910 description: "override_apex - override with empty list",
911 moduleTypeUnderTest: "override_apex",
912 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
913 filesystem: map[string]string{
914 "system/sepolicy/apex/Android.bp": `
915filegroup {
916 name: "com.android.apogee-file_contexts",
917 srcs: [ "apogee-file_contexts", ],
918 bazel_module: { bp2build_available: false },
919}`,
920 },
921 blueprint: `
922prebuilt_etc {
923 name: "prebuilt_file",
924 bazel_module: { bp2build_available: false },
925}
926
927apex {
928 name: "com.android.apogee",
929 bazel_module: { bp2build_available: false },
930 prebuilts: ["prebuilt_file"]
931}
932
933override_apex {
934 name: "com.google.android.apogee",
935 base: ":com.android.apogee",
936 prebuilts: [],
937}
938`,
939 expectedBazelTargets: []string{
940 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
941 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
942 "manifest": `"apex_manifest.json"`,
943 "prebuilts": `[]`,
944 }),
945 }})
946}