1// Copyright (C) 2019 The Android Open Source Project 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 sdk 16 17import ( 18 "fmt" 19 "testing" 20 21 "android/soong/android" 22 "android/soong/cc" 23) 24 25var ccTestFs = android.MockFS{ 26 "Test.cpp": nil, 27 "myinclude/Test.h": nil, 28 "myinclude-android/AndroidTest.h": nil, 29 "myinclude-host/HostTest.h": nil, 30 "arm64/include/Arm64Test.h": nil, 31 "libfoo.so": nil, 32 "aidl/foo/bar/Test.aidl": nil, 33 "some/where/stubslib.map.txt": nil, 34} 35 36// Adds a native bridge target to the configured list of targets. 37var prepareForTestWithNativeBridgeTarget = android.FixtureModifyConfig(func(config android.Config) { 38 config.Targets[android.Android] = append(config.Targets[android.Android], android.Target{ 39 Os: android.Android, 40 Arch: android.Arch{ 41 ArchType: android.Arm64, 42 ArchVariant: "armv8-a", 43 CpuVariant: "cpu", 44 Abi: nil, 45 ArchFeatures: nil, 46 }, 47 NativeBridge: android.NativeBridgeEnabled, 48 NativeBridgeHostArchName: "x86_64", 49 NativeBridgeRelativePath: "native_bridge", 50 }) 51}) 52 53func testSdkWithCc(t *testing.T, bp string) *android.TestResult { 54 t.Helper() 55 return testSdkWithFs(t, bp, ccTestFs) 56} 57 58// Contains tests for SDK members provided by the cc package. 59 60func TestSingleDeviceOsAssumption(t *testing.T) { 61 // Mock a module with DeviceSupported() == true. 62 s := &sdk{} 63 android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon) 64 65 osTypes := s.getPossibleOsTypes() 66 if len(osTypes) != 1 { 67 // The snapshot generation assumes there is a single device OS. If more are 68 // added it might need to disable them by default, like it does for host 69 // OS'es. 70 t.Errorf("expected a single device OS, got %v", osTypes) 71 } 72} 73 74func TestSdkIsCompileMultilibBoth(t *testing.T) { 75 result := testSdkWithCc(t, ` 76 sdk { 77 name: "mysdk", 78 native_shared_libs: ["sdkmember"], 79 } 80 81 cc_library_shared { 82 name: "sdkmember", 83 srcs: ["Test.cpp"], 84 stl: "none", 85 } 86 `) 87 88 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile() 89 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile() 90 91 var inputs []string 92 buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests() 93 for _, bp := range buildParams { 94 if bp.Input != nil { 95 inputs = append(inputs, bp.Input.String()) 96 } 97 } 98 99 // ensure that both 32/64 outputs are inputs of the sdk snapshot 100 ensureListContains(t, inputs, armOutput.String()) 101 ensureListContains(t, inputs, arm64Output.String()) 102} 103 104func TestSdkCompileMultilibOverride(t *testing.T) { 105 result := testSdkWithCc(t, ` 106 sdk { 107 name: "mysdk", 108 host_supported: true, 109 native_shared_libs: ["sdkmember"], 110 compile_multilib: "64", 111 } 112 113 cc_library_shared { 114 name: "sdkmember", 115 host_supported: true, 116 srcs: ["Test.cpp"], 117 stl: "none", 118 compile_multilib: "64", 119 } 120 `) 121 122 CheckSnapshot(t, result, "mysdk", "", 123 checkAndroidBpContents(` 124// This is auto-generated. DO NOT EDIT. 125 126apex_contributions_defaults { 127 name: "mysdk.contributions", 128 contents: ["prebuilt_sdkmember"], 129} 130 131cc_prebuilt_library_shared { 132 name: "sdkmember", 133 prefer: false, 134 visibility: ["//visibility:public"], 135 apex_available: ["//apex_available:platform"], 136 host_supported: true, 137 stl: "none", 138 compile_multilib: "64", 139 target: { 140 host: { 141 enabled: false, 142 }, 143 android_arm64: { 144 srcs: ["android/arm64/lib/sdkmember.so"], 145 }, 146 linux_glibc_x86_64: { 147 enabled: true, 148 srcs: ["linux_glibc/x86_64/lib/sdkmember.so"], 149 }, 150 }, 151 strip: { 152 none: true, 153 }, 154} 155`), 156 checkAllCopyRules(` 157.intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so 158.intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> linux_glibc/x86_64/lib/sdkmember.so 159`)) 160} 161 162// Make sure the sdk can use host specific cc libraries static/shared and both. 163func TestHostSdkWithCc(t *testing.T) { 164 testSdkWithCc(t, ` 165 sdk { 166 name: "mysdk", 167 device_supported: false, 168 host_supported: true, 169 native_shared_libs: ["sdkshared"], 170 native_static_libs: ["sdkstatic"], 171 } 172 173 cc_library_host_shared { 174 name: "sdkshared", 175 stl: "none", 176 } 177 178 cc_library_host_static { 179 name: "sdkstatic", 180 stl: "none", 181 } 182 `) 183} 184 185// Make sure the sdk can use cc libraries static/shared and both. 186func TestSdkWithCc(t *testing.T) { 187 testSdkWithCc(t, ` 188 sdk { 189 name: "mysdk", 190 native_shared_libs: ["sdkshared", "sdkboth1"], 191 native_static_libs: ["sdkstatic", "sdkboth2"], 192 } 193 194 cc_library_shared { 195 name: "sdkshared", 196 stl: "none", 197 } 198 199 cc_library_static { 200 name: "sdkstatic", 201 stl: "none", 202 } 203 204 cc_library { 205 name: "sdkboth1", 206 stl: "none", 207 } 208 209 cc_library { 210 name: "sdkboth2", 211 stl: "none", 212 } 213 `) 214} 215 216func TestSnapshotWithObject(t *testing.T) { 217 result := testSdkWithCc(t, ` 218 sdk { 219 name: "mysdk", 220 native_objects: ["crtobj"], 221 } 222 223 cc_object { 224 name: "crtobj", 225 stl: "none", 226 system_shared_libs: [], 227 sanitize: { 228 never: true, 229 }, 230 } 231 `) 232 233 CheckSnapshot(t, result, "mysdk", "", 234 checkAndroidBpContents(` 235// This is auto-generated. DO NOT EDIT. 236 237apex_contributions_defaults { 238 name: "mysdk.contributions", 239 contents: ["prebuilt_crtobj"], 240} 241 242cc_prebuilt_object { 243 name: "crtobj", 244 prefer: false, 245 visibility: ["//visibility:public"], 246 apex_available: ["//apex_available:platform"], 247 stl: "none", 248 compile_multilib: "both", 249 system_shared_libs: [], 250 sanitize: { 251 never: true, 252 }, 253 arch: { 254 arm64: { 255 srcs: ["arm64/lib/crtobj.o"], 256 }, 257 arm: { 258 srcs: ["arm/lib/crtobj.o"], 259 }, 260 }, 261} 262`), 263 checkAllCopyRules(` 264.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o 265.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o 266`), 267 ) 268} 269 270func TestSnapshotWithCcDuplicateHeaders(t *testing.T) { 271 result := testSdkWithCc(t, ` 272 sdk { 273 name: "mysdk", 274 native_shared_libs: ["mynativelib1", "mynativelib2"], 275 } 276 277 cc_library_shared { 278 name: "mynativelib1", 279 srcs: [ 280 "Test.cpp", 281 ], 282 export_include_dirs: ["myinclude"], 283 stl: "none", 284 } 285 286 cc_library_shared { 287 name: "mynativelib2", 288 srcs: [ 289 "Test.cpp", 290 ], 291 export_include_dirs: ["myinclude"], 292 stl: "none", 293 } 294 `) 295 296 CheckSnapshot(t, result, "mysdk", "", 297 checkAllCopyRules(` 298myinclude/Test.h -> include/myinclude/Test.h 299.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so 300.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so 301.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so 302.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so 303`), 304 ) 305} 306 307func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) { 308 result := testSdkWithCc(t, ` 309 sdk { 310 name: "mysdk", 311 native_shared_libs: ["mynativelib"], 312 } 313 314 cc_library_shared { 315 name: "mynativelib", 316 srcs: [ 317 "Test.cpp", 318 ], 319 generated_headers: [ 320 "generated_foo", 321 ], 322 export_generated_headers: [ 323 "generated_foo", 324 ], 325 export_include_dirs: ["myinclude"], 326 stl: "none", 327 } 328 329 genrule { 330 name: "generated_foo", 331 cmd: "generate-foo", 332 out: [ 333 "generated_foo/protos/foo/bar.h", 334 ], 335 export_include_dirs: [ 336 ".", 337 "protos", 338 ], 339 } 340 `) 341 342 // TODO(b/183322862): Remove this and fix the issue. 343 errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module source path "snapshot/include_gen/generated_foo/gen/protos" does not exist`) 344 345 CheckSnapshot(t, result, "mysdk", "", 346 checkAndroidBpContents(` 347// This is auto-generated. DO NOT EDIT. 348 349apex_contributions_defaults { 350 name: "mysdk.contributions", 351 contents: ["prebuilt_mynativelib"], 352} 353 354cc_prebuilt_library_shared { 355 name: "mynativelib", 356 prefer: false, 357 visibility: ["//visibility:public"], 358 apex_available: ["//apex_available:platform"], 359 stl: "none", 360 compile_multilib: "both", 361 export_include_dirs: [ 362 "include/myinclude", 363 "include_gen/generated_foo/gen", 364 "include_gen/generated_foo/gen/protos", 365 ], 366 arch: { 367 arm64: { 368 srcs: ["arm64/lib/mynativelib.so"], 369 }, 370 arm: { 371 srcs: ["arm/lib/mynativelib.so"], 372 }, 373 }, 374 strip: { 375 none: true, 376 }, 377} 378`), 379 checkAllCopyRules(` 380myinclude/Test.h -> include/myinclude/Test.h 381.intermediates/generated_foo/gen/generated_foo/protos/foo/bar.h -> include_gen/generated_foo/gen/generated_foo/protos/foo/bar.h 382.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so 383.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so 384`), 385 snapshotTestErrorHandler(checkSnapshotWithoutSource, errorHandler), 386 snapshotTestErrorHandler(checkSnapshotWithSourcePreferred, errorHandler), 387 snapshotTestErrorHandler(checkSnapshotPreferredWithSource, errorHandler), 388 ) 389} 390 391// Verify that when the shared library has some common and some arch specific 392// properties that the generated snapshot is optimized properly. Substruct 393// handling is tested with the sanitize clauses (but note there's a lot of 394// built-in logic in sanitize.go that can affect those flags). 395func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) { 396 result := testSdkWithCc(t, ` 397 sdk { 398 name: "mysdk", 399 native_shared_libs: ["mynativelib"], 400 } 401 402 cc_library_shared { 403 name: "mynativelib", 404 srcs: [ 405 "Test.cpp", 406 "aidl/foo/bar/Test.aidl", 407 ], 408 export_include_dirs: ["myinclude"], 409 sanitize: { 410 fuzzer: false, 411 integer_overflow: true, 412 diag: { undefined: false }, 413 }, 414 arch: { 415 arm64: { 416 export_system_include_dirs: ["arm64/include"], 417 sanitize: { 418 integer_overflow: false, 419 }, 420 }, 421 }, 422 stl: "none", 423 } 424 `) 425 426 CheckSnapshot(t, result, "mysdk", "", 427 checkAndroidBpContents(` 428// This is auto-generated. DO NOT EDIT. 429 430apex_contributions_defaults { 431 name: "mysdk.contributions", 432 contents: ["prebuilt_mynativelib"], 433} 434 435cc_prebuilt_library_shared { 436 name: "mynativelib", 437 prefer: false, 438 visibility: ["//visibility:public"], 439 apex_available: ["//apex_available:platform"], 440 stl: "none", 441 compile_multilib: "both", 442 export_include_dirs: ["include/myinclude"], 443 sanitize: { 444 fuzzer: false, 445 diag: { 446 undefined: false, 447 }, 448 }, 449 arch: { 450 arm64: { 451 srcs: ["arm64/lib/mynativelib.so"], 452 export_system_include_dirs: ["arm64/include/arm64/include"], 453 sanitize: { 454 integer_overflow: false, 455 }, 456 }, 457 arm: { 458 srcs: ["arm/lib/mynativelib.so"], 459 sanitize: { 460 integer_overflow: true, 461 }, 462 }, 463 }, 464 strip: { 465 none: true, 466 }, 467} 468`), 469 checkAllCopyRules(` 470myinclude/Test.h -> include/myinclude/Test.h 471.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so 472arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h 473.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`), 474 ) 475} 476 477func TestSnapshotWithCcBinary(t *testing.T) { 478 result := testSdkWithCc(t, ` 479 module_exports { 480 name: "mymodule_exports", 481 native_binaries: ["mynativebinary"], 482 } 483 484 cc_binary { 485 name: "mynativebinary", 486 srcs: [ 487 "Test.cpp", 488 ], 489 compile_multilib: "both", 490 } 491 `) 492 493 CheckSnapshot(t, result, "mymodule_exports", "", 494 checkAndroidBpContents(` 495// This is auto-generated. DO NOT EDIT. 496 497apex_contributions_defaults { 498 name: "mymodule_exports.contributions", 499 contents: ["prebuilt_mynativebinary"], 500} 501 502cc_prebuilt_binary { 503 name: "mynativebinary", 504 prefer: false, 505 visibility: ["//visibility:public"], 506 apex_available: ["//apex_available:platform"], 507 compile_multilib: "both", 508 arch: { 509 arm64: { 510 srcs: ["arm64/bin/mynativebinary"], 511 }, 512 arm: { 513 srcs: ["arm/bin/mynativebinary"], 514 }, 515 }, 516} 517`), 518 checkAllCopyRules(` 519.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary 520.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary 521`), 522 ) 523} 524 525func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) { 526 result := testSdkWithCc(t, ` 527 module_exports { 528 name: "myexports", 529 device_supported: false, 530 host_supported: true, 531 native_binaries: ["mynativebinary"], 532 target: { 533 windows: { 534 enabled: true, 535 }, 536 }, 537 } 538 539 cc_binary { 540 name: "mynativebinary", 541 device_supported: false, 542 host_supported: true, 543 srcs: [ 544 "Test.cpp", 545 ], 546 compile_multilib: "both", 547 stl: "none", 548 target: { 549 windows: { 550 enabled: true, 551 }, 552 }, 553 } 554 `) 555 556 CheckSnapshot(t, result, "myexports", "", 557 checkAndroidBpContents(` 558// This is auto-generated. DO NOT EDIT. 559 560apex_contributions_defaults { 561 name: "myexports.contributions", 562 contents: ["prebuilt_mynativebinary"], 563} 564 565cc_prebuilt_binary { 566 name: "mynativebinary", 567 prefer: false, 568 visibility: ["//visibility:public"], 569 apex_available: ["//apex_available:platform"], 570 device_supported: false, 571 host_supported: true, 572 stl: "none", 573 target: { 574 host: { 575 enabled: false, 576 }, 577 linux_glibc: { 578 compile_multilib: "both", 579 }, 580 linux_glibc_x86_64: { 581 enabled: true, 582 srcs: ["linux_glibc/x86_64/bin/mynativebinary"], 583 }, 584 linux_glibc_x86: { 585 enabled: true, 586 srcs: ["linux_glibc/x86/bin/mynativebinary"], 587 }, 588 windows: { 589 compile_multilib: "64", 590 }, 591 windows_x86_64: { 592 enabled: true, 593 srcs: ["windows/x86_64/bin/mynativebinary.exe"], 594 }, 595 }, 596} 597`), 598 checkAllCopyRules(` 599.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary 600.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary 601.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe 602`), 603 ) 604} 605 606func TestSnapshotWithSingleHostOsType(t *testing.T) { 607 result := android.GroupFixturePreparers( 608 prepareForSdkTest, 609 ccTestFs.AddToFixture(), 610 cc.PrepareForTestOnLinuxBionic, 611 android.FixtureModifyConfig(func(config android.Config) { 612 config.Targets[android.LinuxBionic] = []android.Target{ 613 {android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false}, 614 } 615 }), 616 ).RunTestWithBp(t, ` 617 cc_defaults { 618 name: "mydefaults", 619 device_supported: false, 620 host_supported: true, 621 compile_multilib: "64", 622 target: { 623 host: { 624 enabled: false, 625 }, 626 linux_bionic: { 627 enabled: true, 628 }, 629 }, 630 } 631 632 module_exports { 633 name: "myexports", 634 defaults: ["mydefaults"], 635 native_shared_libs: ["mynativelib"], 636 native_binaries: ["mynativebinary"], 637 compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults. 638 } 639 640 cc_library { 641 name: "mynativelib", 642 defaults: ["mydefaults"], 643 srcs: [ 644 "Test.cpp", 645 ], 646 stl: "none", 647 } 648 649 cc_binary { 650 name: "mynativebinary", 651 defaults: ["mydefaults"], 652 srcs: [ 653 "Test.cpp", 654 ], 655 stl: "none", 656 } 657 `) 658 659 CheckSnapshot(t, result, "myexports", "", 660 checkAndroidBpContents(` 661// This is auto-generated. DO NOT EDIT. 662 663apex_contributions_defaults { 664 name: "myexports.contributions", 665 contents: [ 666 "prebuilt_mynativebinary", 667 "prebuilt_mynativelib", 668 ], 669} 670 671cc_prebuilt_binary { 672 name: "mynativebinary", 673 prefer: false, 674 visibility: ["//visibility:public"], 675 apex_available: ["//apex_available:platform"], 676 device_supported: false, 677 host_supported: true, 678 stl: "none", 679 compile_multilib: "64", 680 target: { 681 host: { 682 enabled: false, 683 }, 684 linux_bionic_x86_64: { 685 enabled: true, 686 srcs: ["x86_64/bin/mynativebinary"], 687 }, 688 }, 689} 690 691cc_prebuilt_library_shared { 692 name: "mynativelib", 693 prefer: false, 694 visibility: ["//visibility:public"], 695 apex_available: ["//apex_available:platform"], 696 device_supported: false, 697 host_supported: true, 698 stl: "none", 699 compile_multilib: "64", 700 target: { 701 host: { 702 enabled: false, 703 }, 704 linux_bionic_x86_64: { 705 enabled: true, 706 srcs: ["x86_64/lib/mynativelib.so"], 707 }, 708 }, 709 strip: { 710 none: true, 711 }, 712} 713`), 714 checkAllCopyRules(` 715.intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary 716.intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so 717`), 718 ) 719} 720 721// Test that we support the necessary flags for the linker binary, which is 722// special in several ways. 723func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) { 724 result := testSdkWithCc(t, ` 725 module_exports { 726 name: "mymodule_exports", 727 host_supported: true, 728 device_supported: false, 729 native_binaries: ["linker"], 730 } 731 732 cc_binary { 733 name: "linker", 734 host_supported: true, 735 static_executable: true, 736 nocrt: true, 737 stl: "none", 738 srcs: [ 739 "Test.cpp", 740 ], 741 compile_multilib: "both", 742 } 743 `) 744 745 CheckSnapshot(t, result, "mymodule_exports", "", 746 checkAndroidBpContents(` 747// This is auto-generated. DO NOT EDIT. 748 749apex_contributions_defaults { 750 name: "mymodule_exports.contributions", 751 contents: ["prebuilt_linker"], 752} 753 754cc_prebuilt_binary { 755 name: "linker", 756 prefer: false, 757 visibility: ["//visibility:public"], 758 apex_available: ["//apex_available:platform"], 759 device_supported: false, 760 host_supported: true, 761 stl: "none", 762 compile_multilib: "both", 763 static_executable: true, 764 nocrt: true, 765 target: { 766 host: { 767 enabled: false, 768 }, 769 linux_glibc_x86_64: { 770 enabled: true, 771 srcs: ["x86_64/bin/linker"], 772 }, 773 linux_glibc_x86: { 774 enabled: true, 775 srcs: ["x86/bin/linker"], 776 }, 777 }, 778} 779`), 780 checkAllCopyRules(` 781.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker 782.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker 783`), 784 ) 785} 786 787func TestSnapshotWithCcSharedLibrary(t *testing.T) { 788 result := testSdkWithCc(t, ` 789 sdk { 790 name: "mysdk", 791 native_shared_libs: ["mynativelib"], 792 } 793 794 cc_library_shared { 795 name: "mynativelib", 796 srcs: [ 797 "Test.cpp", 798 "aidl/foo/bar/Test.aidl", 799 ], 800 apex_available: ["apex1", "apex2"], 801 export_include_dirs: ["myinclude"], 802 aidl: { 803 export_aidl_headers: true, 804 }, 805 stl: "none", 806 } 807 `) 808 809 CheckSnapshot(t, result, "mysdk", "", 810 checkAndroidBpContents(` 811// This is auto-generated. DO NOT EDIT. 812 813apex_contributions_defaults { 814 name: "mysdk.contributions", 815 contents: ["prebuilt_mynativelib"], 816} 817 818cc_prebuilt_library_shared { 819 name: "mynativelib", 820 prefer: false, 821 visibility: ["//visibility:public"], 822 apex_available: [ 823 "apex1", 824 "apex2", 825 ], 826 stl: "none", 827 compile_multilib: "both", 828 export_include_dirs: ["include/myinclude"], 829 arch: { 830 arm64: { 831 srcs: ["arm64/lib/mynativelib.so"], 832 export_include_dirs: ["arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl"], 833 }, 834 arm: { 835 srcs: ["arm/lib/mynativelib.so"], 836 export_include_dirs: ["arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl"], 837 }, 838 }, 839 strip: { 840 none: true, 841 }, 842} 843`), 844 checkAllCopyRules(` 845myinclude/Test.h -> include/myinclude/Test.h 846.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so 847.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h 848.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h 849.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h 850.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so 851.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h 852.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h 853.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h 854`), 855 ) 856} 857 858func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) { 859 result := testSdkWithCc(t, ` 860 sdk { 861 name: "mysdk", 862 native_shared_libs: [ 863 "mynativelib", 864 "myothernativelib", 865 "mysystemnativelib", 866 ], 867 } 868 869 cc_library { 870 name: "mysystemnativelib", 871 srcs: [ 872 "Test.cpp", 873 ], 874 stl: "none", 875 } 876 877 cc_library_shared { 878 name: "myothernativelib", 879 srcs: [ 880 "Test.cpp", 881 ], 882 system_shared_libs: [ 883 // A reference to a library that is not an sdk member. Uses libm as that 884 // is in the default set of modules available to this test and so is available 885 // both here and also when the generated Android.bp file is tested in 886 // CheckSnapshot(). This ensures that the system_shared_libs property correctly 887 // handles references to modules that are not sdk members. 888 "libm", 889 ], 890 stl: "none", 891 } 892 893 cc_library { 894 name: "mynativelib", 895 srcs: [ 896 "Test.cpp", 897 ], 898 shared_libs: [ 899 // A reference to another sdk member. 900 "myothernativelib", 901 ], 902 target: { 903 android: { 904 shared: { 905 shared_libs: [ 906 // A reference to a library that is not an sdk member. The libc library 907 // is used here to check that the shared_libs property is handled correctly 908 // in a similar way to how libm is used to check system_shared_libs above. 909 "libc", 910 ], 911 }, 912 }, 913 }, 914 stl: "none", 915 } 916 `) 917 918 CheckSnapshot(t, result, "mysdk", "", 919 checkAndroidBpContents(` 920// This is auto-generated. DO NOT EDIT. 921 922apex_contributions_defaults { 923 name: "mysdk.contributions", 924 contents: [ 925 "prebuilt_mynativelib", 926 "prebuilt_myothernativelib", 927 "prebuilt_mysystemnativelib", 928 ], 929} 930 931cc_prebuilt_library_shared { 932 name: "mynativelib", 933 prefer: false, 934 visibility: ["//visibility:public"], 935 apex_available: ["//apex_available:platform"], 936 stl: "none", 937 compile_multilib: "both", 938 shared_libs: [ 939 "myothernativelib", 940 "libc", 941 ], 942 arch: { 943 arm64: { 944 srcs: ["arm64/lib/mynativelib.so"], 945 }, 946 arm: { 947 srcs: ["arm/lib/mynativelib.so"], 948 }, 949 }, 950 strip: { 951 none: true, 952 }, 953} 954 955cc_prebuilt_library_shared { 956 name: "myothernativelib", 957 prefer: false, 958 visibility: ["//visibility:public"], 959 apex_available: ["//apex_available:platform"], 960 stl: "none", 961 compile_multilib: "both", 962 system_shared_libs: ["libm"], 963 arch: { 964 arm64: { 965 srcs: ["arm64/lib/myothernativelib.so"], 966 }, 967 arm: { 968 srcs: ["arm/lib/myothernativelib.so"], 969 }, 970 }, 971 strip: { 972 none: true, 973 }, 974} 975 976cc_prebuilt_library_shared { 977 name: "mysystemnativelib", 978 prefer: false, 979 visibility: ["//visibility:public"], 980 apex_available: ["//apex_available:platform"], 981 stl: "none", 982 compile_multilib: "both", 983 arch: { 984 arm64: { 985 srcs: ["arm64/lib/mysystemnativelib.so"], 986 }, 987 arm: { 988 srcs: ["arm/lib/mysystemnativelib.so"], 989 }, 990 }, 991 strip: { 992 none: true, 993 }, 994} 995`), 996 checkAllCopyRules(` 997.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so 998.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so 999.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so 1000.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so 1001.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so 1002.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so 1003`), 1004 ) 1005} 1006 1007func TestHostSnapshotWithCcSharedLibrary(t *testing.T) { 1008 result := testSdkWithCc(t, ` 1009 sdk { 1010 name: "mysdk", 1011 device_supported: false, 1012 host_supported: true, 1013 native_shared_libs: ["mynativelib"], 1014 } 1015 1016 cc_library_shared { 1017 name: "mynativelib", 1018 device_supported: false, 1019 host_supported: true, 1020 srcs: [ 1021 "Test.cpp", 1022 "aidl/foo/bar/Test.aidl", 1023 ], 1024 export_include_dirs: ["myinclude"], 1025 aidl: { 1026 export_aidl_headers: true, 1027 }, 1028 stl: "none", 1029 sdk_version: "minimum", 1030 } 1031 `) 1032 1033 CheckSnapshot(t, result, "mysdk", "", 1034 checkAndroidBpContents(` 1035// This is auto-generated. DO NOT EDIT. 1036 1037apex_contributions_defaults { 1038 name: "mysdk.contributions", 1039 contents: ["prebuilt_mynativelib"], 1040} 1041 1042cc_prebuilt_library_shared { 1043 name: "mynativelib", 1044 prefer: false, 1045 visibility: ["//visibility:public"], 1046 apex_available: ["//apex_available:platform"], 1047 device_supported: false, 1048 host_supported: true, 1049 sdk_version: "minimum", 1050 stl: "none", 1051 compile_multilib: "both", 1052 export_include_dirs: ["include/myinclude"], 1053 target: { 1054 host: { 1055 enabled: false, 1056 }, 1057 linux_glibc_x86_64: { 1058 enabled: true, 1059 srcs: ["x86_64/lib/mynativelib.so"], 1060 export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl"], 1061 }, 1062 linux_glibc_x86: { 1063 enabled: true, 1064 srcs: ["x86/lib/mynativelib.so"], 1065 export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl"], 1066 }, 1067 }, 1068 strip: { 1069 none: true, 1070 }, 1071} 1072`), 1073 checkAllCopyRules(` 1074myinclude/Test.h -> include/myinclude/Test.h 1075.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so 1076.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h 1077.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h 1078.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h 1079.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so 1080.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h 1081.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h 1082.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h 1083`), 1084 ) 1085} 1086 1087func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) { 1088 result := testSdkWithCc(t, ` 1089 sdk { 1090 name: "mysdk", 1091 device_supported: false, 1092 host_supported: true, 1093 native_shared_libs: ["mynativelib"], 1094 target: { 1095 windows: { 1096 enabled: true, 1097 }, 1098 }, 1099 } 1100 1101 cc_library_shared { 1102 name: "mynativelib", 1103 device_supported: false, 1104 host_supported: true, 1105 srcs: [ 1106 "Test.cpp", 1107 ], 1108 stl: "none", 1109 target: { 1110 windows: { 1111 enabled: true, 1112 }, 1113 }, 1114 } 1115 `) 1116 1117 CheckSnapshot(t, result, "mysdk", "", 1118 checkAndroidBpContents(` 1119// This is auto-generated. DO NOT EDIT. 1120 1121apex_contributions_defaults { 1122 name: "mysdk.contributions", 1123 contents: ["prebuilt_mynativelib"], 1124} 1125 1126cc_prebuilt_library_shared { 1127 name: "mynativelib", 1128 prefer: false, 1129 visibility: ["//visibility:public"], 1130 apex_available: ["//apex_available:platform"], 1131 device_supported: false, 1132 host_supported: true, 1133 stl: "none", 1134 target: { 1135 host: { 1136 enabled: false, 1137 }, 1138 linux_glibc: { 1139 compile_multilib: "both", 1140 }, 1141 linux_glibc_x86_64: { 1142 enabled: true, 1143 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], 1144 }, 1145 linux_glibc_x86: { 1146 enabled: true, 1147 srcs: ["linux_glibc/x86/lib/mynativelib.so"], 1148 }, 1149 windows: { 1150 compile_multilib: "64", 1151 }, 1152 windows_x86_64: { 1153 enabled: true, 1154 srcs: ["windows/x86_64/lib/mynativelib.dll"], 1155 }, 1156 }, 1157 strip: { 1158 none: true, 1159 }, 1160} 1161`), 1162 checkAllCopyRules(` 1163.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so 1164.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so 1165.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll 1166`), 1167 ) 1168} 1169 1170func TestSnapshotWithCcStaticLibrary(t *testing.T) { 1171 result := testSdkWithCc(t, ` 1172 module_exports { 1173 name: "myexports", 1174 native_static_libs: ["mynativelib"], 1175 } 1176 1177 cc_library_static { 1178 name: "mynativelib", 1179 srcs: [ 1180 "Test.cpp", 1181 "aidl/foo/bar/Test.aidl", 1182 ], 1183 export_include_dirs: ["myinclude"], 1184 aidl: { 1185 export_aidl_headers: true, 1186 }, 1187 stl: "none", 1188 } 1189 `) 1190 1191 CheckSnapshot(t, result, "myexports", "", 1192 checkAndroidBpContents(` 1193// This is auto-generated. DO NOT EDIT. 1194 1195apex_contributions_defaults { 1196 name: "myexports.contributions", 1197 contents: ["prebuilt_mynativelib"], 1198} 1199 1200cc_prebuilt_library_static { 1201 name: "mynativelib", 1202 prefer: false, 1203 visibility: ["//visibility:public"], 1204 apex_available: ["//apex_available:platform"], 1205 stl: "none", 1206 compile_multilib: "both", 1207 export_include_dirs: ["include/myinclude"], 1208 arch: { 1209 arm64: { 1210 srcs: ["arm64/lib/mynativelib.a"], 1211 export_include_dirs: ["arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl"], 1212 }, 1213 arm: { 1214 srcs: ["arm/lib/mynativelib.a"], 1215 export_include_dirs: ["arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl"], 1216 }, 1217 }, 1218} 1219`), 1220 checkAllCopyRules(` 1221myinclude/Test.h -> include/myinclude/Test.h 1222.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a 1223.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h 1224.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h 1225.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h 1226.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a 1227.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h 1228.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h 1229.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h 1230`), 1231 ) 1232} 1233 1234func TestHostSnapshotWithCcStaticLibrary(t *testing.T) { 1235 result := testSdkWithCc(t, ` 1236 module_exports { 1237 name: "myexports", 1238 device_supported: false, 1239 host_supported: true, 1240 native_static_libs: ["mynativelib"], 1241 } 1242 1243 cc_library_static { 1244 name: "mynativelib", 1245 device_supported: false, 1246 host_supported: true, 1247 srcs: [ 1248 "Test.cpp", 1249 "aidl/foo/bar/Test.aidl", 1250 ], 1251 export_include_dirs: ["myinclude"], 1252 aidl: { 1253 export_aidl_headers: true, 1254 }, 1255 stl: "none", 1256 } 1257 `) 1258 1259 CheckSnapshot(t, result, "myexports", "", 1260 checkAndroidBpContents(` 1261// This is auto-generated. DO NOT EDIT. 1262 1263apex_contributions_defaults { 1264 name: "myexports.contributions", 1265 contents: ["prebuilt_mynativelib"], 1266} 1267 1268cc_prebuilt_library_static { 1269 name: "mynativelib", 1270 prefer: false, 1271 visibility: ["//visibility:public"], 1272 apex_available: ["//apex_available:platform"], 1273 device_supported: false, 1274 host_supported: true, 1275 stl: "none", 1276 compile_multilib: "both", 1277 export_include_dirs: ["include/myinclude"], 1278 target: { 1279 host: { 1280 enabled: false, 1281 }, 1282 linux_glibc_x86_64: { 1283 enabled: true, 1284 srcs: ["x86_64/lib/mynativelib.a"], 1285 export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl"], 1286 }, 1287 linux_glibc_x86: { 1288 enabled: true, 1289 srcs: ["x86/lib/mynativelib.a"], 1290 export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl"], 1291 }, 1292 }, 1293} 1294`), 1295 checkAllCopyRules(` 1296myinclude/Test.h -> include/myinclude/Test.h 1297.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a 1298.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h 1299.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h 1300.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h 1301.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a 1302.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h 1303.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h 1304.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h 1305`), 1306 ) 1307} 1308 1309func TestSnapshotWithCcLibrary(t *testing.T) { 1310 result := testSdkWithCc(t, ` 1311 module_exports { 1312 name: "myexports", 1313 native_libs: ["mynativelib"], 1314 } 1315 1316 cc_library { 1317 name: "mynativelib", 1318 srcs: [ 1319 "Test.cpp", 1320 ], 1321 export_include_dirs: ["myinclude"], 1322 stl: "none", 1323 recovery_available: true, 1324 vendor_available: true, 1325 } 1326 `) 1327 1328 CheckSnapshot(t, result, "myexports", "", 1329 checkAndroidBpContents(` 1330// This is auto-generated. DO NOT EDIT. 1331 1332apex_contributions_defaults { 1333 name: "myexports.contributions", 1334 contents: ["prebuilt_mynativelib"], 1335} 1336 1337cc_prebuilt_library { 1338 name: "mynativelib", 1339 prefer: false, 1340 visibility: ["//visibility:public"], 1341 apex_available: ["//apex_available:platform"], 1342 vendor_available: true, 1343 stl: "none", 1344 compile_multilib: "both", 1345 export_include_dirs: ["include/myinclude"], 1346 arch: { 1347 arm64: { 1348 static: { 1349 srcs: ["arm64/lib/mynativelib.a"], 1350 }, 1351 shared: { 1352 srcs: ["arm64/lib/mynativelib.so"], 1353 }, 1354 }, 1355 arm: { 1356 static: { 1357 srcs: ["arm/lib/mynativelib.a"], 1358 }, 1359 shared: { 1360 srcs: ["arm/lib/mynativelib.so"], 1361 }, 1362 }, 1363 }, 1364} 1365`), 1366 checkAllCopyRules(` 1367myinclude/Test.h -> include/myinclude/Test.h 1368.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a 1369.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so 1370.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a 1371.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so 1372`), 1373 // TODO(b/183315522): Remove this and fix the issue. 1374 snapshotTestErrorHandler(checkSnapshotPreferredWithSource, android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\Qunrecognized property "arch.arm.shared.export_include_dirs"\E`)), 1375 ) 1376} 1377 1378func TestSnapshotSameLibraryWithNativeLibsAndNativeSharedLib(t *testing.T) { 1379 result := testSdkWithCc(t, ` 1380 module_exports { 1381 host_supported: true, 1382 name: "myexports", 1383 target: { 1384 android: { 1385 native_shared_libs: [ 1386 "mynativelib", 1387 ], 1388 }, 1389 not_windows: { 1390 native_libs: [ 1391 "mynativelib", 1392 ], 1393 }, 1394 }, 1395 } 1396 1397 cc_library { 1398 name: "mynativelib", 1399 host_supported: true, 1400 srcs: [ 1401 "Test.cpp", 1402 ], 1403 stl: "none", 1404 recovery_available: true, 1405 vendor_available: true, 1406 } 1407 `) 1408 1409 CheckSnapshot(t, result, "myexports", "", 1410 checkAndroidBpContents(` 1411// This is auto-generated. DO NOT EDIT. 1412 1413apex_contributions_defaults { 1414 name: "myexports.contributions", 1415 contents: ["prebuilt_mynativelib"], 1416} 1417 1418cc_prebuilt_library { 1419 name: "mynativelib", 1420 prefer: false, 1421 visibility: ["//visibility:public"], 1422 apex_available: ["//apex_available:platform"], 1423 host_supported: true, 1424 vendor_available: true, 1425 stl: "none", 1426 compile_multilib: "both", 1427 target: { 1428 host: { 1429 enabled: false, 1430 }, 1431 android_arm64: { 1432 shared: { 1433 srcs: ["android/arm64/lib/mynativelib.so"], 1434 }, 1435 static: { 1436 enabled: false, 1437 }, 1438 }, 1439 android_arm: { 1440 shared: { 1441 srcs: ["android/arm/lib/mynativelib.so"], 1442 }, 1443 static: { 1444 enabled: false, 1445 }, 1446 }, 1447 linux_glibc_x86_64: { 1448 enabled: true, 1449 static: { 1450 srcs: ["linux_glibc/x86_64/lib/mynativelib.a"], 1451 }, 1452 shared: { 1453 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], 1454 }, 1455 }, 1456 linux_glibc_x86: { 1457 enabled: true, 1458 static: { 1459 srcs: ["linux_glibc/x86/lib/mynativelib.a"], 1460 }, 1461 shared: { 1462 srcs: ["linux_glibc/x86/lib/mynativelib.so"], 1463 }, 1464 }, 1465 }, 1466} 1467`), 1468 checkAllCopyRules(` 1469.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> android/arm64/lib/mynativelib.so 1470.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> android/arm/lib/mynativelib.so 1471.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> linux_glibc/x86_64/lib/mynativelib.a 1472.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so 1473.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> linux_glibc/x86/lib/mynativelib.a 1474.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so 1475`), 1476 ) 1477} 1478 1479func TestSnapshotSameLibraryWithAndroidNativeLibsAndHostNativeSharedLib(t *testing.T) { 1480 result := testSdkWithCc(t, ` 1481 module_exports { 1482 host_supported: true, 1483 name: "myexports", 1484 target: { 1485 android: { 1486 native_libs: [ 1487 "mynativelib", 1488 ], 1489 }, 1490 not_windows: { 1491 native_shared_libs: [ 1492 "mynativelib", 1493 ], 1494 }, 1495 }, 1496 } 1497 1498 cc_library { 1499 name: "mynativelib", 1500 host_supported: true, 1501 srcs: [ 1502 "Test.cpp", 1503 ], 1504 stl: "none", 1505 recovery_available: true, 1506 vendor_available: true, 1507 } 1508 `) 1509 1510 CheckSnapshot(t, result, "myexports", "", 1511 checkAndroidBpContents(` 1512// This is auto-generated. DO NOT EDIT. 1513 1514apex_contributions_defaults { 1515 name: "myexports.contributions", 1516 contents: ["prebuilt_mynativelib"], 1517} 1518 1519cc_prebuilt_library { 1520 name: "mynativelib", 1521 prefer: false, 1522 visibility: ["//visibility:public"], 1523 apex_available: ["//apex_available:platform"], 1524 host_supported: true, 1525 vendor_available: true, 1526 stl: "none", 1527 compile_multilib: "both", 1528 target: { 1529 host: { 1530 enabled: false, 1531 }, 1532 android_arm64: { 1533 static: { 1534 srcs: ["android/arm64/lib/mynativelib.a"], 1535 }, 1536 shared: { 1537 srcs: ["android/arm64/lib/mynativelib.so"], 1538 }, 1539 }, 1540 android_arm: { 1541 static: { 1542 srcs: ["android/arm/lib/mynativelib.a"], 1543 }, 1544 shared: { 1545 srcs: ["android/arm/lib/mynativelib.so"], 1546 }, 1547 }, 1548 linux_glibc_x86_64: { 1549 enabled: true, 1550 shared: { 1551 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"], 1552 }, 1553 static: { 1554 enabled: false, 1555 }, 1556 }, 1557 linux_glibc_x86: { 1558 enabled: true, 1559 shared: { 1560 srcs: ["linux_glibc/x86/lib/mynativelib.so"], 1561 }, 1562 static: { 1563 enabled: false, 1564 }, 1565 }, 1566 }, 1567} 1568`), 1569 checkAllCopyRules(` 1570.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> android/arm64/lib/mynativelib.a 1571.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> android/arm64/lib/mynativelib.so 1572.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> android/arm/lib/mynativelib.a 1573.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> android/arm/lib/mynativelib.so 1574.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so 1575.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so 1576`), 1577 ) 1578} 1579 1580func TestSnapshotSameLibraryWithNativeStaticLibsAndNativeSharedLib(t *testing.T) { 1581 testSdkError(t, "Incompatible member types", ` 1582 module_exports { 1583 host_supported: true, 1584 name: "myexports", 1585 target: { 1586 android: { 1587 native_shared_libs: [ 1588 "mynativelib", 1589 ], 1590 }, 1591 not_windows: { 1592 native_static_libs: [ 1593 "mynativelib", 1594 ], 1595 }, 1596 }, 1597 } 1598 1599 cc_library { 1600 name: "mynativelib", 1601 host_supported: true, 1602 srcs: [ 1603 ], 1604 stl: "none", 1605 recovery_available: true, 1606 vendor_available: true, 1607 } 1608 `) 1609} 1610 1611func TestHostSnapshotWithMultiLib64(t *testing.T) { 1612 result := testSdkWithCc(t, ` 1613 module_exports { 1614 name: "myexports", 1615 device_supported: false, 1616 host_supported: true, 1617 target: { 1618 host: { 1619 compile_multilib: "64", 1620 }, 1621 }, 1622 native_static_libs: ["mynativelib"], 1623 } 1624 1625 cc_library_static { 1626 name: "mynativelib", 1627 device_supported: false, 1628 host_supported: true, 1629 srcs: [ 1630 "Test.cpp", 1631 "aidl/foo/bar/Test.aidl", 1632 ], 1633 export_include_dirs: ["myinclude"], 1634 aidl: { 1635 export_aidl_headers: true, 1636 }, 1637 stl: "none", 1638 } 1639 `) 1640 1641 CheckSnapshot(t, result, "myexports", "", 1642 checkAndroidBpContents(` 1643// This is auto-generated. DO NOT EDIT. 1644 1645apex_contributions_defaults { 1646 name: "myexports.contributions", 1647 contents: ["prebuilt_mynativelib"], 1648} 1649 1650cc_prebuilt_library_static { 1651 name: "mynativelib", 1652 prefer: false, 1653 visibility: ["//visibility:public"], 1654 apex_available: ["//apex_available:platform"], 1655 device_supported: false, 1656 host_supported: true, 1657 stl: "none", 1658 compile_multilib: "64", 1659 export_include_dirs: [ 1660 "include/myinclude", 1661 "include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl", 1662 ], 1663 target: { 1664 host: { 1665 enabled: false, 1666 }, 1667 linux_glibc_x86_64: { 1668 enabled: true, 1669 srcs: ["x86_64/lib/mynativelib.a"], 1670 }, 1671 }, 1672} 1673`), 1674 checkAllCopyRules(` 1675myinclude/Test.h -> include/myinclude/Test.h 1676.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h 1677.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h 1678.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h 1679.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a 1680`), 1681 ) 1682} 1683 1684func TestSnapshotWithCcHeadersLibrary(t *testing.T) { 1685 result := testSdkWithCc(t, ` 1686 sdk { 1687 name: "mysdk", 1688 native_header_libs: ["mynativeheaders"], 1689 } 1690 1691 cc_library_headers { 1692 name: "mynativeheaders", 1693 export_include_dirs: ["myinclude"], 1694 stl: "none", 1695 } 1696 `) 1697 1698 CheckSnapshot(t, result, "mysdk", "", 1699 checkAndroidBpContents(` 1700// This is auto-generated. DO NOT EDIT. 1701 1702apex_contributions_defaults { 1703 name: "mysdk.contributions", 1704 contents: ["prebuilt_mynativeheaders"], 1705} 1706 1707cc_prebuilt_library_headers { 1708 name: "mynativeheaders", 1709 prefer: false, 1710 visibility: ["//visibility:public"], 1711 apex_available: ["//apex_available:platform"], 1712 stl: "none", 1713 compile_multilib: "both", 1714 export_include_dirs: ["include/myinclude"], 1715} 1716`), 1717 checkAllCopyRules(` 1718myinclude/Test.h -> include/myinclude/Test.h 1719`), 1720 ) 1721} 1722 1723func TestSnapshotWithCcHeadersLibraryAndNativeBridgeSupport(t *testing.T) { 1724 result := android.GroupFixturePreparers( 1725 cc.PrepareForTestWithCcDefaultModules, 1726 PrepareForTestWithSdkBuildComponents, 1727 ccTestFs.AddToFixture(), 1728 prepareForTestWithNativeBridgeTarget, 1729 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { 1730 android.RegisterApexContributionsBuildComponents(ctx) 1731 }), 1732 ).RunTestWithBp(t, ` 1733 sdk { 1734 name: "mysdk", 1735 native_header_libs: ["mynativeheaders"], 1736 traits: { 1737 native_bridge_support: ["mynativeheaders"], 1738 }, 1739 } 1740 1741 cc_library_headers { 1742 name: "mynativeheaders", 1743 export_include_dirs: ["myinclude"], 1744 stl: "none", 1745 system_shared_libs: [], 1746 native_bridge_supported: true, 1747 } 1748 `) 1749 1750 CheckSnapshot(t, result, "mysdk", "", 1751 checkAndroidBpContents(` 1752// This is auto-generated. DO NOT EDIT. 1753 1754apex_contributions_defaults { 1755 name: "mysdk.contributions", 1756 contents: ["prebuilt_mynativeheaders"], 1757} 1758 1759cc_prebuilt_library_headers { 1760 name: "mynativeheaders", 1761 prefer: false, 1762 visibility: ["//visibility:public"], 1763 apex_available: ["//apex_available:platform"], 1764 native_bridge_supported: true, 1765 stl: "none", 1766 compile_multilib: "both", 1767 system_shared_libs: [], 1768 export_include_dirs: ["include/myinclude"], 1769} 1770`), 1771 checkAllCopyRules(` 1772myinclude/Test.h -> include/myinclude/Test.h 1773`), 1774 ) 1775} 1776 1777// TestSnapshotWithCcHeadersLibrary_DetectsNativeBridgeSpecificProperties verifies that when a 1778// module that has different output files for a native bridge target requests the native bridge 1779// variants are copied into the sdk snapshot that it reports an error. 1780func TestSnapshotWithCcHeadersLibrary_DetectsNativeBridgeSpecificProperties(t *testing.T) { 1781 android.GroupFixturePreparers( 1782 cc.PrepareForTestWithCcDefaultModules, 1783 PrepareForTestWithSdkBuildComponents, 1784 ccTestFs.AddToFixture(), 1785 prepareForTestWithNativeBridgeTarget, 1786 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( 1787 `\QArchitecture variant "arm64_native_bridge" of sdk member "mynativeheaders" has properties distinct from other variants; this is not yet supported. The properties are: 1788 export_include_dirs: [ 1789 "arm64_native_bridge/include/myinclude_nativebridge", 1790 "arm64_native_bridge/include/myinclude", 1791 ],\E`)). 1792 RunTestWithBp(t, ` 1793 sdk { 1794 name: "mysdk", 1795 native_header_libs: ["mynativeheaders"], 1796 traits: { 1797 native_bridge_support: ["mynativeheaders"], 1798 }, 1799 } 1800 1801 cc_library_headers { 1802 name: "mynativeheaders", 1803 export_include_dirs: ["myinclude"], 1804 stl: "none", 1805 system_shared_libs: [], 1806 native_bridge_supported: true, 1807 target: { 1808 native_bridge: { 1809 export_include_dirs: ["myinclude_nativebridge"], 1810 }, 1811 }, 1812 } 1813 `) 1814} 1815 1816func TestSnapshotWithCcHeadersLibraryAndImageVariants(t *testing.T) { 1817 testImageVariant := func(t *testing.T, property, trait string) { 1818 result := android.GroupFixturePreparers( 1819 cc.PrepareForTestWithCcDefaultModules, 1820 PrepareForTestWithSdkBuildComponents, 1821 ccTestFs.AddToFixture(), 1822 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { 1823 android.RegisterApexContributionsBuildComponents(ctx) 1824 }), 1825 ).RunTestWithBp(t, fmt.Sprintf(` 1826 sdk { 1827 name: "mysdk", 1828 native_header_libs: ["mynativeheaders"], 1829 traits: { 1830 %s: ["mynativeheaders"], 1831 }, 1832 } 1833 1834 cc_library_headers { 1835 name: "mynativeheaders", 1836 export_include_dirs: ["myinclude"], 1837 stl: "none", 1838 system_shared_libs: [], 1839 %s: true, 1840 } 1841 `, trait, property)) 1842 1843 CheckSnapshot(t, result, "mysdk", "", 1844 checkAndroidBpContents(fmt.Sprintf(` 1845// This is auto-generated. DO NOT EDIT. 1846 1847apex_contributions_defaults { 1848 name: "mysdk.contributions", 1849 contents: ["prebuilt_mynativeheaders"], 1850} 1851 1852cc_prebuilt_library_headers { 1853 name: "mynativeheaders", 1854 prefer: false, 1855 visibility: ["//visibility:public"], 1856 apex_available: ["//apex_available:platform"], 1857 %s: true, 1858 stl: "none", 1859 compile_multilib: "both", 1860 system_shared_libs: [], 1861 export_include_dirs: ["include/myinclude"], 1862} 1863`, property)), 1864 checkAllCopyRules(` 1865myinclude/Test.h -> include/myinclude/Test.h 1866`), 1867 ) 1868 } 1869 1870 t.Run("ramdisk", func(t *testing.T) { 1871 testImageVariant(t, "ramdisk_available", "ramdisk_image_required") 1872 }) 1873 1874 t.Run("recovery", func(t *testing.T) { 1875 testImageVariant(t, "recovery_available", "recovery_image_required") 1876 }) 1877} 1878 1879func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) { 1880 result := testSdkWithCc(t, ` 1881 sdk { 1882 name: "mysdk", 1883 device_supported: false, 1884 host_supported: true, 1885 native_header_libs: ["mynativeheaders"], 1886 } 1887 1888 cc_library_headers { 1889 name: "mynativeheaders", 1890 device_supported: false, 1891 host_supported: true, 1892 export_include_dirs: ["myinclude"], 1893 stl: "none", 1894 } 1895 `) 1896 1897 CheckSnapshot(t, result, "mysdk", "", 1898 checkAndroidBpContents(` 1899// This is auto-generated. DO NOT EDIT. 1900 1901apex_contributions_defaults { 1902 name: "mysdk.contributions", 1903 contents: ["prebuilt_mynativeheaders"], 1904} 1905 1906cc_prebuilt_library_headers { 1907 name: "mynativeheaders", 1908 prefer: false, 1909 visibility: ["//visibility:public"], 1910 apex_available: ["//apex_available:platform"], 1911 device_supported: false, 1912 host_supported: true, 1913 stl: "none", 1914 compile_multilib: "both", 1915 export_include_dirs: ["include/myinclude"], 1916 target: { 1917 host: { 1918 enabled: false, 1919 }, 1920 linux_glibc_x86_64: { 1921 enabled: true, 1922 }, 1923 linux_glibc_x86: { 1924 enabled: true, 1925 }, 1926 }, 1927} 1928`), 1929 checkAllCopyRules(` 1930myinclude/Test.h -> include/myinclude/Test.h 1931`), 1932 ) 1933} 1934 1935func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) { 1936 result := testSdkWithCc(t, ` 1937 sdk { 1938 name: "mysdk", 1939 host_supported: true, 1940 native_header_libs: ["mynativeheaders"], 1941 } 1942 1943 cc_library_headers { 1944 name: "mynativeheaders", 1945 host_supported: true, 1946 stl: "none", 1947 export_system_include_dirs: ["myinclude"], 1948 target: { 1949 android: { 1950 export_include_dirs: ["myinclude-android"], 1951 }, 1952 host: { 1953 export_include_dirs: ["myinclude-host"], 1954 }, 1955 }, 1956 } 1957 `) 1958 1959 CheckSnapshot(t, result, "mysdk", "", 1960 checkAndroidBpContents(` 1961// This is auto-generated. DO NOT EDIT. 1962 1963apex_contributions_defaults { 1964 name: "mysdk.contributions", 1965 contents: ["prebuilt_mynativeheaders"], 1966} 1967 1968cc_prebuilt_library_headers { 1969 name: "mynativeheaders", 1970 prefer: false, 1971 visibility: ["//visibility:public"], 1972 apex_available: ["//apex_available:platform"], 1973 host_supported: true, 1974 stl: "none", 1975 compile_multilib: "both", 1976 export_system_include_dirs: ["common_os/include/myinclude"], 1977 target: { 1978 host: { 1979 enabled: false, 1980 }, 1981 android: { 1982 export_include_dirs: ["android/include/myinclude-android"], 1983 }, 1984 linux_glibc: { 1985 export_include_dirs: ["linux_glibc/include/myinclude-host"], 1986 }, 1987 linux_glibc_x86_64: { 1988 enabled: true, 1989 }, 1990 linux_glibc_x86: { 1991 enabled: true, 1992 }, 1993 }, 1994} 1995`), 1996 checkAllCopyRules(` 1997myinclude/Test.h -> common_os/include/myinclude/Test.h 1998myinclude-android/AndroidTest.h -> android/include/myinclude-android/AndroidTest.h 1999myinclude-host/HostTest.h -> linux_glibc/include/myinclude-host/HostTest.h 2000`), 2001 ) 2002} 2003 2004func TestSystemSharedLibPropagation(t *testing.T) { 2005 result := testSdkWithCc(t, ` 2006 sdk { 2007 name: "mysdk", 2008 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"], 2009 } 2010 2011 cc_library { 2012 name: "sslnil", 2013 host_supported: true, 2014 } 2015 2016 cc_library { 2017 name: "sslempty", 2018 system_shared_libs: [], 2019 } 2020 2021 cc_library { 2022 name: "sslnonempty", 2023 system_shared_libs: ["sslnil"], 2024 } 2025 `) 2026 2027 CheckSnapshot(t, result, "mysdk", "", 2028 checkAndroidBpContents(` 2029// This is auto-generated. DO NOT EDIT. 2030 2031apex_contributions_defaults { 2032 name: "mysdk.contributions", 2033 contents: [ 2034 "prebuilt_sslnil", 2035 "prebuilt_sslempty", 2036 "prebuilt_sslnonempty", 2037 ], 2038} 2039 2040cc_prebuilt_library_shared { 2041 name: "sslnil", 2042 prefer: false, 2043 visibility: ["//visibility:public"], 2044 apex_available: ["//apex_available:platform"], 2045 compile_multilib: "both", 2046 arch: { 2047 arm64: { 2048 srcs: ["arm64/lib/sslnil.so"], 2049 }, 2050 arm: { 2051 srcs: ["arm/lib/sslnil.so"], 2052 }, 2053 }, 2054 strip: { 2055 none: true, 2056 }, 2057} 2058 2059cc_prebuilt_library_shared { 2060 name: "sslempty", 2061 prefer: false, 2062 visibility: ["//visibility:public"], 2063 apex_available: ["//apex_available:platform"], 2064 compile_multilib: "both", 2065 system_shared_libs: [], 2066 arch: { 2067 arm64: { 2068 srcs: ["arm64/lib/sslempty.so"], 2069 }, 2070 arm: { 2071 srcs: ["arm/lib/sslempty.so"], 2072 }, 2073 }, 2074 strip: { 2075 none: true, 2076 }, 2077} 2078 2079cc_prebuilt_library_shared { 2080 name: "sslnonempty", 2081 prefer: false, 2082 visibility: ["//visibility:public"], 2083 apex_available: ["//apex_available:platform"], 2084 compile_multilib: "both", 2085 system_shared_libs: ["sslnil"], 2086 arch: { 2087 arm64: { 2088 srcs: ["arm64/lib/sslnonempty.so"], 2089 }, 2090 arm: { 2091 srcs: ["arm/lib/sslnonempty.so"], 2092 }, 2093 }, 2094 strip: { 2095 none: true, 2096 }, 2097} 2098`)) 2099 2100 result = testSdkWithCc(t, ` 2101 sdk { 2102 name: "mysdk", 2103 host_supported: true, 2104 native_shared_libs: ["sslvariants"], 2105 } 2106 2107 cc_library { 2108 name: "sslvariants", 2109 host_supported: true, 2110 target: { 2111 android: { 2112 system_shared_libs: [], 2113 }, 2114 }, 2115 } 2116 `) 2117 2118 CheckSnapshot(t, result, "mysdk", "", 2119 checkAndroidBpContents(` 2120// This is auto-generated. DO NOT EDIT. 2121 2122apex_contributions_defaults { 2123 name: "mysdk.contributions", 2124 contents: ["prebuilt_sslvariants"], 2125} 2126 2127cc_prebuilt_library_shared { 2128 name: "sslvariants", 2129 prefer: false, 2130 visibility: ["//visibility:public"], 2131 apex_available: ["//apex_available:platform"], 2132 host_supported: true, 2133 compile_multilib: "both", 2134 target: { 2135 host: { 2136 enabled: false, 2137 }, 2138 android: { 2139 system_shared_libs: [], 2140 }, 2141 android_arm64: { 2142 srcs: ["android/arm64/lib/sslvariants.so"], 2143 }, 2144 android_arm: { 2145 srcs: ["android/arm/lib/sslvariants.so"], 2146 }, 2147 linux_glibc_x86_64: { 2148 enabled: true, 2149 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"], 2150 }, 2151 linux_glibc_x86: { 2152 enabled: true, 2153 srcs: ["linux_glibc/x86/lib/sslvariants.so"], 2154 }, 2155 }, 2156 strip: { 2157 none: true, 2158 }, 2159} 2160`), 2161 ) 2162} 2163 2164func TestStubsLibrary(t *testing.T) { 2165 result := testSdkWithCc(t, ` 2166 sdk { 2167 name: "mysdk", 2168 native_shared_libs: ["stubslib"], 2169 } 2170 2171 cc_library { 2172 name: "internaldep", 2173 } 2174 2175 cc_library { 2176 name: "stubslib", 2177 shared_libs: ["internaldep"], 2178 stubs: { 2179 symbol_file: "some/where/stubslib.map.txt", 2180 versions: ["1", "2", "3"], 2181 }, 2182 } 2183 `) 2184 2185 CheckSnapshot(t, result, "mysdk", "", 2186 checkAndroidBpContents(` 2187// This is auto-generated. DO NOT EDIT. 2188 2189apex_contributions_defaults { 2190 name: "mysdk.contributions", 2191 contents: ["prebuilt_stubslib"], 2192} 2193 2194cc_prebuilt_library_shared { 2195 name: "stubslib", 2196 prefer: false, 2197 visibility: ["//visibility:public"], 2198 apex_available: ["//apex_available:platform"], 2199 stl: "none", 2200 compile_multilib: "both", 2201 stubs: { 2202 versions: [ 2203 "1", 2204 "2", 2205 "3", 2206 "current", 2207 ], 2208 symbol_file: "stubslib.map.txt", 2209 }, 2210 arch: { 2211 arm64: { 2212 srcs: ["arm64/lib/stubslib.so"], 2213 }, 2214 arm: { 2215 srcs: ["arm/lib/stubslib.so"], 2216 }, 2217 }, 2218 strip: { 2219 none: true, 2220 }, 2221} 2222`)) 2223} 2224 2225func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) { 2226 result := testSdkWithCc(t, ` 2227 sdk { 2228 name: "mysdk", 2229 host_supported: true, 2230 native_shared_libs: ["stubslib"], 2231 } 2232 2233 cc_library { 2234 name: "internaldep", 2235 host_supported: true, 2236 } 2237 2238 cc_library { 2239 name: "stubslib", 2240 host_supported: true, 2241 shared_libs: ["internaldep"], 2242 stubs: { 2243 symbol_file: "some/where/stubslib.map.txt", 2244 versions: ["1", "2", "3"], 2245 }, 2246 } 2247 `) 2248 2249 CheckSnapshot(t, result, "mysdk", "", 2250 checkAndroidBpContents(` 2251// This is auto-generated. DO NOT EDIT. 2252 2253apex_contributions_defaults { 2254 name: "mysdk.contributions", 2255 contents: ["prebuilt_stubslib"], 2256} 2257 2258cc_prebuilt_library_shared { 2259 name: "stubslib", 2260 prefer: false, 2261 visibility: ["//visibility:public"], 2262 apex_available: ["//apex_available:platform"], 2263 host_supported: true, 2264 compile_multilib: "both", 2265 stubs: { 2266 versions: [ 2267 "1", 2268 "2", 2269 "3", 2270 "current", 2271 ], 2272 symbol_file: "stubslib.map.txt", 2273 }, 2274 target: { 2275 host: { 2276 enabled: false, 2277 }, 2278 android_arm64: { 2279 srcs: ["android/arm64/lib/stubslib.so"], 2280 }, 2281 android_arm: { 2282 srcs: ["android/arm/lib/stubslib.so"], 2283 }, 2284 linux_glibc_x86_64: { 2285 enabled: true, 2286 srcs: ["linux_glibc/x86_64/lib/stubslib.so"], 2287 }, 2288 linux_glibc_x86: { 2289 enabled: true, 2290 srcs: ["linux_glibc/x86/lib/stubslib.so"], 2291 }, 2292 }, 2293 strip: { 2294 none: true, 2295 }, 2296} 2297`), 2298 ) 2299} 2300 2301func TestUniqueHostSoname(t *testing.T) { 2302 result := testSdkWithCc(t, ` 2303 sdk { 2304 name: "mysdk", 2305 host_supported: true, 2306 native_shared_libs: ["mylib"], 2307 } 2308 2309 cc_library { 2310 name: "mylib", 2311 host_supported: true, 2312 unique_host_soname: true, 2313 } 2314 `) 2315 2316 CheckSnapshot(t, result, "mysdk", "", 2317 checkAndroidBpContents(` 2318// This is auto-generated. DO NOT EDIT. 2319 2320apex_contributions_defaults { 2321 name: "mysdk.contributions", 2322 contents: ["prebuilt_mylib"], 2323} 2324 2325cc_prebuilt_library_shared { 2326 name: "mylib", 2327 prefer: false, 2328 visibility: ["//visibility:public"], 2329 apex_available: ["//apex_available:platform"], 2330 host_supported: true, 2331 unique_host_soname: true, 2332 compile_multilib: "both", 2333 target: { 2334 host: { 2335 enabled: false, 2336 }, 2337 android_arm64: { 2338 srcs: ["android/arm64/lib/mylib.so"], 2339 }, 2340 android_arm: { 2341 srcs: ["android/arm/lib/mylib.so"], 2342 }, 2343 linux_glibc_x86_64: { 2344 enabled: true, 2345 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"], 2346 }, 2347 linux_glibc_x86: { 2348 enabled: true, 2349 srcs: ["linux_glibc/x86/lib/mylib-host.so"], 2350 }, 2351 }, 2352 strip: { 2353 none: true, 2354 }, 2355} 2356`), 2357 checkAllCopyRules(` 2358.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so 2359.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so 2360.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so 2361.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so 2362`), 2363 ) 2364} 2365 2366func TestNoSanitizerMembers(t *testing.T) { 2367 result := testSdkWithCc(t, ` 2368 sdk { 2369 name: "mysdk", 2370 native_shared_libs: ["mynativelib"], 2371 } 2372 2373 cc_library_shared { 2374 name: "mynativelib", 2375 srcs: ["Test.cpp"], 2376 export_include_dirs: ["myinclude"], 2377 arch: { 2378 arm64: { 2379 export_system_include_dirs: ["arm64/include"], 2380 sanitize: { 2381 hwaddress: true, 2382 }, 2383 }, 2384 }, 2385 } 2386 `) 2387 2388 CheckSnapshot(t, result, "mysdk", "", 2389 checkAndroidBpContents(` 2390// This is auto-generated. DO NOT EDIT. 2391 2392apex_contributions_defaults { 2393 name: "mysdk.contributions", 2394 contents: ["prebuilt_mynativelib"], 2395} 2396 2397cc_prebuilt_library_shared { 2398 name: "mynativelib", 2399 prefer: false, 2400 visibility: ["//visibility:public"], 2401 apex_available: ["//apex_available:platform"], 2402 compile_multilib: "both", 2403 export_include_dirs: ["include/myinclude"], 2404 arch: { 2405 arm64: { 2406 export_system_include_dirs: ["arm64/include/arm64/include"], 2407 }, 2408 arm: { 2409 srcs: ["arm/lib/mynativelib.so"], 2410 }, 2411 }, 2412 strip: { 2413 none: true, 2414 }, 2415} 2416`), 2417 checkAllCopyRules(` 2418myinclude/Test.h -> include/myinclude/Test.h 2419arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h 2420.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so 2421`), 2422 ) 2423} 2424