1// 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" 20 "android/soong/cc" 21 "android/soong/etc" 22 "android/soong/java" 23 "android/soong/sh" 24 25 "fmt" 26 "testing" 27) 28 29func runApexTestCase(t *testing.T, tc Bp2buildTestCase) { 30 t.Helper() 31 RunBp2BuildTestCase(t, registerApexModuleTypes, tc) 32} 33 34func registerApexModuleTypes(ctx android.RegistrationContext) { 35 // CC module types needed as they can be APEX dependencies 36 cc.RegisterCCBuildComponents(ctx) 37 38 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) 39 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) 40 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) 44 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) 45 ctx.RegisterModuleType("cc_test", cc.TestFactory) 46} 47 48func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) { 49 t.Helper() 50 RunBp2BuildTestCase(t, registerOverrideApexModuleTypes, tc) 51} 52 53func registerOverrideApexModuleTypes(ctx android.RegistrationContext) { 54 // CC module types needed as they can be APEX dependencies 55 cc.RegisterCCBuildComponents(ctx) 56 57 ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) 58 ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) 59 ctx.RegisterModuleType("cc_library", cc.LibraryFactory) 60 ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) 61 ctx.RegisterModuleType("apex_test", apex.TestApexBundleFactory) 62 ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) 63 ctx.RegisterModuleType("filegroup", android.FileGroupFactory) 64 ctx.RegisterModuleType("apex", apex.BundleFactory) 65 ctx.RegisterModuleType("apex_defaults", apex.DefaultsFactory) 66 ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory) 67 ctx.RegisterModuleType("soong_config_module_type", android.SoongConfigModuleTypeFactory) 68 ctx.RegisterModuleType("soong_config_string_variable", android.SoongConfigStringVariableDummyFactory) 69} 70 71func TestApexBundleSimple(t *testing.T) { 72 runApexTestCase(t, Bp2buildTestCase{ 73 Description: "apex - example with all props, file_context is a module in same Android.bp", 74 ModuleTypeUnderTest: "apex", 75 ModuleTypeUnderTestFactory: apex.BundleFactory, 76 Filesystem: map[string]string{}, 77 Blueprint: ` 78apex_key { 79 name: "com.android.apogee.key", 80 public_key: "com.android.apogee.avbpubkey", 81 private_key: "com.android.apogee.pem", 82 bazel_module: { bp2build_available: false }, 83} 84 85android_app_certificate { 86 name: "com.android.apogee.certificate", 87 certificate: "com.android.apogee", 88 bazel_module: { bp2build_available: false }, 89} 90 91cc_library { 92 name: "native_shared_lib_1", 93 bazel_module: { bp2build_available: false }, 94} 95 96cc_library { 97 name: "native_shared_lib_2", 98 bazel_module: { bp2build_available: false }, 99} 100 101prebuilt_etc { 102 name: "prebuilt_1", 103 bazel_module: { bp2build_available: false }, 104} 105 106prebuilt_etc { 107 name: "prebuilt_2", 108 bazel_module: { bp2build_available: false }, 109} 110 111filegroup { 112 name: "com.android.apogee-file_contexts", 113 srcs: [ 114 "com.android.apogee-file_contexts", 115 ], 116 bazel_module: { bp2build_available: false }, 117} 118 119cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } 120sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } 121 122apex { 123 name: "com.android.apogee", 124 manifest: "apogee_manifest.json", 125 androidManifest: "ApogeeAndroidManifest.xml", 126 file_contexts: ":com.android.apogee-file_contexts", 127 min_sdk_version: "29", 128 key: "com.android.apogee.key", 129 certificate: ":com.android.apogee.certificate", 130 updatable: false, 131 installable: false, 132 compressible: false, 133 native_shared_libs: [ 134 "native_shared_lib_1", 135 "native_shared_lib_2", 136 ], 137 binaries: [ 138 "cc_binary_1", 139 "sh_binary_2", 140 ], 141 prebuilts: [ 142 "prebuilt_1", 143 "prebuilt_2", 144 ], 145 package_name: "com.android.apogee.test.package", 146 logging_parent: "logging.parent", 147} 148`, 149 ExpectedBazelTargets: []string{ 150 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 151 "android_manifest": `"ApogeeAndroidManifest.xml"`, 152 "binaries": `[ 153 ":cc_binary_1", 154 ":sh_binary_2", 155 ]`, 156 "certificate": `":com.android.apogee.certificate"`, 157 "file_contexts": `":com.android.apogee-file_contexts"`, 158 "installable": "False", 159 "key": `":com.android.apogee.key"`, 160 "manifest": `"apogee_manifest.json"`, 161 "min_sdk_version": `"29"`, 162 "native_shared_libs_32": `select({ 163 "//build/bazel/platforms/arch:arm": [ 164 ":native_shared_lib_1", 165 ":native_shared_lib_2", 166 ], 167 "//build/bazel/platforms/arch:x86": [ 168 ":native_shared_lib_1", 169 ":native_shared_lib_2", 170 ], 171 "//conditions:default": [], 172 })`, 173 "native_shared_libs_64": `select({ 174 "//build/bazel/platforms/arch:arm64": [ 175 ":native_shared_lib_1", 176 ":native_shared_lib_2", 177 ], 178 "//build/bazel/platforms/arch:x86_64": [ 179 ":native_shared_lib_1", 180 ":native_shared_lib_2", 181 ], 182 "//conditions:default": [], 183 })`, 184 "prebuilts": `[ 185 ":prebuilt_1", 186 ":prebuilt_2", 187 ]`, 188 "updatable": "False", 189 "compressible": "False", 190 "package_name": `"com.android.apogee.test.package"`, 191 "logging_parent": `"logging.parent"`, 192 }), 193 }}) 194} 195 196func TestApexBundleSimple_fileContextsInAnotherAndroidBp(t *testing.T) { 197 runApexTestCase(t, Bp2buildTestCase{ 198 Description: "apex - file contexts is a module in another Android.bp", 199 ModuleTypeUnderTest: "apex", 200 ModuleTypeUnderTestFactory: apex.BundleFactory, 201 Filesystem: map[string]string{ 202 "a/b/Android.bp": ` 203filegroup { 204 name: "com.android.apogee-file_contexts", 205 srcs: [ 206 "com.android.apogee-file_contexts", 207 ], 208 bazel_module: { bp2build_available: false }, 209} 210`, 211 }, 212 Blueprint: ` 213apex { 214 name: "com.android.apogee", 215 file_contexts: ":com.android.apogee-file_contexts", 216} 217`, 218 ExpectedBazelTargets: []string{ 219 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 220 "file_contexts": `"//a/b:com.android.apogee-file_contexts"`, 221 "manifest": `"apex_manifest.json"`, 222 }), 223 }}) 224} 225 226func TestApexBundleSimple_fileContextsIsFile(t *testing.T) { 227 runApexTestCase(t, Bp2buildTestCase{ 228 Description: "apex - file contexts is a file", 229 ModuleTypeUnderTest: "apex", 230 ModuleTypeUnderTestFactory: apex.BundleFactory, 231 Filesystem: map[string]string{}, 232 Blueprint: ` 233apex { 234 name: "com.android.apogee", 235 file_contexts: "file_contexts_file", 236} 237`, 238 ExpectedBazelTargets: []string{ 239 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 240 "file_contexts": `"file_contexts_file"`, 241 "manifest": `"apex_manifest.json"`, 242 }), 243 }}) 244} 245 246func TestApexBundleSimple_fileContextsIsNotSpecified(t *testing.T) { 247 runApexTestCase(t, Bp2buildTestCase{ 248 Description: "apex - file contexts is not specified", 249 ModuleTypeUnderTest: "apex", 250 ModuleTypeUnderTestFactory: apex.BundleFactory, 251 Filesystem: map[string]string{ 252 "system/sepolicy/apex/Android.bp": ` 253filegroup { 254 name: "com.android.apogee-file_contexts", 255 srcs: [ 256 "com.android.apogee-file_contexts", 257 ], 258 bazel_module: { bp2build_available: false }, 259} 260`, 261 }, 262 Blueprint: ` 263apex { 264 name: "com.android.apogee", 265} 266`, 267 ExpectedBazelTargets: []string{ 268 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 269 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 270 "manifest": `"apex_manifest.json"`, 271 }), 272 }}) 273} 274 275func TestApexBundleCompileMultilibBoth(t *testing.T) { 276 runApexTestCase(t, Bp2buildTestCase{ 277 Description: "apex - example with compile_multilib=both", 278 ModuleTypeUnderTest: "apex", 279 ModuleTypeUnderTestFactory: apex.BundleFactory, 280 Filesystem: map[string]string{ 281 "system/sepolicy/apex/Android.bp": ` 282filegroup { 283 name: "com.android.apogee-file_contexts", 284 srcs: [ "apogee-file_contexts", ], 285 bazel_module: { bp2build_available: false }, 286} 287`, 288 }, 289 Blueprint: createMultilibBlueprint(`compile_multilib: "both",`), 290 ExpectedBazelTargets: []string{ 291 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 292 "native_shared_libs_32": `[ 293 ":unnested_native_shared_lib", 294 ":native_shared_lib_for_both", 295 ":native_shared_lib_for_lib32", 296 ] + select({ 297 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], 298 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], 299 "//conditions:default": [], 300 })`, 301 "native_shared_libs_64": `select({ 302 "//build/bazel/platforms/arch:arm64": [ 303 ":unnested_native_shared_lib", 304 ":native_shared_lib_for_both", 305 ":native_shared_lib_for_lib64", 306 ":native_shared_lib_for_first", 307 ], 308 "//build/bazel/platforms/arch:x86_64": [ 309 ":unnested_native_shared_lib", 310 ":native_shared_lib_for_both", 311 ":native_shared_lib_for_lib64", 312 ":native_shared_lib_for_first", 313 ], 314 "//conditions:default": [], 315 })`, 316 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 317 "manifest": `"apex_manifest.json"`, 318 }), 319 }}) 320} 321 322func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) { 323 expectedBazelTargets := []string{ 324 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 325 "native_shared_libs_32": `select({ 326 "//build/bazel/platforms/arch:arm": [ 327 ":unnested_native_shared_lib", 328 ":native_shared_lib_for_both", 329 ":native_shared_lib_for_lib32", 330 ":native_shared_lib_for_first", 331 ], 332 "//build/bazel/platforms/arch:x86": [ 333 ":unnested_native_shared_lib", 334 ":native_shared_lib_for_both", 335 ":native_shared_lib_for_lib32", 336 ":native_shared_lib_for_first", 337 ], 338 "//conditions:default": [], 339 })`, 340 "native_shared_libs_64": `select({ 341 "//build/bazel/platforms/arch:arm64": [ 342 ":unnested_native_shared_lib", 343 ":native_shared_lib_for_both", 344 ":native_shared_lib_for_lib64", 345 ":native_shared_lib_for_first", 346 ], 347 "//build/bazel/platforms/arch:x86_64": [ 348 ":unnested_native_shared_lib", 349 ":native_shared_lib_for_both", 350 ":native_shared_lib_for_lib64", 351 ":native_shared_lib_for_first", 352 ], 353 "//conditions:default": [], 354 })`, 355 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 356 "manifest": `"apex_manifest.json"`, 357 }), 358 } 359 360 // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib 361 // should result to the same bp2build output 362 compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""} 363 for _, compileMultiLibProp := range compileMultiLibPropValues { 364 descriptionSuffix := compileMultiLibProp 365 if descriptionSuffix == "" { 366 descriptionSuffix = "compile_multilib unset" 367 } 368 runApexTestCase(t, Bp2buildTestCase{ 369 Description: "apex - example with " + compileMultiLibProp, 370 ModuleTypeUnderTest: "apex", 371 ModuleTypeUnderTestFactory: apex.BundleFactory, 372 Filesystem: map[string]string{ 373 "system/sepolicy/apex/Android.bp": ` 374 filegroup { 375 name: "com.android.apogee-file_contexts", 376 srcs: [ "apogee-file_contexts", ], 377 bazel_module: { bp2build_available: false }, 378 } 379 `, 380 }, 381 Blueprint: createMultilibBlueprint(compileMultiLibProp), 382 ExpectedBazelTargets: expectedBazelTargets, 383 }) 384 } 385} 386 387func TestApexBundleCompileMultilib32(t *testing.T) { 388 runApexTestCase(t, Bp2buildTestCase{ 389 Description: "apex - example with compile_multilib=32", 390 ModuleTypeUnderTest: "apex", 391 ModuleTypeUnderTestFactory: apex.BundleFactory, 392 Filesystem: map[string]string{ 393 "system/sepolicy/apex/Android.bp": ` 394filegroup { 395 name: "com.android.apogee-file_contexts", 396 srcs: [ "apogee-file_contexts", ], 397 bazel_module: { bp2build_available: false }, 398} 399`, 400 }, 401 Blueprint: createMultilibBlueprint(`compile_multilib: "32",`), 402 ExpectedBazelTargets: []string{ 403 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 404 "native_shared_libs_32": `[ 405 ":unnested_native_shared_lib", 406 ":native_shared_lib_for_both", 407 ":native_shared_lib_for_lib32", 408 ] + select({ 409 "//build/bazel/platforms/arch:arm": [":native_shared_lib_for_first"], 410 "//build/bazel/platforms/arch:x86": [":native_shared_lib_for_first"], 411 "//conditions:default": [], 412 })`, 413 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 414 "manifest": `"apex_manifest.json"`, 415 }), 416 }}) 417} 418 419func TestApexBundleCompileMultilib64(t *testing.T) { 420 runApexTestCase(t, Bp2buildTestCase{ 421 Description: "apex - example with compile_multilib=64", 422 ModuleTypeUnderTest: "apex", 423 ModuleTypeUnderTestFactory: apex.BundleFactory, 424 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 }, 433 Blueprint: createMultilibBlueprint(`compile_multilib: "64",`), 434 ExpectedBazelTargets: []string{ 435 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 436 "native_shared_libs_64": `select({ 437 "//build/bazel/platforms/arch:arm64": [ 438 ":unnested_native_shared_lib", 439 ":native_shared_lib_for_both", 440 ":native_shared_lib_for_lib64", 441 ":native_shared_lib_for_first", 442 ], 443 "//build/bazel/platforms/arch:x86_64": [ 444 ":unnested_native_shared_lib", 445 ":native_shared_lib_for_both", 446 ":native_shared_lib_for_lib64", 447 ":native_shared_lib_for_first", 448 ], 449 "//conditions:default": [], 450 })`, 451 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 452 "manifest": `"apex_manifest.json"`, 453 }), 454 }}) 455} 456 457func createMultilibBlueprint(compile_multilib string) string { 458 return fmt.Sprintf(` 459cc_library { 460 name: "native_shared_lib_for_both", 461 bazel_module: { bp2build_available: false }, 462} 463 464cc_library { 465 name: "native_shared_lib_for_first", 466 bazel_module: { bp2build_available: false }, 467} 468 469cc_library { 470 name: "native_shared_lib_for_lib32", 471 bazel_module: { bp2build_available: false }, 472} 473 474cc_library { 475 name: "native_shared_lib_for_lib64", 476 bazel_module: { bp2build_available: false }, 477} 478 479cc_library { 480 name: "unnested_native_shared_lib", 481 bazel_module: { bp2build_available: false }, 482} 483 484apex { 485 name: "com.android.apogee", 486 %s 487 native_shared_libs: ["unnested_native_shared_lib"], 488 multilib: { 489 both: { 490 native_shared_libs: [ 491 "native_shared_lib_for_both", 492 ], 493 }, 494 first: { 495 native_shared_libs: [ 496 "native_shared_lib_for_first", 497 ], 498 }, 499 lib32: { 500 native_shared_libs: [ 501 "native_shared_lib_for_lib32", 502 ], 503 }, 504 lib64: { 505 native_shared_libs: [ 506 "native_shared_lib_for_lib64", 507 ], 508 }, 509 }, 510}`, compile_multilib) 511} 512 513func TestApexBundleDefaultPropertyValues(t *testing.T) { 514 runApexTestCase(t, Bp2buildTestCase{ 515 Description: "apex - default property values", 516 ModuleTypeUnderTest: "apex", 517 ModuleTypeUnderTestFactory: apex.BundleFactory, 518 Filesystem: map[string]string{ 519 "system/sepolicy/apex/Android.bp": ` 520filegroup { 521 name: "com.android.apogee-file_contexts", 522 srcs: [ "apogee-file_contexts", ], 523 bazel_module: { bp2build_available: false }, 524} 525`, 526 }, 527 Blueprint: ` 528apex { 529 name: "com.android.apogee", 530 manifest: "apogee_manifest.json", 531} 532`, 533 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 534 "manifest": `"apogee_manifest.json"`, 535 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 536 }), 537 }}) 538} 539 540func TestApexBundleHasBazelModuleProps(t *testing.T) { 541 runApexTestCase(t, Bp2buildTestCase{ 542 Description: "apex - has bazel module props", 543 ModuleTypeUnderTest: "apex", 544 ModuleTypeUnderTestFactory: apex.BundleFactory, 545 Filesystem: map[string]string{ 546 "system/sepolicy/apex/Android.bp": ` 547filegroup { 548 name: "apogee-file_contexts", 549 srcs: [ "apogee-file_contexts", ], 550 bazel_module: { bp2build_available: false }, 551} 552`, 553 }, 554 Blueprint: ` 555apex { 556 name: "apogee", 557 manifest: "manifest.json", 558 bazel_module: { bp2build_available: true }, 559} 560`, 561 ExpectedBazelTargets: []string{MakeBazelTarget("apex", "apogee", AttrNameToString{ 562 "manifest": `"manifest.json"`, 563 "file_contexts": `"//system/sepolicy/apex:apogee-file_contexts"`, 564 }), 565 }}) 566} 567 568func TestBp2BuildOverrideApex(t *testing.T) { 569 runOverrideApexTestCase(t, Bp2buildTestCase{ 570 Description: "override_apex", 571 ModuleTypeUnderTest: "override_apex", 572 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 573 Filesystem: map[string]string{}, 574 Blueprint: ` 575apex_key { 576 name: "com.android.apogee.key", 577 public_key: "com.android.apogee.avbpubkey", 578 private_key: "com.android.apogee.pem", 579 bazel_module: { bp2build_available: false }, 580} 581 582android_app_certificate { 583 name: "com.android.apogee.certificate", 584 certificate: "com.android.apogee", 585 bazel_module: { bp2build_available: false }, 586} 587 588cc_library { 589 name: "native_shared_lib_1", 590 bazel_module: { bp2build_available: false }, 591} 592 593cc_library { 594 name: "native_shared_lib_2", 595 bazel_module: { bp2build_available: false }, 596} 597 598prebuilt_etc { 599 name: "prebuilt_1", 600 bazel_module: { bp2build_available: false }, 601} 602 603prebuilt_etc { 604 name: "prebuilt_2", 605 bazel_module: { bp2build_available: false }, 606} 607 608filegroup { 609 name: "com.android.apogee-file_contexts", 610 srcs: [ 611 "com.android.apogee-file_contexts", 612 ], 613 bazel_module: { bp2build_available: false }, 614} 615 616cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } 617sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } 618 619apex { 620 name: "com.android.apogee", 621 manifest: "apogee_manifest.json", 622 androidManifest: "ApogeeAndroidManifest.xml", 623 file_contexts: ":com.android.apogee-file_contexts", 624 min_sdk_version: "29", 625 key: "com.android.apogee.key", 626 certificate: ":com.android.apogee.certificate", 627 updatable: false, 628 installable: false, 629 compressible: false, 630 native_shared_libs: [ 631 "native_shared_lib_1", 632 "native_shared_lib_2", 633 ], 634 binaries: [ 635 "cc_binary_1", 636 "sh_binary_2", 637 ], 638 prebuilts: [ 639 "prebuilt_1", 640 "prebuilt_2", 641 ], 642 bazel_module: { bp2build_available: false }, 643} 644 645apex_key { 646 name: "com.google.android.apogee.key", 647 public_key: "com.google.android.apogee.avbpubkey", 648 private_key: "com.google.android.apogee.pem", 649 bazel_module: { bp2build_available: false }, 650} 651 652android_app_certificate { 653 name: "com.google.android.apogee.certificate", 654 certificate: "com.google.android.apogee", 655 bazel_module: { bp2build_available: false }, 656} 657 658override_apex { 659 name: "com.google.android.apogee", 660 base: ":com.android.apogee", 661 key: "com.google.android.apogee.key", 662 certificate: ":com.google.android.apogee.certificate", 663 prebuilts: [], 664 compressible: true, 665} 666`, 667 ExpectedBazelTargets: []string{ 668 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 669 "android_manifest": `"ApogeeAndroidManifest.xml"`, 670 "base_apex_name": `"com.android.apogee"`, 671 "binaries": `[ 672 ":cc_binary_1", 673 ":sh_binary_2", 674 ]`, 675 "certificate": `":com.google.android.apogee.certificate"`, 676 "file_contexts": `":com.android.apogee-file_contexts"`, 677 "installable": "False", 678 "key": `":com.google.android.apogee.key"`, 679 "manifest": `"apogee_manifest.json"`, 680 "min_sdk_version": `"29"`, 681 "native_shared_libs_32": `select({ 682 "//build/bazel/platforms/arch:arm": [ 683 ":native_shared_lib_1", 684 ":native_shared_lib_2", 685 ], 686 "//build/bazel/platforms/arch:x86": [ 687 ":native_shared_lib_1", 688 ":native_shared_lib_2", 689 ], 690 "//conditions:default": [], 691 })`, 692 "native_shared_libs_64": `select({ 693 "//build/bazel/platforms/arch:arm64": [ 694 ":native_shared_lib_1", 695 ":native_shared_lib_2", 696 ], 697 "//build/bazel/platforms/arch:x86_64": [ 698 ":native_shared_lib_1", 699 ":native_shared_lib_2", 700 ], 701 "//conditions:default": [], 702 })`, 703 "prebuilts": `[]`, 704 "updatable": "False", 705 "compressible": "True", 706 }), 707 }}) 708} 709 710func TestOverrideApexTest(t *testing.T) { 711 runOverrideApexTestCase(t, Bp2buildTestCase{ 712 Description: "override_apex", 713 ModuleTypeUnderTest: "override_apex", 714 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 715 Filesystem: map[string]string{}, 716 Blueprint: ` 717apex_key { 718 name: "com.android.apogee.key", 719 public_key: "com.android.apogee.avbpubkey", 720 private_key: "com.android.apogee.pem", 721 bazel_module: { bp2build_available: false }, 722} 723 724android_app_certificate { 725 name: "com.android.apogee.certificate", 726 certificate: "com.android.apogee", 727 bazel_module: { bp2build_available: false }, 728} 729 730cc_library { 731 name: "native_shared_lib_1", 732 bazel_module: { bp2build_available: false }, 733} 734 735prebuilt_etc { 736 name: "prebuilt_1", 737 bazel_module: { bp2build_available: false }, 738} 739 740filegroup { 741 name: "com.android.apogee-file_contexts", 742 srcs: [ 743 "com.android.apogee-file_contexts", 744 ], 745 bazel_module: { bp2build_available: false }, 746} 747 748cc_binary { name: "cc_binary_1", bazel_module: { bp2build_available: false } } 749sh_binary { name: "sh_binary_2", bazel_module: { bp2build_available: false } } 750 751apex_test { 752 name: "com.android.apogee", 753 manifest: "apogee_manifest.json", 754 androidManifest: "ApogeeAndroidManifest.xml", 755 file_contexts: ":com.android.apogee-file_contexts", 756 min_sdk_version: "29", 757 key: "com.android.apogee.key", 758 certificate: ":com.android.apogee.certificate", 759 updatable: false, 760 installable: false, 761 compressible: false, 762 native_shared_libs: [ 763 "native_shared_lib_1", 764 ], 765 binaries: [ 766 "cc_binary_1", 767 "sh_binary_2", 768 ], 769 prebuilts: [ 770 "prebuilt_1", 771 ], 772 bazel_module: { bp2build_available: false }, 773} 774 775apex_key { 776 name: "com.google.android.apogee.key", 777 public_key: "com.google.android.apogee.avbpubkey", 778 private_key: "com.google.android.apogee.pem", 779 bazel_module: { bp2build_available: false }, 780} 781 782android_app_certificate { 783 name: "com.google.android.apogee.certificate", 784 certificate: "com.google.android.apogee", 785 bazel_module: { bp2build_available: false }, 786} 787 788override_apex { 789 name: "com.google.android.apogee", 790 base: ":com.android.apogee", 791 key: "com.google.android.apogee.key", 792 certificate: ":com.google.android.apogee.certificate", 793 prebuilts: [], 794 compressible: true, 795} 796`, 797 ExpectedBazelTargets: []string{ 798 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 799 "android_manifest": `"ApogeeAndroidManifest.xml"`, 800 "base_apex_name": `"com.android.apogee"`, 801 "binaries": `[ 802 ":cc_binary_1", 803 ":sh_binary_2", 804 ]`, 805 "certificate": `":com.google.android.apogee.certificate"`, 806 "file_contexts": `":com.android.apogee-file_contexts"`, 807 "installable": "False", 808 "key": `":com.google.android.apogee.key"`, 809 "manifest": `"apogee_manifest.json"`, 810 "min_sdk_version": `"29"`, 811 "native_shared_libs_32": `select({ 812 "//build/bazel/platforms/arch:arm": [":native_shared_lib_1"], 813 "//build/bazel/platforms/arch:x86": [":native_shared_lib_1"], 814 "//conditions:default": [], 815 })`, 816 "native_shared_libs_64": `select({ 817 "//build/bazel/platforms/arch:arm64": [":native_shared_lib_1"], 818 "//build/bazel/platforms/arch:x86_64": [":native_shared_lib_1"], 819 "//conditions:default": [], 820 })`, 821 "testonly": "True", 822 "prebuilts": `[]`, 823 "updatable": "False", 824 "compressible": "True", 825 }), 826 }}) 827} 828 829func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { 830 runOverrideApexTestCase(t, Bp2buildTestCase{ 831 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in different Android.bp", 832 ModuleTypeUnderTest: "override_apex", 833 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 834 Filesystem: map[string]string{ 835 "system/sepolicy/apex/Android.bp": ` 836filegroup { 837 name: "com.android.apogee-file_contexts", 838 srcs: [ "apogee-file_contexts", ], 839 bazel_module: { bp2build_available: false }, 840}`, 841 "a/b/Android.bp": ` 842apex { 843 name: "com.android.apogee", 844 bazel_module: { bp2build_available: false }, 845} 846`, 847 }, 848 Blueprint: ` 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 "base_apex_name": `"com.android.apogee"`, 857 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 858 "manifest": `"//a/b:apex_manifest.json"`, 859 }), 860 }}) 861} 862 863func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInDifferentAndroidBp(t *testing.T) { 864 runOverrideApexTestCase(t, Bp2buildTestCase{ 865 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in different Android.bp", 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 "a/b/Android.bp": ` 876apex { 877 name: "com.android.apogee", 878 manifest: "apogee_manifest.json", 879 bazel_module: { bp2build_available: false }, 880} 881`, 882 }, 883 Blueprint: ` 884override_apex { 885 name: "com.google.android.apogee", 886 base: ":com.android.apogee", 887} 888`, 889 ExpectedBazelTargets: []string{ 890 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 891 "base_apex_name": `"com.android.apogee"`, 892 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 893 "manifest": `"//a/b:apogee_manifest.json"`, 894 }), 895 }}) 896} 897 898func TestApexBundleSimple_manifestIsEmpty_baseApexOverrideApexInSameAndroidBp(t *testing.T) { 899 runOverrideApexTestCase(t, Bp2buildTestCase{ 900 Description: "override_apex - manifest of base apex is empty, base apex and override_apex is in same Android.bp", 901 ModuleTypeUnderTest: "override_apex", 902 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 903 Filesystem: map[string]string{ 904 "system/sepolicy/apex/Android.bp": ` 905filegroup { 906 name: "com.android.apogee-file_contexts", 907 srcs: [ "apogee-file_contexts", ], 908 bazel_module: { bp2build_available: false }, 909}`, 910 }, 911 Blueprint: ` 912apex { 913 name: "com.android.apogee", 914 bazel_module: { bp2build_available: false }, 915} 916 917override_apex { 918 name: "com.google.android.apogee", 919 base: ":com.android.apogee", 920} 921`, 922 ExpectedBazelTargets: []string{ 923 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 924 "base_apex_name": `"com.android.apogee"`, 925 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 926 "manifest": `"apex_manifest.json"`, 927 }), 928 }}) 929} 930 931func TestApexBundleSimple_manifestIsSet_baseApexOverrideApexInSameAndroidBp(t *testing.T) { 932 runOverrideApexTestCase(t, Bp2buildTestCase{ 933 Description: "override_apex - manifest of base apex is set, base apex and override_apex is in same Android.bp", 934 ModuleTypeUnderTest: "override_apex", 935 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 936 Filesystem: map[string]string{ 937 "system/sepolicy/apex/Android.bp": ` 938filegroup { 939 name: "com.android.apogee-file_contexts", 940 srcs: [ "apogee-file_contexts", ], 941 bazel_module: { bp2build_available: false }, 942}`, 943 }, 944 Blueprint: ` 945apex { 946 name: "com.android.apogee", 947 manifest: "apogee_manifest.json", 948 bazel_module: { bp2build_available: false }, 949} 950 951override_apex { 952 name: "com.google.android.apogee", 953 base: ":com.android.apogee", 954} 955`, 956 ExpectedBazelTargets: []string{ 957 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 958 "base_apex_name": `"com.android.apogee"`, 959 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 960 "manifest": `"apogee_manifest.json"`, 961 }), 962 }}) 963} 964 965func TestApexBundleSimple_packageNameOverride(t *testing.T) { 966 runOverrideApexTestCase(t, Bp2buildTestCase{ 967 Description: "override_apex - override package name", 968 ModuleTypeUnderTest: "override_apex", 969 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 970 Filesystem: map[string]string{ 971 "system/sepolicy/apex/Android.bp": ` 972filegroup { 973 name: "com.android.apogee-file_contexts", 974 srcs: [ "apogee-file_contexts", ], 975 bazel_module: { bp2build_available: false }, 976}`, 977 }, 978 Blueprint: ` 979apex { 980 name: "com.android.apogee", 981 bazel_module: { bp2build_available: false }, 982} 983 984override_apex { 985 name: "com.google.android.apogee", 986 base: ":com.android.apogee", 987 package_name: "com.google.android.apogee", 988} 989`, 990 ExpectedBazelTargets: []string{ 991 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 992 "base_apex_name": `"com.android.apogee"`, 993 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 994 "manifest": `"apex_manifest.json"`, 995 "package_name": `"com.google.android.apogee"`, 996 }), 997 }}) 998} 999 1000func TestApexBundleSimple_NoPrebuiltsOverride(t *testing.T) { 1001 runOverrideApexTestCase(t, Bp2buildTestCase{ 1002 Description: "override_apex - no override", 1003 ModuleTypeUnderTest: "override_apex", 1004 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1005 Filesystem: map[string]string{ 1006 "system/sepolicy/apex/Android.bp": ` 1007filegroup { 1008 name: "com.android.apogee-file_contexts", 1009 srcs: [ "apogee-file_contexts", ], 1010 bazel_module: { bp2build_available: false }, 1011}`, 1012 }, 1013 Blueprint: ` 1014prebuilt_etc { 1015 name: "prebuilt_file", 1016 bazel_module: { bp2build_available: false }, 1017} 1018 1019apex { 1020 name: "com.android.apogee", 1021 bazel_module: { bp2build_available: false }, 1022 prebuilts: ["prebuilt_file"] 1023} 1024 1025override_apex { 1026 name: "com.google.android.apogee", 1027 base: ":com.android.apogee", 1028} 1029`, 1030 ExpectedBazelTargets: []string{ 1031 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1032 "base_apex_name": `"com.android.apogee"`, 1033 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 1034 "manifest": `"apex_manifest.json"`, 1035 "prebuilts": `[":prebuilt_file"]`, 1036 }), 1037 }}) 1038} 1039 1040func TestApexBundleSimple_PrebuiltsOverride(t *testing.T) { 1041 runOverrideApexTestCase(t, Bp2buildTestCase{ 1042 Description: "override_apex - ooverride", 1043 ModuleTypeUnderTest: "override_apex", 1044 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1045 Filesystem: map[string]string{ 1046 "system/sepolicy/apex/Android.bp": ` 1047filegroup { 1048 name: "com.android.apogee-file_contexts", 1049 srcs: [ "apogee-file_contexts", ], 1050 bazel_module: { bp2build_available: false }, 1051}`, 1052 }, 1053 Blueprint: ` 1054prebuilt_etc { 1055 name: "prebuilt_file", 1056 bazel_module: { bp2build_available: false }, 1057} 1058 1059prebuilt_etc { 1060 name: "prebuilt_file2", 1061 bazel_module: { bp2build_available: false }, 1062} 1063 1064apex { 1065 name: "com.android.apogee", 1066 bazel_module: { bp2build_available: false }, 1067 prebuilts: ["prebuilt_file"] 1068} 1069 1070override_apex { 1071 name: "com.google.android.apogee", 1072 base: ":com.android.apogee", 1073 prebuilts: ["prebuilt_file2"] 1074} 1075`, 1076 ExpectedBazelTargets: []string{ 1077 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1078 "base_apex_name": `"com.android.apogee"`, 1079 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 1080 "manifest": `"apex_manifest.json"`, 1081 "prebuilts": `[":prebuilt_file2"]`, 1082 }), 1083 }}) 1084} 1085 1086func TestApexBundleSimple_PrebuiltsOverrideEmptyList(t *testing.T) { 1087 runOverrideApexTestCase(t, Bp2buildTestCase{ 1088 Description: "override_apex - override with empty list", 1089 ModuleTypeUnderTest: "override_apex", 1090 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1091 Filesystem: map[string]string{ 1092 "system/sepolicy/apex/Android.bp": ` 1093filegroup { 1094 name: "com.android.apogee-file_contexts", 1095 srcs: [ "apogee-file_contexts", ], 1096 bazel_module: { bp2build_available: false }, 1097}`, 1098 }, 1099 Blueprint: ` 1100prebuilt_etc { 1101 name: "prebuilt_file", 1102 bazel_module: { bp2build_available: false }, 1103} 1104 1105apex { 1106 name: "com.android.apogee", 1107 bazel_module: { bp2build_available: false }, 1108 prebuilts: ["prebuilt_file"] 1109} 1110 1111override_apex { 1112 name: "com.google.android.apogee", 1113 base: ":com.android.apogee", 1114 prebuilts: [], 1115} 1116`, 1117 ExpectedBazelTargets: []string{ 1118 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1119 "base_apex_name": `"com.android.apogee"`, 1120 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 1121 "manifest": `"apex_manifest.json"`, 1122 "prebuilts": `[]`, 1123 }), 1124 }}) 1125} 1126 1127func TestApexBundleSimple_NoLoggingParentOverride(t *testing.T) { 1128 runOverrideApexTestCase(t, Bp2buildTestCase{ 1129 Description: "override_apex - logging_parent - no override", 1130 ModuleTypeUnderTest: "override_apex", 1131 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1132 Filesystem: map[string]string{ 1133 "system/sepolicy/apex/Android.bp": ` 1134filegroup { 1135 name: "com.android.apogee-file_contexts", 1136 srcs: [ "apogee-file_contexts", ], 1137 bazel_module: { bp2build_available: false }, 1138}`, 1139 }, 1140 Blueprint: ` 1141apex { 1142 name: "com.android.apogee", 1143 bazel_module: { bp2build_available: false }, 1144 logging_parent: "foo.bar.baz", 1145} 1146 1147override_apex { 1148 name: "com.google.android.apogee", 1149 base: ":com.android.apogee", 1150} 1151`, 1152 ExpectedBazelTargets: []string{ 1153 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1154 "base_apex_name": `"com.android.apogee"`, 1155 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 1156 "manifest": `"apex_manifest.json"`, 1157 "logging_parent": `"foo.bar.baz"`, 1158 }), 1159 }}) 1160} 1161 1162func TestApexBundleSimple_LoggingParentOverride(t *testing.T) { 1163 runOverrideApexTestCase(t, Bp2buildTestCase{ 1164 Description: "override_apex - logging_parent - override", 1165 ModuleTypeUnderTest: "override_apex", 1166 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1167 Filesystem: map[string]string{ 1168 "system/sepolicy/apex/Android.bp": ` 1169filegroup { 1170 name: "com.android.apogee-file_contexts", 1171 srcs: [ "apogee-file_contexts", ], 1172 bazel_module: { bp2build_available: false }, 1173}`, 1174 }, 1175 Blueprint: ` 1176apex { 1177 name: "com.android.apogee", 1178 bazel_module: { bp2build_available: false }, 1179 logging_parent: "foo.bar.baz", 1180} 1181 1182override_apex { 1183 name: "com.google.android.apogee", 1184 base: ":com.android.apogee", 1185 logging_parent: "foo.bar.baz.override", 1186} 1187`, 1188 ExpectedBazelTargets: []string{ 1189 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1190 "base_apex_name": `"com.android.apogee"`, 1191 "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`, 1192 "manifest": `"apex_manifest.json"`, 1193 "logging_parent": `"foo.bar.baz.override"`, 1194 }), 1195 }}) 1196} 1197 1198func TestBp2BuildOverrideApex_CertificateNil(t *testing.T) { 1199 runOverrideApexTestCase(t, Bp2buildTestCase{ 1200 Description: "override_apex - don't set default certificate", 1201 ModuleTypeUnderTest: "override_apex", 1202 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1203 Filesystem: map[string]string{}, 1204 Blueprint: ` 1205android_app_certificate { 1206 name: "com.android.apogee.certificate", 1207 certificate: "com.android.apogee", 1208 bazel_module: { bp2build_available: false }, 1209} 1210 1211filegroup { 1212 name: "com.android.apogee-file_contexts", 1213 srcs: [ 1214 "com.android.apogee-file_contexts", 1215 ], 1216 bazel_module: { bp2build_available: false }, 1217} 1218 1219apex { 1220 name: "com.android.apogee", 1221 manifest: "apogee_manifest.json", 1222 file_contexts: ":com.android.apogee-file_contexts", 1223 certificate: ":com.android.apogee.certificate", 1224 bazel_module: { bp2build_available: false }, 1225} 1226 1227override_apex { 1228 name: "com.google.android.apogee", 1229 base: ":com.android.apogee", 1230 // certificate is deliberately omitted, and not converted to bazel, 1231 // because the overridden apex shouldn't be using the base apex's cert. 1232} 1233`, 1234 ExpectedBazelTargets: []string{ 1235 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1236 "base_apex_name": `"com.android.apogee"`, 1237 "file_contexts": `":com.android.apogee-file_contexts"`, 1238 "manifest": `"apogee_manifest.json"`, 1239 }), 1240 }}) 1241} 1242 1243func TestApexCertificateIsModule(t *testing.T) { 1244 runApexTestCase(t, Bp2buildTestCase{ 1245 Description: "apex - certificate is module", 1246 ModuleTypeUnderTest: "apex", 1247 ModuleTypeUnderTestFactory: apex.BundleFactory, 1248 Filesystem: map[string]string{}, 1249 Blueprint: ` 1250android_app_certificate { 1251 name: "com.android.apogee.certificate", 1252 certificate: "com.android.apogee", 1253 bazel_module: { bp2build_available: false }, 1254} 1255 1256apex { 1257 name: "com.android.apogee", 1258 manifest: "apogee_manifest.json", 1259 file_contexts: ":com.android.apogee-file_contexts", 1260 certificate: ":com.android.apogee.certificate", 1261} 1262` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), 1263 ExpectedBazelTargets: []string{ 1264 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 1265 "certificate": `":com.android.apogee.certificate"`, 1266 "file_contexts": `":com.android.apogee-file_contexts"`, 1267 "manifest": `"apogee_manifest.json"`, 1268 }), 1269 }}) 1270} 1271 1272func TestApexWithStubLib(t *testing.T) { 1273 runApexTestCase(t, Bp2buildTestCase{ 1274 Description: "apex - static variant of stub lib should not have apex_available tag", 1275 ModuleTypeUnderTest: "apex", 1276 ModuleTypeUnderTestFactory: apex.BundleFactory, 1277 Filesystem: map[string]string{}, 1278 Blueprint: ` 1279cc_library{ 1280 name: "foo", 1281 stubs: { symbol_file: "foo.map.txt", versions: ["28", "29", "current"] }, 1282 apex_available: ["myapex"], 1283} 1284 1285cc_binary{ 1286 name: "bar", 1287 static_libs: ["foo"], 1288 apex_available: ["myapex"], 1289} 1290 1291apex { 1292 name: "myapex", 1293 manifest: "myapex_manifest.json", 1294 file_contexts: ":myapex-file_contexts", 1295 binaries: ["bar"], 1296 native_shared_libs: ["foo"], 1297} 1298` + simpleModuleDoNotConvertBp2build("filegroup", "myapex-file_contexts"), 1299 ExpectedBazelTargets: []string{ 1300 MakeBazelTarget("cc_binary", "bar", AttrNameToString{ 1301 "local_includes": `["."]`, 1302 "deps": `[":foo_bp2build_cc_library_static"]`, 1303 "tags": `["apex_available=myapex"]`, 1304 }), 1305 MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ 1306 "local_includes": `["."]`, 1307 }), 1308 MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ 1309 "local_includes": `["."]`, 1310 "stubs_symbol_file": `"foo.map.txt"`, 1311 "tags": `["apex_available=myapex"]`, 1312 }), 1313 MakeBazelTarget("cc_stub_suite", "foo_stub_libs", AttrNameToString{ 1314 "soname": `"foo.so"`, 1315 "source_library_label": `"//:foo"`, 1316 "symbol_file": `"foo.map.txt"`, 1317 "versions": `[ 1318 "28", 1319 "29", 1320 "current", 1321 ]`, 1322 }), 1323 MakeBazelTarget("apex", "myapex", AttrNameToString{ 1324 "file_contexts": `":myapex-file_contexts"`, 1325 "manifest": `"myapex_manifest.json"`, 1326 "binaries": `[":bar"]`, 1327 "native_shared_libs_32": `select({ 1328 "//build/bazel/platforms/arch:arm": [":foo"], 1329 "//build/bazel/platforms/arch:x86": [":foo"], 1330 "//conditions:default": [], 1331 })`, 1332 "native_shared_libs_64": `select({ 1333 "//build/bazel/platforms/arch:arm64": [":foo"], 1334 "//build/bazel/platforms/arch:x86_64": [":foo"], 1335 "//conditions:default": [], 1336 })`, 1337 }), 1338 }, 1339 }) 1340} 1341 1342func TestApexCertificateIsSrc(t *testing.T) { 1343 runApexTestCase(t, Bp2buildTestCase{ 1344 Description: "apex - certificate is src", 1345 ModuleTypeUnderTest: "apex", 1346 ModuleTypeUnderTestFactory: apex.BundleFactory, 1347 Filesystem: map[string]string{}, 1348 Blueprint: ` 1349apex { 1350 name: "com.android.apogee", 1351 manifest: "apogee_manifest.json", 1352 file_contexts: ":com.android.apogee-file_contexts", 1353 certificate: "com.android.apogee.certificate", 1354} 1355` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee-file_contexts"), 1356 ExpectedBazelTargets: []string{ 1357 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 1358 "certificate_name": `"com.android.apogee.certificate"`, 1359 "file_contexts": `":com.android.apogee-file_contexts"`, 1360 "manifest": `"apogee_manifest.json"`, 1361 }), 1362 }}) 1363} 1364 1365func TestBp2BuildOverrideApex_CertificateIsModule(t *testing.T) { 1366 runOverrideApexTestCase(t, Bp2buildTestCase{ 1367 Description: "override_apex - certificate is module", 1368 ModuleTypeUnderTest: "override_apex", 1369 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1370 Filesystem: map[string]string{}, 1371 Blueprint: ` 1372android_app_certificate { 1373 name: "com.android.apogee.certificate", 1374 certificate: "com.android.apogee", 1375 bazel_module: { bp2build_available: false }, 1376} 1377 1378filegroup { 1379 name: "com.android.apogee-file_contexts", 1380 srcs: [ 1381 "com.android.apogee-file_contexts", 1382 ], 1383 bazel_module: { bp2build_available: false }, 1384} 1385 1386apex { 1387 name: "com.android.apogee", 1388 manifest: "apogee_manifest.json", 1389 file_contexts: ":com.android.apogee-file_contexts", 1390 certificate: ":com.android.apogee.certificate", 1391 bazel_module: { bp2build_available: false }, 1392} 1393 1394android_app_certificate { 1395 name: "com.google.android.apogee.certificate", 1396 certificate: "com.google.android.apogee", 1397 bazel_module: { bp2build_available: false }, 1398} 1399 1400override_apex { 1401 name: "com.google.android.apogee", 1402 base: ":com.android.apogee", 1403 certificate: ":com.google.android.apogee.certificate", 1404} 1405`, 1406 ExpectedBazelTargets: []string{ 1407 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1408 "base_apex_name": `"com.android.apogee"`, 1409 "file_contexts": `":com.android.apogee-file_contexts"`, 1410 "certificate": `":com.google.android.apogee.certificate"`, 1411 "manifest": `"apogee_manifest.json"`, 1412 }), 1413 }}) 1414} 1415 1416func TestBp2BuildOverrideApex_CertificateIsSrc(t *testing.T) { 1417 runOverrideApexTestCase(t, Bp2buildTestCase{ 1418 Description: "override_apex - certificate is src", 1419 ModuleTypeUnderTest: "override_apex", 1420 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1421 Filesystem: map[string]string{}, 1422 Blueprint: ` 1423android_app_certificate { 1424 name: "com.android.apogee.certificate", 1425 certificate: "com.android.apogee", 1426 bazel_module: { bp2build_available: false }, 1427} 1428 1429filegroup { 1430 name: "com.android.apogee-file_contexts", 1431 srcs: [ 1432 "com.android.apogee-file_contexts", 1433 ], 1434 bazel_module: { bp2build_available: false }, 1435} 1436 1437apex { 1438 name: "com.android.apogee", 1439 manifest: "apogee_manifest.json", 1440 file_contexts: ":com.android.apogee-file_contexts", 1441 certificate: ":com.android.apogee.certificate", 1442 bazel_module: { bp2build_available: false }, 1443} 1444 1445override_apex { 1446 name: "com.google.android.apogee", 1447 base: ":com.android.apogee", 1448 certificate: "com.google.android.apogee.certificate", 1449} 1450`, 1451 ExpectedBazelTargets: []string{ 1452 MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{ 1453 "base_apex_name": `"com.android.apogee"`, 1454 "file_contexts": `":com.android.apogee-file_contexts"`, 1455 "certificate_name": `"com.google.android.apogee.certificate"`, 1456 "manifest": `"apogee_manifest.json"`, 1457 }), 1458 }}) 1459} 1460 1461func TestApexTestBundleSimple(t *testing.T) { 1462 runApexTestCase(t, Bp2buildTestCase{ 1463 Description: "apex_test - simple", 1464 ModuleTypeUnderTest: "apex_test", 1465 ModuleTypeUnderTestFactory: apex.TestApexBundleFactory, 1466 Filesystem: map[string]string{}, 1467 Blueprint: ` 1468cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } } 1469 1470apex_test { 1471 name: "test_com.android.apogee", 1472 file_contexts: "file_contexts_file", 1473 tests: ["cc_test_1"], 1474} 1475`, 1476 ExpectedBazelTargets: []string{ 1477 MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{ 1478 "file_contexts": `"file_contexts_file"`, 1479 "manifest": `"apex_manifest.json"`, 1480 "testonly": `True`, 1481 "tests": `[":cc_test_1"]`, 1482 }), 1483 }}) 1484} 1485 1486func TestApexBundle_overridePlusProductVars(t *testing.T) { 1487 // Reproduction of b/271424349 1488 // Tests that overriding an apex that uses product variables correctly copies the product var 1489 // selects over to the override. 1490 runOverrideApexTestCase(t, Bp2buildTestCase{ 1491 Description: "apex - overriding a module that uses product vars", 1492 ModuleTypeUnderTest: "override_apex", 1493 ModuleTypeUnderTestFactory: apex.OverrideApexFactory, 1494 Blueprint: ` 1495soong_config_string_variable { 1496 name: "library_linking_strategy", 1497 values: [ 1498 "prefer_static", 1499 ], 1500} 1501 1502soong_config_module_type { 1503 name: "library_linking_strategy_apex_defaults", 1504 module_type: "apex_defaults", 1505 config_namespace: "ANDROID", 1506 variables: ["library_linking_strategy"], 1507 properties: [ 1508 "manifest", 1509 "min_sdk_version", 1510 ], 1511} 1512 1513library_linking_strategy_apex_defaults { 1514 name: "higher_min_sdk_when_prefer_static", 1515 soong_config_variables: { 1516 library_linking_strategy: { 1517 // Use the R min_sdk_version 1518 prefer_static: {}, 1519 // Override the R min_sdk_version to min_sdk_version that supports dcla 1520 conditions_default: { 1521 min_sdk_version: "31", 1522 }, 1523 }, 1524 }, 1525} 1526 1527filegroup { 1528 name: "foo-file_contexts", 1529 srcs: [ 1530 "com.android.apogee-file_contexts", 1531 ], 1532 bazel_module: { bp2build_available: false }, 1533} 1534 1535apex { 1536 name: "foo", 1537 defaults: ["higher_min_sdk_when_prefer_static"], 1538 min_sdk_version: "30", 1539 package_name: "pkg_name", 1540 file_contexts: ":foo-file_contexts", 1541} 1542override_apex { 1543 name: "override_foo", 1544 base: ":foo", 1545 package_name: "override_pkg_name", 1546} 1547`, 1548 ExpectedBazelTargets: []string{ 1549 MakeBazelTarget("apex", "foo", AttrNameToString{ 1550 "file_contexts": `":foo-file_contexts"`, 1551 "manifest": `"apex_manifest.json"`, 1552 "min_sdk_version": `select({ 1553 "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30", 1554 "//conditions:default": "31", 1555 })`, 1556 "package_name": `"pkg_name"`, 1557 }), MakeBazelTarget("apex", "override_foo", AttrNameToString{ 1558 "base_apex_name": `"foo"`, 1559 "file_contexts": `":foo-file_contexts"`, 1560 "manifest": `"apex_manifest.json"`, 1561 "min_sdk_version": `select({ 1562 "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": "30", 1563 "//conditions:default": "31", 1564 })`, 1565 "package_name": `"override_pkg_name"`, 1566 }), 1567 }}) 1568} 1569 1570func TestApexBundleSimple_customCannedFsConfig(t *testing.T) { 1571 runApexTestCase(t, Bp2buildTestCase{ 1572 Description: "apex - custom canned_fs_config", 1573 ModuleTypeUnderTest: "apex", 1574 ModuleTypeUnderTestFactory: apex.BundleFactory, 1575 Filesystem: map[string]string{}, 1576 Blueprint: ` 1577apex { 1578 name: "com.android.apogee", 1579 canned_fs_config: "custom.canned_fs_config", 1580 file_contexts: "file_contexts_file", 1581} 1582`, 1583 ExpectedBazelTargets: []string{ 1584 MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{ 1585 "canned_fs_config": `"custom.canned_fs_config"`, 1586 "file_contexts": `"file_contexts_file"`, 1587 "manifest": `"apex_manifest.json"`, 1588 }), 1589 }}) 1590} 1591