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