blob: 3f1349f1150ebc6041d149f8be858459e890f388 [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 ],
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000136 package_name: "com.android.apogee.test.package",
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400137}
138`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500139 expectedBazelTargets: []string{
140 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
141 "android_manifest": `"ApogeeAndroidManifest.xml"`,
142 "binaries": `[
Jingwen Chenb07c9012021-12-08 10:05:45 +0000143 ":cc_binary_1",
144 ":sh_binary_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500145 ]`,
146 "certificate": `":com.android.apogee.certificate"`,
147 "file_contexts": `":com.android.apogee-file_contexts"`,
148 "installable": "False",
149 "key": `":com.android.apogee.key"`,
150 "manifest": `"apogee_manifest.json"`,
151 "min_sdk_version": `"29"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800152 "native_shared_libs_32": `[
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400153 ":native_shared_lib_1",
154 ":native_shared_lib_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500155 ]`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800156 "native_shared_libs_64": `select({
157 "//build/bazel/platforms/arch:arm64": [
158 ":native_shared_lib_1",
159 ":native_shared_lib_2",
160 ],
161 "//build/bazel/platforms/arch:x86_64": [
162 ":native_shared_lib_1",
163 ":native_shared_lib_2",
164 ],
165 "//conditions:default": [],
166 })`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500167 "prebuilts": `[
Rupert Shuttleworth9447e1e2021-07-28 05:53:42 -0400168 ":pretend_prebuilt_1",
169 ":pretend_prebuilt_2",
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500170 ]`,
Wei Lif034cb42022-01-19 15:54:31 -0800171 "updatable": "False",
172 "compressible": "False",
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000173 "package_name": `"com.android.apogee.test.package"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500174 }),
175 }})
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400176}
177
Wei Li1c66fc72022-05-09 23:59:14 -0700178func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) {
179 runApexTestCase(t, bp2buildTestCase{
180 description: "apex - file contexts is a module in another Android.bp",
181 moduleTypeUnderTest: "apex",
182 moduleTypeUnderTestFactory: apex.BundleFactory,
183 filesystem: map[string]string{
184 "a/b/Android.bp": `
185filegroup {
186 name: "com.android.apogee-file_contexts",
187 srcs: [
188 "com.android.apogee-file_contexts",
189 ],
190 bazel_module: { bp2build_available: false },
191}
192`,
193 },
194 blueprint: `
195apex {
196 name: "com.android.apogee",
197 file_contexts: ":com.android.apogee-file_contexts",
198}
199`,
200 expectedBazelTargets: []string{
201 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
202 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700203 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700204 }),
205 }})
206}
207
208func TestApexBundleSimple_fileContextsIsFile(t *testing.T) {
209 runApexTestCase(t, bp2buildTestCase{
210 description: "apex - file contexts is a file",
211 moduleTypeUnderTest: "apex",
212 moduleTypeUnderTestFactory: apex.BundleFactory,
213 filesystem: map[string]string{},
214 blueprint: `
215apex {
216 name: "com.android.apogee",
217 file_contexts: "file_contexts_file",
218}
219`,
220 expectedBazelTargets: []string{
221 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
222 "file_contexts": `"file_contexts_file"`,
Wei Li40f98732022-05-20 22:08:11 -0700223 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700224 }),
225 }})
226}
227
228func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) {
229 runApexTestCase(t, bp2buildTestCase{
230 description: "apex - file contexts is not specified",
231 moduleTypeUnderTest: "apex",
232 moduleTypeUnderTestFactory: apex.BundleFactory,
233 filesystem: map[string]string{
234 "system/sepolicy/apex/Android.bp": `
235filegroup {
236 name: "com.android.apogee-file_contexts",
237 srcs: [
238 "com.android.apogee-file_contexts",
239 ],
240 bazel_module: { bp2build_available: false },
241}
242`,
243 },
244 blueprint: `
245apex {
246 name: "com.android.apogee",
247}
248`,
249 expectedBazelTargets: []string{
250 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
251 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700252 "manifest": `"apex_manifest.json"`,
Wei Li1c66fc72022-05-09 23:59:14 -0700253 }),
254 }})
255}
256
Yu Liu4ae55d12022-01-05 17:17:23 -0800257func TestApexBundleCompileMultilibBoth(t *testing.T) {
258 runApexTestCase(t, bp2buildTestCase{
259 description: "apex - example with compile_multilib=both",
260 moduleTypeUnderTest: "apex",
261 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700262 filesystem: map[string]string{
263 "system/sepolicy/apex/Android.bp": `
264filegroup {
265 name: "com.android.apogee-file_contexts",
266 srcs: [ "apogee-file_contexts", ],
267 bazel_module: { bp2build_available: false },
268}
269`,
270 },
271 blueprint: createMultilibBlueprint("both"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800272 expectedBazelTargets: []string{
273 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
274 "native_shared_libs_32": `[
275 ":native_shared_lib_1",
276 ":native_shared_lib_3",
277 ] + select({
278 "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
279 "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
280 "//conditions:default": [],
281 })`,
282 "native_shared_libs_64": `select({
283 "//build/bazel/platforms/arch:arm64": [
284 ":native_shared_lib_1",
285 ":native_shared_lib_4",
286 ":native_shared_lib_2",
287 ],
288 "//build/bazel/platforms/arch:x86_64": [
289 ":native_shared_lib_1",
290 ":native_shared_lib_4",
291 ":native_shared_lib_2",
292 ],
293 "//conditions:default": [],
294 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700295 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700296 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800297 }),
298 }})
299}
300
301func TestApexBundleCompileMultilibFirst(t *testing.T) {
302 runApexTestCase(t, bp2buildTestCase{
303 description: "apex - example with compile_multilib=first",
304 moduleTypeUnderTest: "apex",
305 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700306 filesystem: map[string]string{
307 "system/sepolicy/apex/Android.bp": `
308filegroup {
309 name: "com.android.apogee-file_contexts",
310 srcs: [ "apogee-file_contexts", ],
311 bazel_module: { bp2build_available: false },
312}
313`,
314 },
315 blueprint: createMultilibBlueprint("first"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800316 expectedBazelTargets: []string{
317 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
318 "native_shared_libs_32": `select({
319 "//build/bazel/platforms/arch:arm": [
320 ":native_shared_lib_1",
321 ":native_shared_lib_3",
322 ":native_shared_lib_2",
323 ],
324 "//build/bazel/platforms/arch:x86": [
325 ":native_shared_lib_1",
326 ":native_shared_lib_3",
327 ":native_shared_lib_2",
328 ],
329 "//conditions:default": [],
330 })`,
331 "native_shared_libs_64": `select({
332 "//build/bazel/platforms/arch:arm64": [
333 ":native_shared_lib_1",
334 ":native_shared_lib_4",
335 ":native_shared_lib_2",
336 ],
337 "//build/bazel/platforms/arch:x86_64": [
338 ":native_shared_lib_1",
339 ":native_shared_lib_4",
340 ":native_shared_lib_2",
341 ],
342 "//conditions:default": [],
343 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700344 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700345 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800346 }),
347 }})
348}
349
350func TestApexBundleCompileMultilib32(t *testing.T) {
351 runApexTestCase(t, bp2buildTestCase{
352 description: "apex - example with compile_multilib=32",
353 moduleTypeUnderTest: "apex",
354 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700355 filesystem: map[string]string{
356 "system/sepolicy/apex/Android.bp": `
357filegroup {
358 name: "com.android.apogee-file_contexts",
359 srcs: [ "apogee-file_contexts", ],
360 bazel_module: { bp2build_available: false },
361}
362`,
363 },
364 blueprint: createMultilibBlueprint("32"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800365 expectedBazelTargets: []string{
366 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
367 "native_shared_libs_32": `[
368 ":native_shared_lib_1",
369 ":native_shared_lib_3",
370 ] + select({
371 "//build/bazel/platforms/arch:arm": [":native_shared_lib_2"],
372 "//build/bazel/platforms/arch:x86": [":native_shared_lib_2"],
373 "//conditions:default": [],
374 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700375 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700376 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800377 }),
378 }})
379}
380
381func TestApexBundleCompileMultilib64(t *testing.T) {
382 runApexTestCase(t, bp2buildTestCase{
383 description: "apex - example with compile_multilib=64",
384 moduleTypeUnderTest: "apex",
385 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700386 filesystem: map[string]string{
387 "system/sepolicy/apex/Android.bp": `
388filegroup {
389 name: "com.android.apogee-file_contexts",
390 srcs: [ "apogee-file_contexts", ],
391 bazel_module: { bp2build_available: false },
392}
393`,
394 },
395 blueprint: createMultilibBlueprint("64"),
Yu Liu4ae55d12022-01-05 17:17:23 -0800396 expectedBazelTargets: []string{
397 makeBazelTarget("apex", "com.android.apogee", attrNameToString{
398 "native_shared_libs_64": `select({
399 "//build/bazel/platforms/arch:arm64": [
400 ":native_shared_lib_1",
401 ":native_shared_lib_4",
402 ":native_shared_lib_2",
403 ],
404 "//build/bazel/platforms/arch:x86_64": [
405 ":native_shared_lib_1",
406 ":native_shared_lib_4",
407 ":native_shared_lib_2",
408 ],
409 "//conditions:default": [],
410 })`,
Wei Li1c66fc72022-05-09 23:59:14 -0700411 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Wei Li40f98732022-05-20 22:08:11 -0700412 "manifest": `"apex_manifest.json"`,
Yu Liu4ae55d12022-01-05 17:17:23 -0800413 }),
414 }})
415}
416
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400417func TestApexBundleDefaultPropertyValues(t *testing.T) {
418 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400419 description: "apex - default property values",
420 moduleTypeUnderTest: "apex",
421 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700422 filesystem: map[string]string{
423 "system/sepolicy/apex/Android.bp": `
424filegroup {
425 name: "com.android.apogee-file_contexts",
426 srcs: [ "apogee-file_contexts", ],
427 bazel_module: { bp2build_available: false },
428}
429`,
430 },
Rupert Shuttleworth6e4950a2021-07-27 01:34:59 -0400431 blueprint: `
432apex {
433 name: "com.android.apogee",
434 manifest: "apogee_manifest.json",
435}
436`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500437 expectedBazelTargets: []string{makeBazelTarget("apex", "com.android.apogee", attrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700438 "manifest": `"apogee_manifest.json"`,
439 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500440 }),
441 }})
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400442}
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000443
444func TestApexBundleHasBazelModuleProps(t *testing.T) {
445 runApexTestCase(t, bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -0400446 description: "apex - has bazel module props",
447 moduleTypeUnderTest: "apex",
448 moduleTypeUnderTestFactory: apex.BundleFactory,
Wei Li1c66fc72022-05-09 23:59:14 -0700449 filesystem: map[string]string{
450 "system/sepolicy/apex/Android.bp": `
451filegroup {
452 name: "apogee-file_contexts",
453 srcs: [ "apogee-file_contexts", ],
454 bazel_module: { bp2build_available: false },
455}
456`,
457 },
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000458 blueprint: `
459apex {
460 name: "apogee",
461 manifest: "manifest.json",
462 bazel_module: { bp2build_available: true },
463}
464`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500465 expectedBazelTargets: []string{makeBazelTarget("apex", "apogee", attrNameToString{
Wei Li1c66fc72022-05-09 23:59:14 -0700466 "manifest": `"manifest.json"`,
467 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -0500468 }),
469 }})
Jingwen Chenf59a8e12021-07-16 09:28:53 +0000470}
Yu Liu4ae55d12022-01-05 17:17:23 -0800471
472func createMultilibBlueprint(compile_multilib string) string {
473 return `
474cc_library {
475 name: "native_shared_lib_1",
476 bazel_module: { bp2build_available: false },
477}
478
479cc_library {
480 name: "native_shared_lib_2",
481 bazel_module: { bp2build_available: false },
482}
483
484cc_library {
485 name: "native_shared_lib_3",
486 bazel_module: { bp2build_available: false },
487}
488
489cc_library {
490 name: "native_shared_lib_4",
491 bazel_module: { bp2build_available: false },
492}
493
494apex {
495 name: "com.android.apogee",
496 compile_multilib: "` + compile_multilib + `",
497 multilib: {
498 both: {
499 native_shared_libs: [
500 "native_shared_lib_1",
501 ],
502 },
503 first: {
504 native_shared_libs: [
505 "native_shared_lib_2",
506 ],
507 },
508 lib32: {
509 native_shared_libs: [
510 "native_shared_lib_3",
511 ],
512 },
513 lib64: {
514 native_shared_libs: [
515 "native_shared_lib_4",
516 ],
517 },
518 },
519}`
520}
Wei Li1c66fc72022-05-09 23:59:14 -0700521
522func TestBp2BuildOverrideApex(t *testing.T) {
523 runOverrideApexTestCase(t, bp2buildTestCase{
524 description: "override_apex",
525 moduleTypeUnderTest: "override_apex",
526 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
527 filesystem: map[string]string{},
528 blueprint: `
529apex_key {
530 name: "com.android.apogee.key",
531 public_key: "com.android.apogee.avbpubkey",
532 private_key: "com.android.apogee.pem",
533 bazel_module: { bp2build_available: false },
534}
535
536android_app_certificate {
537 name: "com.android.apogee.certificate",
538 certificate: "com.android.apogee",
539 bazel_module: { bp2build_available: false },
540}
541
542cc_library {
543 name: "native_shared_lib_1",
544 bazel_module: { bp2build_available: false },
545}
546
547cc_library {
548 name: "native_shared_lib_2",
549 bazel_module: { bp2build_available: false },
550}
551
552cc_library {
553 name: "pretend_prebuilt_1",
554 bazel_module: { bp2build_available: false },
555}
556
557cc_library {
558 name: "pretend_prebuilt_2",
559 bazel_module: { bp2build_available: false },
560}
561
562filegroup {
563 name: "com.android.apogee-file_contexts",
564 srcs: [
565 "com.android.apogee-file_contexts",
566 ],
567 bazel_module: { bp2build_available: false },
568}
569
570cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } }
571sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } }
572
573apex {
574 name: "com.android.apogee",
575 manifest: "apogee_manifest.json",
576 androidManifest: "ApogeeAndroidManifest.xml",
577 file_contexts: ":com.android.apogee-file_contexts",
578 min_sdk_version: "29",
579 key: "com.android.apogee.key",
580 certificate: "com.android.apogee.certificate",
581 updatable: false,
582 installable: false,
583 compressible: false,
584 native_shared_libs: [
585 "native_shared_lib_1",
586 "native_shared_lib_2",
587 ],
588 binaries: [
589 "cc_binary_1",
590 "sh_binary_2",
591 ],
592 prebuilts: [
593 "pretend_prebuilt_1",
594 "pretend_prebuilt_2",
595 ],
596 bazel_module: { bp2build_available: false },
597}
598
599apex_key {
600 name: "com.google.android.apogee.key",
601 public_key: "com.google.android.apogee.avbpubkey",
602 private_key: "com.google.android.apogee.pem",
603 bazel_module: { bp2build_available: false },
604}
605
606android_app_certificate {
607 name: "com.google.android.apogee.certificate",
608 certificate: "com.google.android.apogee",
609 bazel_module: { bp2build_available: false },
610}
611
612override_apex {
613 name: "com.google.android.apogee",
614 base: ":com.android.apogee",
615 key: "com.google.android.apogee.key",
616 certificate: "com.google.android.apogee.certificate",
617 prebuilts: [],
618 compressible: true,
619}
620`,
621 expectedBazelTargets: []string{
622 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
623 "android_manifest": `"ApogeeAndroidManifest.xml"`,
624 "binaries": `[
625 ":cc_binary_1",
626 ":sh_binary_2",
627 ]`,
628 "certificate": `":com.google.android.apogee.certificate"`,
629 "file_contexts": `":com.android.apogee-file_contexts"`,
630 "installable": "False",
631 "key": `":com.google.android.apogee.key"`,
632 "manifest": `"apogee_manifest.json"`,
633 "min_sdk_version": `"29"`,
634 "native_shared_libs_32": `[
635 ":native_shared_lib_1",
636 ":native_shared_lib_2",
637 ]`,
638 "native_shared_libs_64": `select({
639 "//build/bazel/platforms/arch:arm64": [
640 ":native_shared_lib_1",
641 ":native_shared_lib_2",
642 ],
643 "//build/bazel/platforms/arch:x86_64": [
644 ":native_shared_lib_1",
645 ":native_shared_lib_2",
646 ],
647 "//conditions:default": [],
648 })`,
649 "prebuilts": `[]`,
650 "updatable": "False",
651 "compressible": "True",
652 }),
653 }})
654}
Wei Li40f98732022-05-20 22:08:11 -0700655
656func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
657 runOverrideApexTestCase(t, bp2buildTestCase{
658 description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp",
659 moduleTypeUnderTest: "override_apex",
660 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
661 filesystem: map[string]string{
662 "system/sepolicy/apex/Android.bp": `
663filegroup {
664 name: "com.android.apogee-file_contexts",
665 srcs: [ "apogee-file_contexts", ],
666 bazel_module: { bp2build_available: false },
667}`,
668 "a/b/Android.bp": `
669apex {
670 name: "com.android.apogee",
671 bazel_module: { bp2build_available: false },
672}
673`,
674 },
675 blueprint: `
676override_apex {
677 name: "com.google.android.apogee",
678 base: ":com.android.apogee",
679}
680`,
681 expectedBazelTargets: []string{
682 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
683 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
684 "manifest": `"//a/b:apex_manifest.json"`,
685 }),
686 }})
687}
688
689func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) {
690 runOverrideApexTestCase(t, bp2buildTestCase{
691 description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp",
692 moduleTypeUnderTest: "override_apex",
693 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
694 filesystem: map[string]string{
695 "system/sepolicy/apex/Android.bp": `
696filegroup {
697 name: "com.android.apogee-file_contexts",
698 srcs: [ "apogee-file_contexts", ],
699 bazel_module: { bp2build_available: false },
700}`,
701 "a/b/Android.bp": `
702apex {
703 name: "com.android.apogee",
704 manifest: "apogee_manifest.json",
705 bazel_module: { bp2build_available: false },
706}
707`,
708 },
709 blueprint: `
710override_apex {
711 name: "com.google.android.apogee",
712 base: ":com.android.apogee",
713}
714`,
715 expectedBazelTargets: []string{
716 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
717 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
718 "manifest": `"//a/b:apogee_manifest.json"`,
719 }),
720 }})
721}
722
723func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
724 runOverrideApexTestCase(t, bp2buildTestCase{
725 description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp",
726 moduleTypeUnderTest: "override_apex",
727 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
728 filesystem: map[string]string{
729 "system/sepolicy/apex/Android.bp": `
730filegroup {
731 name: "com.android.apogee-file_contexts",
732 srcs: [ "apogee-file_contexts", ],
733 bazel_module: { bp2build_available: false },
734}`,
735 },
736 blueprint: `
737apex {
738 name: "com.android.apogee",
739 bazel_module: { bp2build_available: false },
740}
741
742override_apex {
743 name: "com.google.android.apogee",
744 base: ":com.android.apogee",
745}
746`,
747 expectedBazelTargets: []string{
748 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
749 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
750 "manifest": `"apex_manifest.json"`,
751 }),
752 }})
753}
754
755func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) {
756 runOverrideApexTestCase(t, bp2buildTestCase{
757 description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp",
758 moduleTypeUnderTest: "override_apex",
759 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
760 filesystem: map[string]string{
761 "system/sepolicy/apex/Android.bp": `
762filegroup {
763 name: "com.android.apogee-file_contexts",
764 srcs: [ "apogee-file_contexts", ],
765 bazel_module: { bp2build_available: false },
766}`,
767 },
768 blueprint: `
769apex {
770 name: "com.android.apogee",
771 manifest: "apogee_manifest.json",
772 bazel_module: { bp2build_available: false },
773}
774
775override_apex {
776 name: "com.google.android.apogee",
777 base: ":com.android.apogee",
778}
779`,
780 expectedBazelTargets: []string{
781 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
782 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
783 "manifest": `"apogee_manifest.json"`,
784 }),
785 }})
786}
Jingwen Chen9b7ebca2022-06-03 09:11:20 +0000787
788func TestApexBundleSimple_packageNameOverride(t *testing.T) {
789 runOverrideApexTestCase(t, bp2buildTestCase{
790 description: "override_apex - override package name",
791 moduleTypeUnderTest: "override_apex",
792 moduleTypeUnderTestFactory: apex.OverrideApexFactory,
793 filesystem: map[string]string{
794 "system/sepolicy/apex/Android.bp": `
795filegroup {
796 name: "com.android.apogee-file_contexts",
797 srcs: [ "apogee-file_contexts", ],
798 bazel_module: { bp2build_available: false },
799}`,
800 },
801 blueprint: `
802apex {
803 name: "com.android.apogee",
804 bazel_module: { bp2build_available: false },
805}
806
807override_apex {
808 name: "com.google.android.apogee",
809 base: ":com.android.apogee",
810 package_name: "com.google.android.apogee",
811}
812`,
813 expectedBazelTargets: []string{
814 makeBazelTarget("apex", "com.google.android.apogee", attrNameToString{
815 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
816 "manifest": `"apex_manifest.json"`,
817 "package_name": `"com.google.android.apogee"`,
818 }),
819 }})
820}