blob: d15dc0cd8cf8b71ac9d6f77f04e5179d1c5d769d [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"
21 "android/soong/java"
Jingwen Chenb07c9012021-12-08 10:05:45 +000022 "android/soong/sh"
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040023
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040024 "testing"
25)
26
27func runApexTestCase(t *testing.T, tc bp2buildTestCase) {
28 t.Helper()
29 runBp2BuildTestCase(t, registerApexModuleTypes, tc)
30}
31
32func registerApexModuleTypes(ctx android.RegistrationContext) {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040033 // CC module types needed as they can be APEX dependencies
34 cc.RegisterCCBuildComponents(ctx)
35
Jingwen Chenb07c9012021-12-08 10:05:45 +000036 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
37 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040038 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
39 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
40 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
41 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040042}
43
Wei Li1c66fc72022-05-09 23:59:14 -070044func runOverrideApexTestCase(t *testing.T, tc bp2buildTestCase) {
45 t.Helper()
46 runBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc)
47}
48
49func registerOverrideApexModuleTypes(ctx android.RegistrationContext) {
50 // CC module types needed as they can be APEX dependencies
51 cc.RegisterCCBuildComponents(ctx)
52
53 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory)
54 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
55 ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
56 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory)
57 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
58 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
59 ctx.RegisterModuleType("apex", apex.BundleFactory)
60}
61
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040062func TestApexBundleSimple(t *testing.T) {
63 runApexTestCase(t, bp2buildTestCase{
Wei Li1c66fc72022-05-09 23:59:14 -070064 description: "apex - example with all props, file_context is a module in same Android.bp",
Liz Kammerbe46fcc2021-11-01 15:32:43 -040065 moduleTypeUnderTest: "apex",
66 moduleTypeUnderTestFactory: apex.BundleFactory,
67 filesystem: map[string]string{},
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -040068 blueprint: `
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040069apex_key {
Jingwen Chenb07c9012021-12-08 10:05:45 +000070 name: "com.android.apogee.key",
71 public_key: "com.android.apogee.avbpubkey",
72 private_key: "com.android.apogee.pem",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040073 bazel_module: { bp2build_available: false },
74}
75
76android_app_certificate {
Jingwen Chenb07c9012021-12-08 10:05:45 +000077 name: "com.android.apogee.certificate",
78 certificate: "com.android.apogee",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040079 bazel_module: { bp2build_available: false },
80}
81
82cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000083 name: "native_shared_lib_1",
84 bazel_module: { bp2build_available: false },
85}
86
87cc_library {
88 name: "native_shared_lib_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -040089 bazel_module: { bp2build_available: false },
90}
91
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040092cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000093 name: "pretend_prebuilt_1",
94 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040095}
96
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -040097cc_library {
Jingwen Chenb07c9012021-12-08 10:05:45 +000098 name: "pretend_prebuilt_2",
99 bazel_module: { bp2build_available: false },
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400100}
101
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400102filegroup {
103 name: "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000104 srcs: [
Wei Li1c66fc72022-05-09 23:59:14 -0700105 "com.android.apogee-file_contexts",
Jingwen Chenb07c9012021-12-08 10:05:45 +0000106 ],
107 bazel_module: { bp2build_available: false },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400108}
109
Jingwen Chenb07c9012021-12-08 10:05:45 +0000110cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
111sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
112
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400113apex {
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400114 name: "com.android.apogee",
115 manifest: "apogee_manifest.json",
116 androidManifest: "ApogeeAndroidManifest.xml",
Wei Li1c66fc72022-05-09 23:59:14 -0700117 file_contexts: ":com.android.apogee-file_contexts",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400118 min_sdk_version: "29",
119 key: "com.android.apogee.key",
120 certificate: "com.android.apogee.certificate",
121 updatable: false,
122 installable: false,
Wei Lif034cb42022-01-19 15:54:31 -0800123 compressible: false,
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400124 native_shared_libs: [
125 "native_shared_lib_1",
126 "native_shared_lib_2",
127 ],
128 binaries: [
Jingwen Chenb07c9012021-12-08 10:05:45 +0000129 "cc_binary_1",
130 "sh_binary_2",
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400131 ],
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400132 prebuilts: [
133 "pretend_prebuilt_1",
134 "pretend_prebuilt_2",
135 ],
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400136}
137`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500138 expectedBazelTargets: []string{
139 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
140 "android_manifest": `"ApogeeAndroidManifest.xml"`,
141 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000142 ":cc_binary_1",
143 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500144 ]`,
145 "certificate": `":com.android.apogee.certificate"`,
146 "file_contexts": `":com.android.apogee-file_contexts"`,
147 "installable": "False",
148 "key": `":com.android.apogee.key"`,
149 "manifest": `"apogee_manifest.json"`,
150 "min_sdk_version": `"29"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800151 "native_shared_libs_32": `[
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400152 ":native_shared_lib_1",
153 ":native_shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500154 ]`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800155 "native_shared_libs_64": `select({
156 "//build/bazel/platforms/arch:arm64": [
157 ":native_shared_lib_1",
158 ":native_shared_lib_2",
159 ],
160 "//build/bazel/platforms/arch:x86_64": [
161 ":native_shared_lib_1",
162 ":native_shared_lib_2",
163 ],
164 "//conditions:default": [],
165 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500166 "prebuilts": `[
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400167 ":pretend_prebuilt_1",
168 ":pretend_prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500169 ]`,
Wei Lif034cb42022-01-19 15:54:31 -0800170 "updatable": "False",
171 "compressible": "False",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500172 }),
173 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400174}
175
Wei Li1c66fc72022-05-09 23:59:14 -0700176func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
177 runApexTestCase(t, bp2buildTestCase{
178 description: "apex - file contexts is a module in another Android.bp",
179 moduleTypeUnderTest: "apex",
180 moduleTypeUnderTestFactory: apex.BundleFactory,
181 filesystem: map[string]string{
182 "a/b/Android.bp": `
183filegroup {
184 name: "com.android.apogee-file_contexts",
185 srcs: [
186 "com.android.apogee-file_contexts",
187 ],
188 bazel_module: { bp2build_available: false },
189}
190`,
191 },
192 blueprint: `
193apex {
194 name: "com.android.apogee",
195 file_contexts: ":com.android.apogee-file_contexts",
196}
197`,
198 expectedBazelTargets: []string{
199 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
200 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700201 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700202 }),
203 }})
204}
205
206func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
207 runApexTestCase(t, bp2buildTestCase{
208 description: "apex - file contexts is a file",
209 moduleTypeUnderTest: "apex",
210 moduleTypeUnderTestFactory: apex.BundleFactory,
211 filesystem: map[string]string{},
212 blueprint: `
213apex {
214 name: "com.android.apogee",
215 file_contexts: "file_contexts_file",
216}
217`,
218 expectedBazelTargets: []string{
219 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
220 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700221 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700222 }),
223 }})
224}
225
226func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
227 runApexTestCase(t, bp2buildTestCase{
228 description: "apex - file contexts is not specified",
229 moduleTypeUnderTest: "apex",
230 moduleTypeUnderTestFactory: apex.BundleFactory,
231 filesystem: map[string]string{
232 "system/sepolicy/apex/Android.bp": `
233filegroup {
234 name: "com.android.apogee-file_contexts",
235 srcs: [
236 "com.android.apogee-file_contexts",
237 ],
238 bazel_module: { bp2build_available: false },
239}
240`,
241 },
242 blueprint: `
243apex {
244 name: "com.android.apogee",
245}
246`,
247 expectedBazelTargets: []string{
248 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
249 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700250 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700251 }),
252 }})
253}
254
Yu Liu4ae55d12022-01-05 17:17:23 -0800255func TestApexBundleCompileMultilibBoth(t *testing.T) {
256 runApexTestCase(t, bp2buildTestCase{
257 description: "apex - example with compile_multilib=both",
258 moduleTypeUnderTest: "apex",
259 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700260 filesystem: map[string]string{
261 "system/sepolicy/apex/Android.bp": `
262filegroup {
263 name: "com.android.apogee-file_contexts",
264 srcs: [ "apogee-file_contexts", ],
265 bazel_module: { bp2build_available: false },
266}
267`,
268 },
269 blueprint: createMultilibBlueprint("both"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800270 expectedBazelTargets: []string{
271 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
272 "native_shared_libs_32": `[
273 ":native_shared_lib_1",
274 ":native_shared_lib_3",
275 ] + select({
276 "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
277 "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
278 "//conditions:default": [],
279 })`,
280 "native_shared_libs_64": `select({
281 "//build/bazel/platforms/arch:arm64": [
282 ":native_shared_lib_1",
283 ":native_shared_lib_4",
284 ":native_shared_lib_2",
285 ],
286 "//build/bazel/platforms/arch:x86_64": [
287 ":native_shared_lib_1",
288 ":native_shared_lib_4",
289 ":native_shared_lib_2",
290 ],
291 "//conditions:default": [],
292 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700293 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700294 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800295 }),
296 }})
297}
298
299func TestApexBundleCompileMultilibFirst(t *testing.T) {
300 runApexTestCase(t, bp2buildTestCase{
301 description: "apex - example with compile_multilib=first",
302 moduleTypeUnderTest: "apex",
303 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700304 filesystem: map[string]string{
305 "system/sepolicy/apex/Android.bp": `
306filegroup {
307 name: "com.android.apogee-file_contexts",
308 srcs: [ "apogee-file_contexts", ],
309 bazel_module: { bp2build_available: false },
310}
311`,
312 },
313 blueprint: createMultilibBlueprint("first"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800314 expectedBazelTargets: []string{
315 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
316 "native_shared_libs_32": `select({
317 "//build/bazel/platforms/arch:arm": [
318 ":native_shared_lib_1",
319 ":native_shared_lib_3",
320 ":native_shared_lib_2",
321 ],
322 "//build/bazel/platforms/arch:x86": [
323 ":native_shared_lib_1",
324 ":native_shared_lib_3",
325 ":native_shared_lib_2",
326 ],
327 "//conditions:default": [],
328 })`,
329 "native_shared_libs_64": `select({
330 "//build/bazel/platforms/arch:arm64": [
331 ":native_shared_lib_1",
332 ":native_shared_lib_4",
333 ":native_shared_lib_2",
334 ],
335 "//build/bazel/platforms/arch:x86_64": [
336 ":native_shared_lib_1",
337 ":native_shared_lib_4",
338 ":native_shared_lib_2",
339 ],
340 "//conditions:default": [],
341 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700342 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700343 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800344 }),
345 }})
346}
347
348func TestApexBundleCompileMultilib32(t *testing.T) {
349 runApexTestCase(t, bp2buildTestCase{
350 description: "apex - example with compile_multilib=32",
351 moduleTypeUnderTest: "apex",
352 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700353 filesystem: map[string]string{
354 "system/sepolicy/apex/Android.bp": `
355filegroup {
356 name: "com.android.apogee-file_contexts",
357 srcs: [ "apogee-file_contexts", ],
358 bazel_module: { bp2build_available: false },
359}
360`,
361 },
362 blueprint: createMultilibBlueprint("32"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800363 expectedBazelTargets: []string{
364 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
365 "native_shared_libs_32": `[
366 ":native_shared_lib_1",
367 ":native_shared_lib_3",
368 ] + select({
369 "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
370 "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
371 "//conditions:default": [],
372 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700373 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700374 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800375 }),
376 }})
377}
378
379func TestApexBundleCompileMultilib64(t *testing.T) {
380 runApexTestCase(t, bp2buildTestCase{
381 description: "apex - example with compile_multilib=64",
382 moduleTypeUnderTest: "apex",
383 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700384 filesystem: map[string]string{
385 "system/sepolicy/apex/Android.bp": `
386filegroup {
387 name: "com.android.apogee-file_contexts",
388 srcs: [ "apogee-file_contexts", ],
389 bazel_module: { bp2build_available: false },
390}
391`,
392 },
393 blueprint: createMultilibBlueprint("64"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800394 expectedBazelTargets: []string{
395 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
396 "native_shared_libs_64": `select({
397 "//build/bazel/platforms/arch:arm64": [
398 ":native_shared_lib_1",
399 ":native_shared_lib_4",
400 ":native_shared_lib_2",
401 ],
402 "//build/bazel/platforms/arch:x86_64": [
403 ":native_shared_lib_1",
404 ":native_shared_lib_4",
405 ":native_shared_lib_2",
406 ],
407 "//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
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400415func TestApexBundleDefaultPropertyValues(t *testing.T) {
416 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400417 description: "apex - default property values",
418 moduleTypeUnderTest: "apex",
419 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700420 filesystem: map[string]string{
421 "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 },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400429 blueprint: `
430apex {
431 name: "com.android.apogee",
432 manifest: "apogee_manifest.json",
433}
434`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500435 expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700436 "manifest": `"apogee_manifest.json"`,
437 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500438 }),
439 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400440}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000441
442func TestApexBundleHasBazelModuleProps(t *testing.T) {
443 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400444 description: "apex - has bazel module props",
445 moduleTypeUnderTest: "apex",
446 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700447 filesystem: map[string]string{
448 "system/sepolicy/apex/Android.bp": `
449filegroup {
450 name: "apogee-file_contexts",
451 srcs: [ "apogee-file_contexts", ],
452 bazel_module: { bp2build_available: false },
453}
454`,
455 },
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000456 blueprint: `
457apex {
458 name: "apogee",
459 manifest: "manifest.json",
460 bazel_module: { bp2build_available: true },
461}
462`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500463 expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700464 "manifest": `"manifest.json"`,
465 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500466 }),
467 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000468}
Yu Liu4ae55d12022-01-05 17:17:23 -0800469
470func createMultilibBlueprint(compile_multilib string) string {
471 return `
472cc_library {
473 name: "native_shared_lib_1",
474 bazel_module: { bp2build_available: false },
475}
476
477cc_library {
478 name: "native_shared_lib_2",
479 bazel_module: { bp2build_available: false },
480}
481
482cc_library {
483 name: "native_shared_lib_3",
484 bazel_module: { bp2build_available: false },
485}
486
487cc_library {
488 name: "native_shared_lib_4",
489 bazel_module: { bp2build_available: false },
490}
491
492apex {
493 name: "com.android.apogee",
494 compile_multilib: "` + compile_multilib + `",
495 multilib: {
496 both: {
497 native_shared_libs: [
498 "native_shared_lib_1",
499 ],
500 },
501 first: {
502 native_shared_libs: [
503 "native_shared_lib_2",
504 ],
505 },
506 lib32: {
507 native_shared_libs: [
508 "native_shared_lib_3",
509 ],
510 },
511 lib64: {
512 native_shared_libs: [
513 "native_shared_lib_4",
514 ],
515 },
516 },
517}`
518}
Wei Li1c66fc72022-05-09 23:59:14 -0700519
520func TestBp2BuildOverrideApex(t *testing.T) {
521 runOverrideApexTestCase(t, bp2buildTestCase{
522 description: "override_apex",
523 moduleTypeUnderTest: "override_apex",
524 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
525 filesystem: map[string]string{},
526 blueprint: `
527apex_key {
528 name: "com.android.apogee.key",
529 public_key: "com.android.apogee.avbpubkey",
530 private_key: "com.android.apogee.pem",
531 bazel_module: { bp2build_available: false },
532}
533
534android_app_certificate {
535 name: "com.android.apogee.certificate",
536 certificate: "com.android.apogee",
537 bazel_module: { bp2build_available: false },
538}
539
540cc_library {
541 name: "native_shared_lib_1",
542 bazel_module: { bp2build_available: false },
543}
544
545cc_library {
546 name: "native_shared_lib_2",
547 bazel_module: { bp2build_available: false },
548}
549
550cc_library {
551 name: "pretend_prebuilt_1",
552 bazel_module: { bp2build_available: false },
553}
554
555cc_library {
556 name: "pretend_prebuilt_2",
557 bazel_module: { bp2build_available: false },
558}
559
560filegroup {
561 name: "com.android.apogee-file_contexts",
562 srcs: [
563 "com.android.apogee-file_contexts",
564 ],
565 bazel_module: { bp2build_available: false },
566}
567
568cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
569sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
570
571apex {
572 name: "com.android.apogee",
573 manifest: "apogee_manifest.json",
574 androidManifest: "ApogeeAndroidManifest.xml",
575 file_contexts: ":com.android.apogee-file_contexts",
576 min_sdk_version: "29",
577 key: "com.android.apogee.key",
578 certificate: "com.android.apogee.certificate",
579 updatable: false,
580 installable: false,
581 compressible: false,
582 native_shared_libs: [
583 "native_shared_lib_1",
584 "native_shared_lib_2",
585 ],
586 binaries: [
587 "cc_binary_1",
588 "sh_binary_2",
589 ],
590 prebuilts: [
591 "pretend_prebuilt_1",
592 "pretend_prebuilt_2",
593 ],
594 bazel_module: { bp2build_available: false },
595}
596
597apex_key {
598 name: "com.google.android.apogee.key",
599 public_key: "com.google.android.apogee.avbpubkey",
600 private_key: "com.google.android.apogee.pem",
601 bazel_module: { bp2build_available: false },
602}
603
604android_app_certificate {
605 name: "com.google.android.apogee.certificate",
606 certificate: "com.google.android.apogee",
607 bazel_module: { bp2build_available: false },
608}
609
610override_apex {
611 name: "com.google.android.apogee",
612 base: ":com.android.apogee",
613 key: "com.google.android.apogee.key",
614 certificate: "com.google.android.apogee.certificate",
615 prebuilts: [],
616 compressible: true,
617}
618`,
619 expectedBazelTargets: []string{
620 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
621 "android_manifest": `"ApogeeAndroidManifest.xml"`,
622 "binaries": `[
623 ":cc_binary_1",
624 ":sh_binary_2",
625 ]`,
626 "certificate": `":com.google.android.apogee.certificate"`,
627 "file_contexts": `":com.android.apogee-file_contexts"`,
628 "installable": "False",
629 "key": `":com.google.android.apogee.key"`,
630 "manifest": `"apogee_manifest.json"`,
631 "min_sdk_version": `"29"`,
632 "native_shared_libs_32": `[
633 ":native_shared_lib_1",
634 ":native_shared_lib_2",
635 ]`,
636 "native_shared_libs_64": `select({
637 "//build/bazel/platforms/arch:arm64": [
638 ":native_shared_lib_1",
639 ":native_shared_lib_2",
640 ],
641 "//build/bazel/platforms/arch:x86_64": [
642 ":native_shared_lib_1",
643 ":native_shared_lib_2",
644 ],
645 "//conditions:default": [],
646 })`,
647 "prebuilts": `[]`,
648 "updatable": "False",
649 "compressible": "True",
650 }),
651 }})
652}
Wei Li40f98732022-05-20 22:08:11 -0700653
654func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
655 runOverrideApexTestCase(t, bp2buildTestCase{
656 description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
657 moduleTypeUnderTest: "override_apex",
658 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
659 filesystem: map[string]string{
660 "system/sepolicy/apex/Android.bp": `
661filegroup {
662 name: "com.android.apogee-file_contexts",
663 srcs: [ "apogee-file_contexts", ],
664 bazel_module: { bp2build_available: false },
665}`,
666 "a/b/Android.bp": `
667apex {
668 name: "com.android.apogee",
669 bazel_module: { bp2build_available: false },
670}
671`,
672 },
673 blueprint: `
674override_apex {
675 name: "com.google.android.apogee",
676 base: ":com.android.apogee",
677}
678`,
679 expectedBazelTargets: []string{
680 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
681 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
682 "manifest": `"//a/b:apex_manifest.json"`,
683 }),
684 }})
685}
686
687func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
688 runOverrideApexTestCase(t, bp2buildTestCase{
689 description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
690 moduleTypeUnderTest: "override_apex",
691 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
692 filesystem: map[string]string{
693 "system/sepolicy/apex/Android.bp": `
694filegroup {
695 name: "com.android.apogee-file_contexts",
696 srcs: [ "apogee-file_contexts", ],
697 bazel_module: { bp2build_available: false },
698}`,
699 "a/b/Android.bp": `
700apex {
701 name: "com.android.apogee",
702 manifest: "apogee_manifest.json",
703 bazel_module: { bp2build_available: false },
704}
705`,
706 },
707 blueprint: `
708override_apex {
709 name: "com.google.android.apogee",
710 base: ":com.android.apogee",
711}
712`,
713 expectedBazelTargets: []string{
714 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
715 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
716 "manifest": `"//a/b:apogee_manifest.json"`,
717 }),
718 }})
719}
720
721func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
722 runOverrideApexTestCase(t, bp2buildTestCase{
723 description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
724 moduleTypeUnderTest: "override_apex",
725 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
726 filesystem: map[string]string{
727 "system/sepolicy/apex/Android.bp": `
728filegroup {
729 name: "com.android.apogee-file_contexts",
730 srcs: [ "apogee-file_contexts", ],
731 bazel_module: { bp2build_available: false },
732}`,
733 },
734 blueprint: `
735apex {
736 name: "com.android.apogee",
737 bazel_module: { bp2build_available: false },
738}
739
740override_apex {
741 name: "com.google.android.apogee",
742 base: ":com.android.apogee",
743}
744`,
745 expectedBazelTargets: []string{
746 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
747 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
748 "manifest": `"apex_manifest.json"`,
749 }),
750 }})
751}
752
753func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
754 runOverrideApexTestCase(t, bp2buildTestCase{
755 description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
756 moduleTypeUnderTest: "override_apex",
757 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
758 filesystem: map[string]string{
759 "system/sepolicy/apex/Android.bp": `
760filegroup {
761 name: "com.android.apogee-file_contexts",
762 srcs: [ "apogee-file_contexts", ],
763 bazel_module: { bp2build_available: false },
764}`,
765 },
766 blueprint: `
767apex {
768 name: "com.android.apogee",
769 manifest: "apogee_manifest.json",
770 bazel_module: { bp2build_available: false },
771}
772
773override_apex {
774 name: "com.google.android.apogee",
775 base: ":com.android.apogee",
776}
777`,
778 expectedBazelTargets: []string{
779 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
780 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
781 "manifest": `"apogee_manifest.json"`,
782 }),
783 }})
784}