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/dexpreopt" 23 "android/soong/java" 24) 25 26var prepareForSdkTestWithJava = android.GroupFixturePreparers( 27 java.PrepareForTestWithJavaBuildComponents, 28 PrepareForTestWithSdkBuildComponents, 29 dexpreopt.PrepareForTestWithFakeDex2oatd, 30 31 // Ensure that all source paths are provided. This helps ensure that the snapshot generation is 32 // consistent and all files referenced from the snapshot's Android.bp file have actually been 33 // copied into the snapshot. 34 android.PrepareForTestDisallowNonExistentPaths, 35 36 // Files needs by most of the tests. 37 android.MockFS{ 38 "Test.java": nil, 39 "art-profile": nil, 40 }.AddToFixture(), 41) 42 43var prepareForSdkTestWithJavaSdkLibrary = android.GroupFixturePreparers( 44 prepareForSdkTestWithJava, 45 java.PrepareForTestWithJavaDefaultModules, 46 java.PrepareForTestWithJavaSdkLibraryFiles, 47 java.FixtureWithLastReleaseApis("myjavalib"), 48 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 49 variables.BuildFlags = map[string]string{ 50 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", 51 } 52 }), 53) 54 55// Contains tests for SDK members provided by the java package. 56 57func TestSdkDependsOnSourceEvenWhenPrebuiltPreferred(t *testing.T) { 58 result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` 59 sdk { 60 name: "mysdk", 61 java_header_libs: ["sdkmember"], 62 } 63 64 java_library { 65 name: "sdkmember", 66 srcs: ["Test.java"], 67 system_modules: "none", 68 sdk_version: "none", 69 } 70 `) 71 72 // Make sure that the mysdk module depends on "sdkmember" and not "prebuilt_sdkmember". 73 sdkChecker := func(t *testing.T, result *android.TestResult) { 74 java.CheckModuleDependencies(t, result.TestContext, "mysdk", "android_common", []string{"sdkmember"}) 75 } 76 77 CheckSnapshot(t, result, "mysdk", "", 78 snapshotTestChecker(checkSnapshotWithSourcePreferred, sdkChecker), 79 snapshotTestChecker(checkSnapshotPreferredWithSource, sdkChecker), 80 ) 81} 82 83func TestSnapshotWithJavaHeaderLibrary(t *testing.T) { 84 result := android.GroupFixturePreparers( 85 prepareForSdkTestWithJava, 86 android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil), 87 ).RunTestWithBp(t, ` 88 sdk { 89 name: "mysdk", 90 java_header_libs: ["myjavalib"], 91 } 92 93 java_library { 94 name: "myjavalib", 95 srcs: ["Test.java"], 96 aidl: { 97 export_include_dirs: ["aidl"], 98 }, 99 system_modules: "none", 100 sdk_version: "none", 101 compile_dex: true, 102 host_supported: true, 103 permitted_packages: ["pkg.myjavalib"], 104 } 105 `) 106 107 CheckSnapshot(t, result, "mysdk", "", 108 checkAndroidBpContents(` 109// This is auto-generated. DO NOT EDIT. 110 111apex_contributions_defaults { 112 name: "mysdk.contributions", 113 contents: ["prebuilt_myjavalib"], 114} 115 116java_import { 117 name: "myjavalib", 118 prefer: false, 119 visibility: ["//visibility:public"], 120 apex_available: ["//apex_available:platform"], 121 jars: ["java/myjavalib.jar"], 122 permitted_packages: ["pkg.myjavalib"], 123} 124`), 125 checkAllCopyRules(` 126.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar 127aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl 128`), 129 ) 130} 131 132func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) { 133 result := android.GroupFixturePreparers( 134 prepareForSdkTestWithJava, 135 android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil), 136 ).RunTestWithBp(t, ` 137 sdk { 138 name: "mysdk", 139 device_supported: false, 140 host_supported: true, 141 java_header_libs: ["myjavalib"], 142 } 143 144 java_library { 145 name: "myjavalib", 146 device_supported: false, 147 host_supported: true, 148 srcs: ["Test.java"], 149 aidl: { 150 export_include_dirs: ["aidl"], 151 }, 152 system_modules: "none", 153 sdk_version: "none", 154 compile_dex: true, 155 } 156 `) 157 158 CheckSnapshot(t, result, "mysdk", "", 159 checkAndroidBpContents(` 160// This is auto-generated. DO NOT EDIT. 161 162apex_contributions_defaults { 163 name: "mysdk.contributions", 164 contents: ["prebuilt_myjavalib"], 165} 166 167java_import { 168 name: "myjavalib", 169 prefer: false, 170 visibility: ["//visibility:public"], 171 apex_available: ["//apex_available:platform"], 172 device_supported: false, 173 host_supported: true, 174 jars: ["java/myjavalib.jar"], 175} 176`), 177 checkAllCopyRules(` 178.intermediates/myjavalib/linux_glibc_common/javac-header/myjavalib.jar -> java/myjavalib.jar 179aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl 180`), 181 ) 182} 183 184func TestDeviceAndHostSnapshotWithJavaHeaderLibrary(t *testing.T) { 185 result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` 186 sdk { 187 name: "mysdk", 188 host_supported: true, 189 java_header_libs: ["myjavalib"], 190 } 191 192 java_library { 193 name: "myjavalib", 194 host_supported: true, 195 srcs: ["Test.java"], 196 system_modules: "none", 197 sdk_version: "none", 198 compile_dex: true, 199 } 200 `) 201 202 CheckSnapshot(t, result, "mysdk", "", 203 checkAndroidBpContents(` 204// This is auto-generated. DO NOT EDIT. 205 206apex_contributions_defaults { 207 name: "mysdk.contributions", 208 contents: ["prebuilt_myjavalib"], 209} 210 211java_import { 212 name: "myjavalib", 213 prefer: false, 214 visibility: ["//visibility:public"], 215 apex_available: ["//apex_available:platform"], 216 host_supported: true, 217 target: { 218 android: { 219 jars: ["java/android/myjavalib.jar"], 220 }, 221 linux_glibc: { 222 jars: ["java/linux_glibc/myjavalib.jar"], 223 }, 224 }, 225} 226`), 227 checkAllCopyRules(` 228.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/android/myjavalib.jar 229.intermediates/myjavalib/linux_glibc_common/javac-header/myjavalib.jar -> java/linux_glibc/myjavalib.jar 230`), 231 ) 232} 233 234func TestSnapshotWithJavaImplLibrary(t *testing.T) { 235 result := android.GroupFixturePreparers( 236 prepareForSdkTestWithJava, 237 android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil), 238 android.FixtureAddFile("resource.txt", nil), 239 ).RunTestWithBp(t, ` 240 module_exports { 241 name: "myexports", 242 java_libs: ["myjavalib"], 243 } 244 245 java_library { 246 name: "myjavalib", 247 srcs: ["Test.java"], 248 java_resources: ["resource.txt"], 249 aidl: { 250 export_include_dirs: ["aidl"], 251 }, 252 system_modules: "none", 253 sdk_version: "none", 254 compile_dex: true, 255 host_supported: true, 256 } 257 `) 258 259 CheckSnapshot(t, result, "myexports", "", 260 checkAndroidBpContents(` 261// This is auto-generated. DO NOT EDIT. 262 263apex_contributions_defaults { 264 name: "myexports.contributions", 265 contents: ["prebuilt_myjavalib"], 266} 267 268java_import { 269 name: "myjavalib", 270 prefer: false, 271 visibility: ["//visibility:public"], 272 apex_available: ["//apex_available:platform"], 273 jars: ["java/myjavalib.jar"], 274} 275`), 276 checkAllCopyRules(` 277.intermediates/myjavalib/android_common/withres/myjavalib.jar -> java/myjavalib.jar 278aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl 279`), 280 ) 281} 282 283func TestSnapshotWithJavaBootLibrary(t *testing.T) { 284 result := android.GroupFixturePreparers( 285 prepareForSdkTestWithJava, 286 android.FixtureAddFile("aidl", nil), 287 android.FixtureAddFile("resource.txt", nil), 288 ).RunTestWithBp(t, ` 289 sdk { 290 name: "mysdk", 291 java_boot_libs: ["myjavalib"], 292 } 293 294 java_library { 295 name: "myjavalib", 296 srcs: ["Test.java"], 297 java_resources: ["resource.txt"], 298 // The aidl files should not be copied to the snapshot because a java_boot_libs member is not 299 // intended to be used for compiling Java, only for accessing the dex implementation jar. 300 aidl: { 301 export_include_dirs: ["aidl"], 302 }, 303 system_modules: "none", 304 sdk_version: "none", 305 compile_dex: true, 306 permitted_packages: ["pkg.myjavalib"], 307 } 308 `) 309 310 CheckSnapshot(t, result, "mysdk", "", 311 checkAndroidBpContents(` 312// This is auto-generated. DO NOT EDIT. 313 314apex_contributions_defaults { 315 name: "mysdk.contributions", 316 contents: [], 317} 318 319java_import { 320 name: "myjavalib", 321 prefer: false, 322 visibility: ["//visibility:public"], 323 apex_available: ["//apex_available:platform"], 324 jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"], 325 permitted_packages: ["pkg.myjavalib"], 326} 327`), 328 checkAllCopyRules(` 329.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar 330`), 331 ) 332} 333 334func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) { 335 runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) { 336 result := android.GroupFixturePreparers( 337 prepareForSdkTestWithJava, 338 android.FixtureMergeEnv(map[string]string{ 339 "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, 340 }), 341 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 342 variables.Platform_version_active_codenames = []string{"VanillaIceCream"} 343 }), 344 ).RunTestWithBp(t, ` 345 sdk { 346 name: "mysdk", 347 java_boot_libs: ["updatable-media"], 348 } 349 350 java_library { 351 name: "updatable-media", 352 srcs: ["Test.java"], 353 system_modules: "none", 354 sdk_version: "none", 355 compile_dex: true, 356 permitted_packages: ["pkg.media"], 357 apex_available: ["com.android.media"], 358 } 359 `) 360 361 CheckSnapshot(t, result, "mysdk", "", 362 checkAndroidBpContents(fmt.Sprintf(` 363// This is auto-generated. DO NOT EDIT. 364 365java_import { 366 name: "updatable-media", 367 prefer: false, 368 visibility: ["//visibility:public"], 369 apex_available: ["com.android.media"], 370 jars: ["%s"], 371 permitted_packages: ["pkg.media"], 372} 373`, expectedJarPath)), 374 checkAllCopyRules(expectedCopyRule), 375 ) 376 } 377 378 t.Run("updatable-media in S", func(t *testing.T) { 379 runTest(t, "S", "java/updatable-media.jar", ` 380.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar 381`) 382 }) 383 384 t.Run("updatable-media in T", func(t *testing.T) { 385 runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", ` 386.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar 387`) 388 }) 389} 390 391func TestSnapshotWithJavaLibrary_MinSdkVersion(t *testing.T) { 392 runTest := func(t *testing.T, targetBuildRelease, minSdkVersion, expectedMinSdkVersion string) { 393 result := android.GroupFixturePreparers( 394 prepareForSdkTestWithJava, 395 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 396 variables.Platform_version_active_codenames = []string{"S", "Tiramisu", "Unfinalized"} 397 }), 398 android.FixtureMergeEnv(map[string]string{ 399 "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, 400 }), 401 ).RunTestWithBp(t, fmt.Sprintf(` 402 sdk { 403 name: "mysdk", 404 java_header_libs: ["mylib"], 405 } 406 407 java_library { 408 name: "mylib", 409 srcs: ["Test.java"], 410 system_modules: "none", 411 sdk_version: "none", 412 compile_dex: true, 413 min_sdk_version: "%s", 414 } 415 `, minSdkVersion)) 416 417 expectedMinSdkVersionLine := "" 418 if expectedMinSdkVersion != "" { 419 expectedMinSdkVersionLine = fmt.Sprintf(" min_sdk_version: %q,\n", expectedMinSdkVersion) 420 } 421 422 CheckSnapshot(t, result, "mysdk", "", 423 checkAndroidBpContents(fmt.Sprintf(` 424// This is auto-generated. DO NOT EDIT. 425 426apex_contributions_defaults { 427 name: "mysdk.contributions", 428 contents: ["prebuilt_mylib"], 429} 430 431java_import { 432 name: "mylib", 433 prefer: false, 434 visibility: ["//visibility:public"], 435 apex_available: ["//apex_available:platform"], 436 jars: ["java/mylib.jar"], 437%s} 438`, expectedMinSdkVersionLine)), 439 ) 440 } 441 442 t.Run("min_sdk_version=S in S", func(t *testing.T) { 443 // min_sdk_version was not added to java_import until Tiramisu. 444 runTest(t, "S", "S", "") 445 }) 446 447 t.Run("min_sdk_version=S in Tiramisu", func(t *testing.T) { 448 // The canonical form of S is 31. 449 runTest(t, "Tiramisu", "S", "31") 450 }) 451 452 t.Run("min_sdk_version=24 in Tiramisu", func(t *testing.T) { 453 // A numerical min_sdk_version is already in canonical form. 454 runTest(t, "Tiramisu", "24", "24") 455 }) 456 457 t.Run("min_sdk_version=Unfinalized in latest", func(t *testing.T) { 458 // An unfinalized min_sdk_version has no numeric value yet. 459 runTest(t, "", "Unfinalized", "Unfinalized") 460 }) 461} 462 463func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) { 464 result := android.GroupFixturePreparers( 465 prepareForSdkTestWithJava, 466 android.FixtureAddFile("aidl", nil), 467 android.FixtureAddFile("resource.txt", nil), 468 ).RunTestWithBp(t, ` 469 module_exports { 470 name: "myexports", 471 java_systemserver_libs: ["myjavalib"], 472 } 473 474 java_library { 475 name: "myjavalib", 476 srcs: ["Test.java"], 477 java_resources: ["resource.txt"], 478 // The aidl files should not be copied to the snapshot because a java_systemserver_libs member 479 // is not intended to be used for compiling Java, only for accessing the dex implementation 480 // jar. 481 aidl: { 482 export_include_dirs: ["aidl"], 483 }, 484 system_modules: "none", 485 sdk_version: "none", 486 compile_dex: true, 487 permitted_packages: ["pkg.myjavalib"], 488 } 489 `) 490 491 CheckSnapshot(t, result, "myexports", "", 492 checkAndroidBpContents(` 493// This is auto-generated. DO NOT EDIT. 494 495apex_contributions_defaults { 496 name: "myexports.contributions", 497 contents: [], 498} 499 500java_import { 501 name: "myjavalib", 502 prefer: false, 503 visibility: ["//visibility:public"], 504 apex_available: ["//apex_available:platform"], 505 jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"], 506 permitted_packages: ["pkg.myjavalib"], 507} 508`), 509 checkAllCopyRules(` 510.intermediates/myexports/common_os/empty -> java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar 511`), 512 ) 513} 514 515func TestHostSnapshotWithJavaImplLibrary(t *testing.T) { 516 result := android.GroupFixturePreparers( 517 prepareForSdkTestWithJava, 518 android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil), 519 ).RunTestWithBp(t, ` 520 module_exports { 521 name: "myexports", 522 device_supported: false, 523 host_supported: true, 524 java_libs: ["myjavalib"], 525 } 526 527 java_library { 528 name: "myjavalib", 529 device_supported: false, 530 host_supported: true, 531 srcs: ["Test.java"], 532 aidl: { 533 export_include_dirs: ["aidl"], 534 }, 535 system_modules: "none", 536 sdk_version: "none", 537 compile_dex: true, 538 } 539 `) 540 541 CheckSnapshot(t, result, "myexports", "", 542 checkAndroidBpContents(` 543// This is auto-generated. DO NOT EDIT. 544 545apex_contributions_defaults { 546 name: "myexports.contributions", 547 contents: ["prebuilt_myjavalib"], 548} 549 550java_import { 551 name: "myjavalib", 552 prefer: false, 553 visibility: ["//visibility:public"], 554 apex_available: ["//apex_available:platform"], 555 device_supported: false, 556 host_supported: true, 557 jars: ["java/myjavalib.jar"], 558} 559`), 560 checkAllCopyRules(` 561.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar 562aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl 563`), 564 ) 565} 566 567func TestSnapshotWithJavaTest(t *testing.T) { 568 result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` 569 module_exports { 570 name: "myexports", 571 java_tests: ["myjavatests"], 572 } 573 574 java_test { 575 name: "myjavatests", 576 srcs: ["Test.java"], 577 system_modules: "none", 578 sdk_version: "none", 579 compile_dex: true, 580 host_supported: true, 581 } 582 `) 583 584 CheckSnapshot(t, result, "myexports", "", 585 checkAndroidBpContents(` 586// This is auto-generated. DO NOT EDIT. 587 588apex_contributions_defaults { 589 name: "myexports.contributions", 590 contents: ["prebuilt_myjavatests"], 591} 592 593java_test_import { 594 name: "myjavatests", 595 prefer: false, 596 visibility: ["//visibility:public"], 597 apex_available: ["//apex_available:platform"], 598 jars: ["java/myjavatests.jar"], 599 test_config: "java/myjavatests-AndroidTest.xml", 600} 601`), 602 checkAllCopyRules(` 603.intermediates/myjavatests/android_common/javac/myjavatests.jar -> java/myjavatests.jar 604.intermediates/myjavatests/android_common/myjavatests.config -> java/myjavatests-AndroidTest.xml 605`), 606 ) 607} 608 609func TestHostSnapshotWithJavaTest(t *testing.T) { 610 result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` 611 module_exports { 612 name: "myexports", 613 device_supported: false, 614 host_supported: true, 615 java_tests: ["myjavatests"], 616 } 617 618 java_test { 619 name: "myjavatests", 620 device_supported: false, 621 host_supported: true, 622 srcs: ["Test.java"], 623 system_modules: "none", 624 sdk_version: "none", 625 compile_dex: true, 626 } 627 `) 628 629 CheckSnapshot(t, result, "myexports", "", 630 checkAndroidBpContents(` 631// This is auto-generated. DO NOT EDIT. 632 633apex_contributions_defaults { 634 name: "myexports.contributions", 635 contents: ["prebuilt_myjavatests"], 636} 637 638java_test_import { 639 name: "myjavatests", 640 prefer: false, 641 visibility: ["//visibility:public"], 642 apex_available: ["//apex_available:platform"], 643 device_supported: false, 644 host_supported: true, 645 jars: ["java/myjavatests.jar"], 646 test_config: "java/myjavatests-AndroidTest.xml", 647} 648`), 649 checkAllCopyRules(` 650.intermediates/myjavatests/linux_glibc_common/javac/myjavatests.jar -> java/myjavatests.jar 651.intermediates/myjavatests/linux_glibc_common/myjavatests.config -> java/myjavatests-AndroidTest.xml 652`), 653 ) 654} 655 656func TestSnapshotWithJavaSystemModules(t *testing.T) { 657 result := android.GroupFixturePreparers( 658 prepareForSdkTestWithJava, 659 java.PrepareForTestWithJavaDefaultModules, 660 java.PrepareForTestWithJavaSdkLibraryFiles, 661 java.FixtureWithPrebuiltApisAndExtensions(map[string][]string{ 662 "31": {"myjavalib"}, 663 "32": {"myjavalib"}, 664 "current": {"myjavalib"}, 665 }, map[string][]string{ 666 "1": {"myjavalib"}, 667 "2": {"myjavalib"}, 668 }), 669 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 670 variables.BuildFlags = map[string]string{ 671 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", 672 } 673 }), 674 ).RunTestWithBp(t, ` 675 sdk { 676 name: "mysdk", 677 java_header_libs: ["exported-system-module"], 678 java_sdk_libs: ["myjavalib"], 679 java_system_modules: ["my-system-modules"], 680 } 681 682 java_sdk_library { 683 name: "myjavalib", 684 apex_available: ["//apex_available:anyapex"], 685 srcs: ["Test.java"], 686 sdk_version: "current", 687 shared_library: false, 688 public: { 689 enabled: true, 690 }, 691 system: { 692 enabled: true, 693 }, 694 module_lib: { 695 enabled: true, 696 }, 697 } 698 699 java_system_modules { 700 name: "my-system-modules", 701 libs: ["system-module", "exported-system-module", "myjavalib.stubs"], 702 } 703 704 java_library { 705 name: "system-module", 706 srcs: ["Test.java"], 707 sdk_version: "none", 708 system_modules: "none", 709 } 710 711 java_library { 712 name: "exported-system-module", 713 srcs: ["Test.java"], 714 sdk_version: "none", 715 system_modules: "none", 716 } 717 `) 718 719 CheckSnapshot(t, result, "mysdk", "", 720 checkAndroidBpContents(` 721// This is auto-generated. DO NOT EDIT. 722 723apex_contributions_defaults { 724 name: "mysdk.contributions", 725 contents: [ 726 "prebuilt_exported-system-module", 727 "prebuilt_myjavalib", 728 "prebuilt_my-system-modules", 729 ], 730} 731 732java_import { 733 name: "exported-system-module", 734 prefer: false, 735 visibility: ["//visibility:public"], 736 apex_available: ["//apex_available:platform"], 737 jars: ["java/exported-system-module.jar"], 738} 739 740java_import { 741 name: "mysdk_system-module", 742 prefer: false, 743 visibility: ["//visibility:private"], 744 apex_available: ["//apex_available:platform"], 745 jars: ["java/system-module.jar"], 746} 747 748java_sdk_library_import { 749 name: "myjavalib", 750 prefer: false, 751 visibility: ["//visibility:public"], 752 apex_available: ["//apex_available:anyapex"], 753 shared_library: false, 754 public: { 755 jars: ["sdk_library/public/myjavalib-stubs.jar"], 756 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 757 current_api: "sdk_library/public/myjavalib.txt", 758 removed_api: "sdk_library/public/myjavalib-removed.txt", 759 sdk_version: "current", 760 }, 761 system: { 762 jars: ["sdk_library/system/myjavalib-stubs.jar"], 763 stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], 764 current_api: "sdk_library/system/myjavalib.txt", 765 removed_api: "sdk_library/system/myjavalib-removed.txt", 766 sdk_version: "system_current", 767 }, 768 module_lib: { 769 jars: ["sdk_library/module-lib/myjavalib-stubs.jar"], 770 stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"], 771 current_api: "sdk_library/module-lib/myjavalib.txt", 772 removed_api: "sdk_library/module-lib/myjavalib-removed.txt", 773 sdk_version: "module_current", 774 }, 775} 776 777java_system_modules_import { 778 name: "my-system-modules", 779 prefer: false, 780 visibility: ["//visibility:public"], 781 libs: [ 782 "mysdk_system-module", 783 "exported-system-module", 784 "myjavalib.stubs", 785 ], 786} 787`), 788 checkAllCopyRules(` 789.intermediates/exported-system-module/android_common/turbine-combined/exported-system-module.jar -> java/exported-system-module.jar 790.intermediates/system-module/android_common/turbine-combined/system-module.jar -> java/system-module.jar 791.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 792.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 793.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 794.intermediates/myjavalib.stubs.exportable.system/android_common/combined/myjavalib.stubs.exportable.system.jar -> sdk_library/system/myjavalib-stubs.jar 795.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt 796.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt 797.intermediates/myjavalib.stubs.exportable.module_lib/android_common/combined/myjavalib.stubs.exportable.module_lib.jar -> sdk_library/module-lib/myjavalib-stubs.jar 798.intermediates/myjavalib.stubs.source.module_lib/android_common/exportable/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt 799.intermediates/myjavalib.stubs.source.module_lib/android_common/exportable/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt 800`), 801 checkInfoContents(result.Config, ` 802[ 803 { 804 "@type": "sdk", 805 "@name": "mysdk", 806 "java_header_libs": [ 807 "exported-system-module", 808 "system-module" 809 ], 810 "java_sdk_libs": [ 811 "myjavalib" 812 ], 813 "java_system_modules": [ 814 "my-system-modules" 815 ] 816 }, 817 { 818 "@type": "java_library", 819 "@name": "exported-system-module" 820 }, 821 { 822 "@type": "java_system_modules", 823 "@name": "my-system-modules", 824 "@deps": [ 825 "exported-system-module", 826 "system-module" 827 ] 828 }, 829 { 830 "@type": "java_sdk_library", 831 "@name": "myjavalib", 832 "dist_stem": "myjavalib", 833 "scopes": { 834 "module-lib": { 835 "current_api": "sdk_library/module-lib/myjavalib.txt", 836 "latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.module-lib.latest/gen/myjavalib.api.module-lib.latest", 837 "latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.module-lib.latest/gen/myjavalib-removed.api.module-lib.latest", 838 "removed_api": "sdk_library/module-lib/myjavalib-removed.txt" 839 }, 840 "public": { 841 "current_api": "sdk_library/public/myjavalib.txt", 842 "latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.public.latest/gen/myjavalib.api.public.latest", 843 "latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.public.latest/gen/myjavalib-removed.api.public.latest", 844 "removed_api": "sdk_library/public/myjavalib-removed.txt" 845 }, 846 "system": { 847 "current_api": "sdk_library/system/myjavalib.txt", 848 "latest_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib.api.system.latest/gen/myjavalib.api.system.latest", 849 "latest_removed_api": "out/soong/.intermediates/prebuilts/sdk/myjavalib-removed.api.system.latest/gen/myjavalib-removed.api.system.latest", 850 "removed_api": "sdk_library/system/myjavalib-removed.txt" 851 } 852 } 853 }, 854 { 855 "@type": "java_library", 856 "@name": "system-module" 857 } 858] 859`), 860 ) 861} 862 863func TestHostSnapshotWithJavaSystemModules(t *testing.T) { 864 result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` 865 sdk { 866 name: "mysdk", 867 device_supported: false, 868 host_supported: true, 869 java_system_modules: ["my-system-modules"], 870 } 871 872 java_system_modules { 873 name: "my-system-modules", 874 device_supported: false, 875 host_supported: true, 876 libs: ["system-module"], 877 } 878 879 java_library { 880 name: "system-module", 881 device_supported: false, 882 host_supported: true, 883 srcs: ["Test.java"], 884 sdk_version: "none", 885 system_modules: "none", 886 } 887 `) 888 889 CheckSnapshot(t, result, "mysdk", "", 890 checkAndroidBpContents(` 891// This is auto-generated. DO NOT EDIT. 892 893apex_contributions_defaults { 894 name: "mysdk.contributions", 895 contents: ["prebuilt_my-system-modules"], 896} 897 898java_import { 899 name: "mysdk_system-module", 900 prefer: false, 901 visibility: ["//visibility:private"], 902 apex_available: ["//apex_available:platform"], 903 device_supported: false, 904 host_supported: true, 905 jars: ["java/system-module.jar"], 906} 907 908java_system_modules_import { 909 name: "my-system-modules", 910 prefer: false, 911 visibility: ["//visibility:public"], 912 device_supported: false, 913 host_supported: true, 914 libs: ["mysdk_system-module"], 915} 916`), 917 checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac-header/system-module.jar -> java/system-module.jar"), 918 ) 919} 920 921func TestDeviceAndHostSnapshotWithOsSpecificMembers(t *testing.T) { 922 result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, ` 923 module_exports { 924 name: "myexports", 925 host_supported: true, 926 java_libs: ["myjavalib"], 927 target: { 928 android: { 929 java_header_libs: ["androidjavalib"], 930 }, 931 host: { 932 java_header_libs: ["hostjavalib"], 933 }, 934 }, 935 } 936 937 java_library { 938 name: "myjavalib", 939 host_supported: true, 940 srcs: ["Test.java"], 941 system_modules: "none", 942 sdk_version: "none", 943 } 944 945 java_library { 946 name: "androidjavalib", 947 srcs: ["Test.java"], 948 system_modules: "none", 949 sdk_version: "none", 950 } 951 952 java_library_host { 953 name: "hostjavalib", 954 srcs: ["Test.java"], 955 } 956 `) 957 958 CheckSnapshot(t, result, "myexports", "", 959 checkAndroidBpContents(` 960// This is auto-generated. DO NOT EDIT. 961 962apex_contributions_defaults { 963 name: "myexports.contributions", 964 contents: [ 965 "prebuilt_hostjavalib", 966 "prebuilt_androidjavalib", 967 "prebuilt_myjavalib", 968 ], 969} 970 971java_import { 972 name: "hostjavalib", 973 prefer: false, 974 visibility: ["//visibility:public"], 975 apex_available: ["//apex_available:platform"], 976 device_supported: false, 977 host_supported: true, 978 jars: ["java/hostjavalib.jar"], 979} 980 981java_import { 982 name: "androidjavalib", 983 prefer: false, 984 visibility: ["//visibility:public"], 985 apex_available: ["//apex_available:platform"], 986 jars: ["java/androidjavalib.jar"], 987} 988 989java_import { 990 name: "myjavalib", 991 prefer: false, 992 visibility: ["//visibility:public"], 993 apex_available: ["//apex_available:platform"], 994 host_supported: true, 995 target: { 996 android: { 997 jars: ["java/android/myjavalib.jar"], 998 }, 999 linux_glibc: { 1000 jars: ["java/linux_glibc/myjavalib.jar"], 1001 }, 1002 }, 1003} 1004`), 1005 checkAllCopyRules(` 1006.intermediates/hostjavalib/linux_glibc_common/javac-header/hostjavalib.jar -> java/hostjavalib.jar 1007.intermediates/androidjavalib/android_common/turbine-combined/androidjavalib.jar -> java/androidjavalib.jar 1008.intermediates/myjavalib/android_common/javac/myjavalib.jar -> java/android/myjavalib.jar 1009.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar 1010`), 1011 ) 1012} 1013 1014func TestSnapshotWithJavaSdkLibrary(t *testing.T) { 1015 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1016 sdk { 1017 name: "mysdk", 1018 java_sdk_libs: ["myjavalib"], 1019 } 1020 1021 java_sdk_library { 1022 name: "myjavalib", 1023 apex_available: ["//apex_available:anyapex"], 1024 srcs: ["Test.java"], 1025 sdk_version: "current", 1026 shared_library: false, 1027 stubs_library_visibility: ["//other"], 1028 stubs_source_visibility: ["//another"], 1029 permitted_packages: ["pkg.myjavalib"], 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_myjavalib"], 1040} 1041 1042java_sdk_library_import { 1043 name: "myjavalib", 1044 prefer: false, 1045 visibility: ["//visibility:public"], 1046 apex_available: ["//apex_available:anyapex"], 1047 shared_library: false, 1048 permitted_packages: ["pkg.myjavalib"], 1049 public: { 1050 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1051 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1052 current_api: "sdk_library/public/myjavalib.txt", 1053 removed_api: "sdk_library/public/myjavalib-removed.txt", 1054 sdk_version: "current", 1055 }, 1056 system: { 1057 jars: ["sdk_library/system/myjavalib-stubs.jar"], 1058 stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], 1059 current_api: "sdk_library/system/myjavalib.txt", 1060 removed_api: "sdk_library/system/myjavalib-removed.txt", 1061 sdk_version: "system_current", 1062 }, 1063 test: { 1064 jars: ["sdk_library/test/myjavalib-stubs.jar"], 1065 stub_srcs: ["sdk_library/test/myjavalib_stub_sources"], 1066 current_api: "sdk_library/test/myjavalib.txt", 1067 removed_api: "sdk_library/test/myjavalib-removed.txt", 1068 sdk_version: "test_current", 1069 }, 1070} 1071`), 1072 checkAllCopyRules(` 1073.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1074.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1075.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1076.intermediates/myjavalib.stubs.exportable.system/android_common/combined/myjavalib.stubs.exportable.system.jar -> sdk_library/system/myjavalib-stubs.jar 1077.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt 1078.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt 1079.intermediates/myjavalib.stubs.exportable.test/android_common/combined/myjavalib.stubs.exportable.test.jar -> sdk_library/test/myjavalib-stubs.jar 1080.intermediates/myjavalib.stubs.source.test/android_common/exportable/myjavalib.stubs.source.test_api.txt -> sdk_library/test/myjavalib.txt 1081.intermediates/myjavalib.stubs.source.test/android_common/exportable/myjavalib.stubs.source.test_removed.txt -> sdk_library/test/myjavalib-removed.txt 1082`), 1083 checkMergeZips( 1084 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1085 ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", 1086 ".intermediates/mysdk/common_os/tmp/sdk_library/test/myjavalib_stub_sources.zip", 1087 ), 1088 ) 1089} 1090 1091func TestSnapshotWithJavaSdkLibrary_DistStem(t *testing.T) { 1092 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1093 sdk { 1094 name: "mysdk", 1095 java_sdk_libs: ["myjavalib-foo"], 1096 } 1097 1098 java_sdk_library { 1099 name: "myjavalib-foo", 1100 apex_available: ["//apex_available:anyapex"], 1101 srcs: ["Test.java"], 1102 sdk_version: "current", 1103 shared_library: false, 1104 public: { 1105 enabled: true, 1106 }, 1107 dist_stem: "myjavalib", 1108 } 1109 `) 1110 1111 CheckSnapshot(t, result, "mysdk", "", 1112 checkAndroidBpContents(` 1113// This is auto-generated. DO NOT EDIT. 1114 1115apex_contributions_defaults { 1116 name: "mysdk.contributions", 1117 contents: ["prebuilt_myjavalib-foo"], 1118} 1119 1120java_sdk_library_import { 1121 name: "myjavalib-foo", 1122 prefer: false, 1123 visibility: ["//visibility:public"], 1124 apex_available: ["//apex_available:anyapex"], 1125 shared_library: false, 1126 public: { 1127 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1128 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1129 current_api: "sdk_library/public/myjavalib.txt", 1130 removed_api: "sdk_library/public/myjavalib-removed.txt", 1131 sdk_version: "current", 1132 }, 1133} 1134`), 1135 checkAllCopyRules(` 1136.intermediates/myjavalib-foo.stubs.exportable/android_common/combined/myjavalib-foo.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1137.intermediates/myjavalib-foo.stubs.source/android_common/exportable/myjavalib-foo.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1138.intermediates/myjavalib-foo.stubs.source/android_common/exportable/myjavalib-foo.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1139`), 1140 checkMergeZips( 1141 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1142 ), 1143 ) 1144} 1145 1146func TestSnapshotWithJavaSdkLibrary_UseSrcJar(t *testing.T) { 1147 result := android.GroupFixturePreparers( 1148 prepareForSdkTestWithJavaSdkLibrary, 1149 android.FixtureMergeEnv(map[string]string{ 1150 "SOONG_SDK_SNAPSHOT_USE_SRCJAR": "true", 1151 }), 1152 ).RunTestWithBp(t, ` 1153 sdk { 1154 name: "mysdk", 1155 java_sdk_libs: ["myjavalib"], 1156 } 1157 1158 java_sdk_library { 1159 name: "myjavalib", 1160 srcs: ["Test.java"], 1161 sdk_version: "current", 1162 shared_library: false, 1163 public: { 1164 enabled: true, 1165 }, 1166 } 1167 `) 1168 1169 CheckSnapshot(t, result, "mysdk", "", 1170 checkAndroidBpContents(` 1171// This is auto-generated. DO NOT EDIT. 1172 1173apex_contributions_defaults { 1174 name: "mysdk.contributions", 1175 contents: ["prebuilt_myjavalib"], 1176} 1177 1178java_sdk_library_import { 1179 name: "myjavalib", 1180 prefer: false, 1181 visibility: ["//visibility:public"], 1182 apex_available: ["//apex_available:platform"], 1183 shared_library: false, 1184 public: { 1185 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1186 stub_srcs: ["sdk_library/public/myjavalib.srcjar"], 1187 current_api: "sdk_library/public/myjavalib.txt", 1188 removed_api: "sdk_library/public/myjavalib-removed.txt", 1189 sdk_version: "current", 1190 }, 1191} 1192 `), 1193 checkAllCopyRules(` 1194.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1195.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source-stubs.srcjar -> sdk_library/public/myjavalib.srcjar 1196.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1197.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1198 `), 1199 ) 1200} 1201 1202func TestSnapshotWithJavaSdkLibrary_AnnotationsZip(t *testing.T) { 1203 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1204 sdk { 1205 name: "mysdk", 1206 java_sdk_libs: ["myjavalib"], 1207 } 1208 1209 java_sdk_library { 1210 name: "myjavalib", 1211 srcs: ["Test.java"], 1212 sdk_version: "current", 1213 shared_library: false, 1214 annotations_enabled: true, 1215 public: { 1216 enabled: true, 1217 }, 1218 } 1219 `) 1220 1221 CheckSnapshot(t, result, "mysdk", "", 1222 checkAndroidBpContents(` 1223// This is auto-generated. DO NOT EDIT. 1224 1225apex_contributions_defaults { 1226 name: "mysdk.contributions", 1227 contents: ["prebuilt_myjavalib"], 1228} 1229 1230java_sdk_library_import { 1231 name: "myjavalib", 1232 prefer: false, 1233 visibility: ["//visibility:public"], 1234 apex_available: ["//apex_available:platform"], 1235 shared_library: false, 1236 public: { 1237 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1238 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1239 current_api: "sdk_library/public/myjavalib.txt", 1240 removed_api: "sdk_library/public/myjavalib-removed.txt", 1241 annotations: "sdk_library/public/myjavalib_annotations.zip", 1242 sdk_version: "current", 1243 }, 1244} 1245 `), 1246 checkAllCopyRules(` 1247.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1248.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1249.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1250.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_annotations.zip -> sdk_library/public/myjavalib_annotations.zip 1251 `), 1252 checkMergeZips(".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip"), 1253 ) 1254} 1255 1256func TestSnapshotWithJavaSdkLibrary_AnnotationsZip_PreT(t *testing.T) { 1257 result := android.GroupFixturePreparers( 1258 prepareForSdkTestWithJavaSdkLibrary, 1259 android.FixtureMergeEnv(map[string]string{ 1260 "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", 1261 }), 1262 ).RunTestWithBp(t, ` 1263 sdk { 1264 name: "mysdk", 1265 java_sdk_libs: ["myjavalib"], 1266 } 1267 1268 java_sdk_library { 1269 name: "myjavalib", 1270 srcs: ["Test.java"], 1271 sdk_version: "S", 1272 shared_library: false, 1273 annotations_enabled: true, 1274 public: { 1275 enabled: true, 1276 }, 1277 } 1278 `) 1279 1280 CheckSnapshot(t, result, "mysdk", "", 1281 checkAndroidBpContents(` 1282// This is auto-generated. DO NOT EDIT. 1283 1284apex_contributions_defaults { 1285 name: "mysdk.contributions", 1286 contents: ["prebuilt_myjavalib"], 1287} 1288 1289java_sdk_library_import { 1290 name: "myjavalib", 1291 prefer: false, 1292 visibility: ["//visibility:public"], 1293 apex_available: ["//apex_available:platform"], 1294 shared_library: false, 1295 public: { 1296 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1297 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1298 current_api: "sdk_library/public/myjavalib.txt", 1299 removed_api: "sdk_library/public/myjavalib-removed.txt", 1300 sdk_version: "current", 1301 }, 1302} 1303 `), 1304 checkAllCopyRules(` 1305.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1306.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1307.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1308 `), 1309 checkMergeZips(".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip"), 1310 ) 1311} 1312 1313func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) { 1314 result := android.GroupFixturePreparers( 1315 prepareForSdkTestWithJavaSdkLibrary, 1316 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 1317 variables.BuildFlags = map[string]string{ 1318 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", 1319 } 1320 }), 1321 ).RunTestWithBp(t, ` 1322 sdk { 1323 name: "mysdk", 1324 java_sdk_libs: ["myjavalib"], 1325 } 1326 1327 java_sdk_library { 1328 name: "myjavalib", 1329 srcs: ["Test.java"], 1330 sdk_version: "current", 1331 shared_library: false, 1332 compile_dex: true, 1333 public: { 1334 enabled: true, 1335 }, 1336 system: { 1337 enabled: true, 1338 }, 1339 } 1340 `) 1341 1342 CheckSnapshot(t, result, "mysdk", "", 1343 checkAndroidBpContents(` 1344// This is auto-generated. DO NOT EDIT. 1345 1346apex_contributions_defaults { 1347 name: "mysdk.contributions", 1348 contents: ["prebuilt_myjavalib"], 1349} 1350 1351java_sdk_library_import { 1352 name: "myjavalib", 1353 prefer: false, 1354 visibility: ["//visibility:public"], 1355 apex_available: ["//apex_available:platform"], 1356 shared_library: false, 1357 compile_dex: true, 1358 public: { 1359 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1360 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1361 current_api: "sdk_library/public/myjavalib.txt", 1362 removed_api: "sdk_library/public/myjavalib-removed.txt", 1363 sdk_version: "current", 1364 }, 1365 system: { 1366 jars: ["sdk_library/system/myjavalib-stubs.jar"], 1367 stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], 1368 current_api: "sdk_library/system/myjavalib.txt", 1369 removed_api: "sdk_library/system/myjavalib-removed.txt", 1370 sdk_version: "system_current", 1371 }, 1372} 1373`), 1374 snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) { 1375 ctx := android.ModuleInstallPathContextForTesting(result.Config) 1376 dexJarBuildPath := func(name string, kind android.SdkKind) string { 1377 dep := result.Module(name, "android_common").(java.SdkLibraryDependency) 1378 path := dep.SdkApiExportableStubDexJar(ctx, kind).Path() 1379 return path.RelativeToTop().String() 1380 } 1381 1382 dexJarPath := dexJarBuildPath("myjavalib", android.SdkPublic) 1383 android.AssertStringEquals(t, "source dex public stubs jar build path", "out/soong/.intermediates/myjavalib.stubs.exportable/android_common/dex/myjavalib.stubs.exportable.jar", dexJarPath) 1384 1385 dexJarPath = dexJarBuildPath("myjavalib", android.SdkSystem) 1386 systemDexJar := "out/soong/.intermediates/myjavalib.stubs.exportable.system/android_common/dex/myjavalib.stubs.exportable.system.jar" 1387 android.AssertStringEquals(t, "source dex system stubs jar build path", systemDexJar, dexJarPath) 1388 1389 // This should fall back to system as module is not available. 1390 dexJarPath = dexJarBuildPath("myjavalib", android.SdkModule) 1391 android.AssertStringEquals(t, "source dex module stubs jar build path", systemDexJar, dexJarPath) 1392 1393 // Prebuilt dex jar does not come from the exportable stubs. 1394 dexJarPath = dexJarBuildPath(android.PrebuiltNameFromSource("myjavalib"), android.SdkPublic) 1395 android.AssertStringEquals(t, "prebuilt dex public stubs jar build path", "out/soong/.intermediates/snapshot/prebuilt_myjavalib.stubs/android_common/dex/myjavalib.stubs.jar", dexJarPath) 1396 }), 1397 ) 1398} 1399 1400func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) { 1401 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1402 sdk { 1403 name: "mysdk", 1404 java_sdk_libs: ["myjavalib"], 1405 } 1406 1407 java_sdk_library { 1408 name: "myjavalib", 1409 srcs: ["Test.java"], 1410 sdk_version: "none", 1411 system_modules: "none", 1412 } 1413 `) 1414 1415 CheckSnapshot(t, result, "mysdk", "", 1416 checkAndroidBpContents(` 1417// This is auto-generated. DO NOT EDIT. 1418 1419apex_contributions_defaults { 1420 name: "mysdk.contributions", 1421 contents: ["prebuilt_myjavalib"], 1422} 1423 1424java_sdk_library_import { 1425 name: "myjavalib", 1426 prefer: false, 1427 visibility: ["//visibility:public"], 1428 apex_available: ["//apex_available:platform"], 1429 shared_library: true, 1430 public: { 1431 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1432 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1433 current_api: "sdk_library/public/myjavalib.txt", 1434 removed_api: "sdk_library/public/myjavalib-removed.txt", 1435 sdk_version: "none", 1436 }, 1437} 1438`), 1439 checkAllCopyRules(` 1440.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1441.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1442.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1443`), 1444 checkMergeZips( 1445 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1446 ), 1447 ) 1448} 1449 1450func TestSnapshotWithJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { 1451 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1452 sdk { 1453 name: "mysdk", 1454 java_sdk_libs: ["myjavalib"], 1455 } 1456 1457 java_sdk_library { 1458 name: "myjavalib", 1459 srcs: ["Test.java"], 1460 sdk_version: "module_current", 1461 public: { 1462 enabled: true, 1463 sdk_version: "module_current", 1464 }, 1465 } 1466 `) 1467 1468 CheckSnapshot(t, result, "mysdk", "", 1469 checkAndroidBpContents(` 1470// This is auto-generated. DO NOT EDIT. 1471 1472apex_contributions_defaults { 1473 name: "mysdk.contributions", 1474 contents: ["prebuilt_myjavalib"], 1475} 1476 1477java_sdk_library_import { 1478 name: "myjavalib", 1479 prefer: false, 1480 visibility: ["//visibility:public"], 1481 apex_available: ["//apex_available:platform"], 1482 shared_library: true, 1483 public: { 1484 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1485 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1486 current_api: "sdk_library/public/myjavalib.txt", 1487 removed_api: "sdk_library/public/myjavalib-removed.txt", 1488 sdk_version: "module_current", 1489 }, 1490} 1491`), 1492 checkAllCopyRules(` 1493.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1494.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1495.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1496`), 1497 checkMergeZips( 1498 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1499 ), 1500 ) 1501} 1502 1503func TestSnapshotWithJavaSdkLibrary_ApiScopes(t *testing.T) { 1504 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1505 sdk { 1506 name: "mysdk", 1507 java_sdk_libs: ["myjavalib"], 1508 } 1509 1510 java_sdk_library { 1511 name: "myjavalib", 1512 apex_available: ["//apex_available:anyapex"], 1513 srcs: ["Test.java"], 1514 sdk_version: "current", 1515 public: { 1516 enabled: true, 1517 }, 1518 system: { 1519 enabled: true, 1520 }, 1521 } 1522 `) 1523 1524 CheckSnapshot(t, result, "mysdk", "", 1525 checkAndroidBpContents(` 1526// This is auto-generated. DO NOT EDIT. 1527 1528apex_contributions_defaults { 1529 name: "mysdk.contributions", 1530 contents: ["prebuilt_myjavalib"], 1531} 1532 1533java_sdk_library_import { 1534 name: "myjavalib", 1535 prefer: false, 1536 visibility: ["//visibility:public"], 1537 apex_available: ["//apex_available:anyapex"], 1538 shared_library: true, 1539 public: { 1540 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1541 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1542 current_api: "sdk_library/public/myjavalib.txt", 1543 removed_api: "sdk_library/public/myjavalib-removed.txt", 1544 sdk_version: "current", 1545 }, 1546 system: { 1547 jars: ["sdk_library/system/myjavalib-stubs.jar"], 1548 stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], 1549 current_api: "sdk_library/system/myjavalib.txt", 1550 removed_api: "sdk_library/system/myjavalib-removed.txt", 1551 sdk_version: "system_current", 1552 }, 1553} 1554`), 1555 checkAllCopyRules(` 1556.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1557.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1558.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1559.intermediates/myjavalib.stubs.exportable.system/android_common/combined/myjavalib.stubs.exportable.system.jar -> sdk_library/system/myjavalib-stubs.jar 1560.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt 1561.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt 1562`), 1563 checkMergeZips( 1564 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1565 ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", 1566 ), 1567 ) 1568} 1569 1570func TestSnapshotWithJavaSdkLibrary_ModuleLib(t *testing.T) { 1571 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1572 sdk { 1573 name: "mysdk", 1574 java_sdk_libs: ["myjavalib"], 1575 } 1576 1577 java_sdk_library { 1578 name: "myjavalib", 1579 apex_available: ["//apex_available:anyapex"], 1580 srcs: ["Test.java"], 1581 sdk_version: "current", 1582 public: { 1583 enabled: true, 1584 }, 1585 system: { 1586 enabled: true, 1587 }, 1588 module_lib: { 1589 enabled: true, 1590 }, 1591 } 1592 `) 1593 1594 CheckSnapshot(t, result, "mysdk", "", 1595 checkAndroidBpContents(` 1596// This is auto-generated. DO NOT EDIT. 1597 1598apex_contributions_defaults { 1599 name: "mysdk.contributions", 1600 contents: ["prebuilt_myjavalib"], 1601} 1602 1603java_sdk_library_import { 1604 name: "myjavalib", 1605 prefer: false, 1606 visibility: ["//visibility:public"], 1607 apex_available: ["//apex_available:anyapex"], 1608 shared_library: true, 1609 public: { 1610 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1611 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1612 current_api: "sdk_library/public/myjavalib.txt", 1613 removed_api: "sdk_library/public/myjavalib-removed.txt", 1614 sdk_version: "current", 1615 }, 1616 system: { 1617 jars: ["sdk_library/system/myjavalib-stubs.jar"], 1618 stub_srcs: ["sdk_library/system/myjavalib_stub_sources"], 1619 current_api: "sdk_library/system/myjavalib.txt", 1620 removed_api: "sdk_library/system/myjavalib-removed.txt", 1621 sdk_version: "system_current", 1622 }, 1623 module_lib: { 1624 jars: ["sdk_library/module-lib/myjavalib-stubs.jar"], 1625 stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"], 1626 current_api: "sdk_library/module-lib/myjavalib.txt", 1627 removed_api: "sdk_library/module-lib/myjavalib-removed.txt", 1628 sdk_version: "module_current", 1629 }, 1630} 1631`), 1632 checkAllCopyRules(` 1633.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1634.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1635.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1636.intermediates/myjavalib.stubs.exportable.system/android_common/combined/myjavalib.stubs.exportable.system.jar -> sdk_library/system/myjavalib-stubs.jar 1637.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt 1638.intermediates/myjavalib.stubs.source.system/android_common/exportable/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt 1639.intermediates/myjavalib.stubs.exportable.module_lib/android_common/combined/myjavalib.stubs.exportable.module_lib.jar -> sdk_library/module-lib/myjavalib-stubs.jar 1640.intermediates/myjavalib.stubs.source.module_lib/android_common/exportable/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt 1641.intermediates/myjavalib.stubs.source.module_lib/android_common/exportable/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt 1642`), 1643 checkMergeZips( 1644 ".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip", 1645 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1646 ".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip", 1647 ), 1648 ) 1649} 1650 1651func TestSnapshotWithJavaSdkLibrary_SystemServer(t *testing.T) { 1652 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1653 sdk { 1654 name: "mysdk", 1655 java_sdk_libs: ["myjavalib"], 1656 } 1657 1658 java_sdk_library { 1659 name: "myjavalib", 1660 apex_available: ["//apex_available:anyapex"], 1661 srcs: ["Test.java"], 1662 sdk_version: "current", 1663 public: { 1664 enabled: true, 1665 }, 1666 system_server: { 1667 enabled: true, 1668 }, 1669 } 1670 `) 1671 1672 CheckSnapshot(t, result, "mysdk", "", 1673 checkAndroidBpContents(` 1674// This is auto-generated. DO NOT EDIT. 1675 1676apex_contributions_defaults { 1677 name: "mysdk.contributions", 1678 contents: ["prebuilt_myjavalib"], 1679} 1680 1681java_sdk_library_import { 1682 name: "myjavalib", 1683 prefer: false, 1684 visibility: ["//visibility:public"], 1685 apex_available: ["//apex_available:anyapex"], 1686 shared_library: true, 1687 public: { 1688 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1689 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1690 current_api: "sdk_library/public/myjavalib.txt", 1691 removed_api: "sdk_library/public/myjavalib-removed.txt", 1692 sdk_version: "current", 1693 }, 1694 system_server: { 1695 jars: ["sdk_library/system-server/myjavalib-stubs.jar"], 1696 stub_srcs: ["sdk_library/system-server/myjavalib_stub_sources"], 1697 current_api: "sdk_library/system-server/myjavalib.txt", 1698 removed_api: "sdk_library/system-server/myjavalib-removed.txt", 1699 sdk_version: "system_server_current", 1700 }, 1701} 1702`), 1703 checkAllCopyRules(` 1704.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1705.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1706.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1707.intermediates/myjavalib.stubs.exportable.system_server/android_common/combined/myjavalib.stubs.exportable.system_server.jar -> sdk_library/system-server/myjavalib-stubs.jar 1708.intermediates/myjavalib.stubs.source.system_server/android_common/exportable/myjavalib.stubs.source.system_server_api.txt -> sdk_library/system-server/myjavalib.txt 1709.intermediates/myjavalib.stubs.source.system_server/android_common/exportable/myjavalib.stubs.source.system_server_removed.txt -> sdk_library/system-server/myjavalib-removed.txt 1710`), 1711 checkMergeZips( 1712 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1713 ".intermediates/mysdk/common_os/tmp/sdk_library/system-server/myjavalib_stub_sources.zip", 1714 ), 1715 ) 1716} 1717 1718func TestSnapshotWithJavaSdkLibrary_NamingScheme(t *testing.T) { 1719 result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, ` 1720 sdk { 1721 name: "mysdk", 1722 java_sdk_libs: ["myjavalib"], 1723 } 1724 1725 java_sdk_library { 1726 name: "myjavalib", 1727 apex_available: ["//apex_available:anyapex"], 1728 srcs: ["Test.java"], 1729 sdk_version: "current", 1730 naming_scheme: "default", 1731 public: { 1732 enabled: true, 1733 }, 1734 } 1735 `) 1736 1737 CheckSnapshot(t, result, "mysdk", "", 1738 checkAndroidBpContents(` 1739// This is auto-generated. DO NOT EDIT. 1740 1741apex_contributions_defaults { 1742 name: "mysdk.contributions", 1743 contents: ["prebuilt_myjavalib"], 1744} 1745 1746java_sdk_library_import { 1747 name: "myjavalib", 1748 prefer: false, 1749 visibility: ["//visibility:public"], 1750 apex_available: ["//apex_available:anyapex"], 1751 naming_scheme: "default", 1752 shared_library: true, 1753 public: { 1754 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1755 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1756 current_api: "sdk_library/public/myjavalib.txt", 1757 removed_api: "sdk_library/public/myjavalib-removed.txt", 1758 sdk_version: "current", 1759 }, 1760} 1761`), 1762 checkAllCopyRules(` 1763.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1764.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1765.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1766`), 1767 checkMergeZips( 1768 ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", 1769 ), 1770 ) 1771} 1772 1773func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) { 1774 result := android.GroupFixturePreparers( 1775 prepareForSdkTestWithJavaSdkLibrary, 1776 android.FixtureAddFile("docs/known_doctags", nil), 1777 ).RunTestWithBp(t, ` 1778 sdk { 1779 name: "mysdk", 1780 java_sdk_libs: ["myjavalib"], 1781 } 1782 1783 java_sdk_library { 1784 name: "myjavalib", 1785 srcs: ["Test.java"], 1786 sdk_version: "current", 1787 public: { 1788 enabled: true, 1789 }, 1790 doctag_files: ["docs/known_doctags"], 1791 } 1792 1793 filegroup { 1794 name: "mygroup", 1795 srcs: [":myjavalib{.doctags}"], 1796 } 1797 `) 1798 1799 CheckSnapshot(t, result, "mysdk", "", 1800 checkAndroidBpContents(` 1801// This is auto-generated. DO NOT EDIT. 1802 1803apex_contributions_defaults { 1804 name: "mysdk.contributions", 1805 contents: ["prebuilt_myjavalib"], 1806} 1807 1808java_sdk_library_import { 1809 name: "myjavalib", 1810 prefer: false, 1811 visibility: ["//visibility:public"], 1812 apex_available: ["//apex_available:platform"], 1813 shared_library: true, 1814 doctag_files: ["doctags/docs/known_doctags"], 1815 public: { 1816 jars: ["sdk_library/public/myjavalib-stubs.jar"], 1817 stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], 1818 current_api: "sdk_library/public/myjavalib.txt", 1819 removed_api: "sdk_library/public/myjavalib-removed.txt", 1820 sdk_version: "current", 1821 }, 1822} 1823`), 1824 checkAllCopyRules(` 1825.intermediates/myjavalib.stubs.exportable/android_common/combined/myjavalib.stubs.exportable.jar -> sdk_library/public/myjavalib-stubs.jar 1826.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt 1827.intermediates/myjavalib.stubs.source/android_common/exportable/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt 1828docs/known_doctags -> doctags/docs/known_doctags 1829`), 1830 ) 1831} 1832